Optimized support for GlassFish 4.1.1 (Tyrus 1.9 - 1.12)

Issue: SPR-13566
This commit is contained in:
Juergen Hoeller 2015-10-13 20:42:47 +02:00
parent 2e5ddef07d
commit 8fbba84aca
1 changed files with 11 additions and 3 deletions

View File

@ -60,6 +60,7 @@ import org.springframework.web.socket.server.HandshakeFailureException;
* <p>Works with Tyrus 1.3.5 (WebLogic 12.1.3) and Tyrus 1.7+ (GlassFish 4.1.x). * <p>Works with Tyrus 1.3.5 (WebLogic 12.1.3) and Tyrus 1.7+ (GlassFish 4.1.x).
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @author Brian Clozel
* @since 4.1 * @since 4.1
* @see <a href="https://tyrus.java.net/">Project Tyrus</a> * @see <a href="https://tyrus.java.net/">Project Tyrus</a>
*/ */
@ -181,6 +182,8 @@ public abstract class AbstractTyrusRequestUpgradeStrategy extends AbstractStanda
private static final Constructor<?> constructor; private static final Constructor<?> constructor;
private static boolean constructorWithBooleanArgument;
private static final Method registerMethod; private static final Method registerMethod;
private static final Method unRegisterMethod; private static final Method unRegisterMethod;
@ -188,6 +191,11 @@ public abstract class AbstractTyrusRequestUpgradeStrategy extends AbstractStanda
static { static {
try { try {
constructor = getEndpointConstructor(); 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); registerMethod = TyrusWebSocketEngine.class.getDeclaredMethod("register", TyrusEndpointWrapper.class);
unRegisterMethod = TyrusWebSocketEngine.class.getDeclaredMethod("unregister", TyrusEndpointWrapper.class); unRegisterMethod = TyrusWebSocketEngine.class.getDeclaredMethod("unregister", TyrusEndpointWrapper.class);
ReflectionUtils.makeAccessible(registerMethod); ReflectionUtils.makeAccessible(registerMethod);
@ -216,13 +224,13 @@ public abstract class AbstractTyrusRequestUpgradeStrategy extends AbstractStanda
Object sessionListener = accessor.getPropertyValue("sessionListener"); Object sessionListener = accessor.getPropertyValue("sessionListener");
Object clusterContext = accessor.getPropertyValue("clusterContext"); Object clusterContext = accessor.getPropertyValue("clusterContext");
try { try {
if (constructor.getParameterTypes().length == 9) { if (constructorWithBooleanArgument) {
return constructor.newInstance(registration.getEndpoint(), registration, provider, container, return constructor.newInstance(registration.getEndpoint(), registration, provider, container,
"/", registration.getConfigurator(), sessionListener, clusterContext, null); "/", registration.getConfigurator(), sessionListener, clusterContext, null, Boolean.TRUE);
} }
else { else {
return constructor.newInstance(registration.getEndpoint(), registration, provider, container, return constructor.newInstance(registration.getEndpoint(), registration, provider, container,
"/", registration.getConfigurator(), sessionListener, clusterContext, null, Boolean.TRUE); "/", registration.getConfigurator(), sessionListener, clusterContext, null);
} }
} }
catch (Exception ex) { catch (Exception ex) {