From c33c26ac5d99e37c5e460c8e7441434ea61cd288 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 13 Oct 2015 20:09:13 +0200 Subject: [PATCH] Support for GlassFish 4.1.1 (Tyrus 1.9 - 1.12) Issue: SPR-13566 --- .../AbstractTyrusRequestUpgradeStrategy.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/server/standard/AbstractTyrusRequestUpgradeStrategy.java b/spring-websocket/src/main/java/org/springframework/web/socket/server/standard/AbstractTyrusRequestUpgradeStrategy.java index 8d0077e2a5a..b64e60e5552 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/server/standard/AbstractTyrusRequestUpgradeStrategy.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/server/standard/AbstractTyrusRequestUpgradeStrategy.java @@ -60,6 +60,7 @@ import org.springframework.web.socket.server.HandshakeFailureException; *

Works with Tyrus 1.3.5 (WebLogic 12.1.3) and Tyrus 1.7+ (GlassFish 4.1.x). * * @author Rossen Stoyanchev + * @author Brian Clozel * @since 4.1 * @see Project Tyrus */ @@ -181,6 +182,8 @@ public abstract class AbstractTyrusRequestUpgradeStrategy extends AbstractStanda private static final Constructor constructor; + private static boolean constructorWithBooleanArgument; + private static final Method registerMethod; private static final Method unRegisterMethod; @@ -188,6 +191,11 @@ public abstract class AbstractTyrusRequestUpgradeStrategy extends AbstractStanda static { try { constructor = getEndpointConstructor(); + int parameterCount = constructor.getParameterTypes().length; + constructorWithBooleanArgument = (parameterCount == 10); + if (!constructorWithBooleanArgument && parameterCount != 9) { + throw new IllegalStateException("Expected TyrusEndpointWrapper constructor with 9 or 10 arguments"); + } registerMethod = TyrusWebSocketEngine.class.getDeclaredMethod("register", TyrusEndpointWrapper.class); unRegisterMethod = TyrusWebSocketEngine.class.getDeclaredMethod("unregister", TyrusEndpointWrapper.class); ReflectionUtils.makeAccessible(registerMethod); @@ -216,8 +224,14 @@ public abstract class AbstractTyrusRequestUpgradeStrategy extends AbstractStanda Object sessionListener = accessor.getPropertyValue("sessionListener"); Object clusterContext = accessor.getPropertyValue("clusterContext"); try { - return constructor.newInstance(registration.getEndpoint(), registration, provider, container, - "/", registration.getConfigurator(), sessionListener, clusterContext, null); + if (constructorWithBooleanArgument) { + return constructor.newInstance(registration.getEndpoint(), registration, provider, container, + "/", registration.getConfigurator(), sessionListener, clusterContext, null, Boolean.TRUE); + } + else { + return constructor.newInstance(registration.getEndpoint(), registration, provider, container, + "/", registration.getConfigurator(), sessionListener, clusterContext, null); + } } catch (Exception ex) { throw new HandshakeFailureException("Failed to register " + registration, ex);