Skip to content

Commit 8fbba84

Browse files
committed
Optimized support for GlassFish 4.1.1 (Tyrus 1.9 - 1.12)
Issue: SPR-13566
1 parent 2e5ddef commit 8fbba84

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

spring-websocket/src/main/java/org/springframework/web/socket/server/standard/AbstractTyrusRequestUpgradeStrategy.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
* <p>Works with Tyrus 1.3.5 (WebLogic 12.1.3) and Tyrus 1.7+ (GlassFish 4.1.x).
6161
*
6262
* @author Rossen Stoyanchev
63+
* @author Brian Clozel
6364
* @since 4.1
6465
* @see <a href="https://tyrus.java.net/">Project Tyrus</a>
6566
*/
@@ -181,13 +182,20 @@ protected static class Tyrus17EndpointHelper implements TyrusEndpointHelper {
181182

182183
private static final Constructor<?> constructor;
183184

185+
private static boolean constructorWithBooleanArgument;
186+
184187
private static final Method registerMethod;
185188

186189
private static final Method unRegisterMethod;
187190

188191
static {
189192
try {
190193
constructor = getEndpointConstructor();
194+
int parameterCount = constructor.getParameterTypes().length;
195+
constructorWithBooleanArgument = (parameterCount == 10);
196+
if (!constructorWithBooleanArgument && parameterCount != 9) {
197+
throw new IllegalStateException("Expected TyrusEndpointWrapper constructor with 9 or 10 arguments");
198+
}
191199
registerMethod = TyrusWebSocketEngine.class.getDeclaredMethod("register", TyrusEndpointWrapper.class);
192200
unRegisterMethod = TyrusWebSocketEngine.class.getDeclaredMethod("unregister", TyrusEndpointWrapper.class);
193201
ReflectionUtils.makeAccessible(registerMethod);
@@ -216,13 +224,13 @@ public Object createdEndpoint(ServerEndpointRegistration registration, Component
216224
Object sessionListener = accessor.getPropertyValue("sessionListener");
217225
Object clusterContext = accessor.getPropertyValue("clusterContext");
218226
try {
219-
if (constructor.getParameterTypes().length == 9) {
227+
if (constructorWithBooleanArgument) {
220228
return constructor.newInstance(registration.getEndpoint(), registration, provider, container,
221-
"/", registration.getConfigurator(), sessionListener, clusterContext, null);
229+
"/", registration.getConfigurator(), sessionListener, clusterContext, null, Boolean.TRUE);
222230
}
223231
else {
224232
return constructor.newInstance(registration.getEndpoint(), registration, provider, container,
225-
"/", registration.getConfigurator(), sessionListener, clusterContext, null, Boolean.TRUE);
233+
"/", registration.getConfigurator(), sessionListener, clusterContext, null);
226234
}
227235
}
228236
catch (Exception ex) {

0 commit comments

Comments
 (0)