Skip to content

Commit c2d7192

Browse files
committed
Fix for change in Jetty 9.4.20.v20190813
Closes gh-23500
1 parent 88e9dce commit c2d7192

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

spring-websocket/src/main/java/org/springframework/web/socket/server/jetty/JettyRequestUpgradeStrategy.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717
package org.springframework.web.socket.server.jetty;
1818

1919
import java.io.IOException;
20+
import java.lang.reflect.Method;
2021
import java.security.Principal;
2122
import java.util.ArrayList;
2223
import java.util.List;
@@ -28,6 +29,7 @@
2829

2930
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
3031
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
32+
import org.eclipse.jetty.websocket.api.extensions.ExtensionFactory;
3133
import org.eclipse.jetty.websocket.server.HandshakeRFC6455;
3234
import org.eclipse.jetty.websocket.server.WebSocketServerFactory;
3335

@@ -38,7 +40,9 @@
3840
import org.springframework.http.server.ServletServerHttpRequest;
3941
import org.springframework.http.server.ServletServerHttpResponse;
4042
import org.springframework.util.Assert;
43+
import org.springframework.util.ClassUtils;
4144
import org.springframework.util.CollectionUtils;
45+
import org.springframework.util.ReflectionUtils;
4246
import org.springframework.web.context.ServletContextAware;
4347
import org.springframework.web.socket.WebSocketExtension;
4448
import org.springframework.web.socket.WebSocketHandler;
@@ -167,14 +171,26 @@ public List<WebSocketExtension> getSupportedExtensions(ServerHttpRequest request
167171
}
168172

169173
private List<WebSocketExtension> buildWebSocketExtensions() {
170-
Set<String> names = this.factory.getExtensionFactory().getExtensionNames();
174+
Set<String> names = getExtensionNames();
171175
List<WebSocketExtension> result = new ArrayList<>(names.size());
172176
for (String name : names) {
173177
result.add(new WebSocketExtension(name));
174178
}
175179
return result;
176180
}
177181

182+
@SuppressWarnings({"unchecked"})
183+
private Set<String> getExtensionNames() {
184+
try {
185+
return this.factory.getExtensionFactory().getExtensionNames();
186+
}
187+
catch (IncompatibleClassChangeError ex) {
188+
// 9.4.20.v20190813: ExtensionFactory (abstract class -> interface)
189+
Method method = ClassUtils.getMethod(ExtensionFactory.class, "getExtensionNames");
190+
return (Set<String>) ReflectionUtils.invokeMethod(method, this.factory.getExtensionFactory());
191+
}
192+
}
193+
178194
@Override
179195
public void upgrade(ServerHttpRequest request, ServerHttpResponse response,
180196
String selectedProtocol, List<WebSocketExtension> selectedExtensions, Principal user,

0 commit comments

Comments
 (0)