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:09:13 +02:00
parent 0086dd830b
commit c33c26ac5d
1 changed files with 16 additions and 2 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).
*
* @author Rossen Stoyanchev
* @author Brian Clozel
* @since 4.1
* @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 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);