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 66297bdb62..0e6a31df0d 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 @@ -53,13 +53,14 @@ import org.springframework.util.StringUtils; import org.springframework.web.socket.WebSocketExtension; import org.springframework.web.socket.server.HandshakeFailureException; -import static org.glassfish.tyrus.spi.WebSocketEngine.UpgradeStatus.SUCCESS; +import static org.glassfish.tyrus.spi.WebSocketEngine.UpgradeStatus.*; /** * A base class for {@code RequestUpgradeStrategy} implementations on top of * JSR-356 based servers which include Tyrus as their WebSocket engine. * - *

Works with Tyrus 1.3.5 (WebLogic 12.1.3) and Tyrus 1.7+ (GlassFish 4.1.x). + *

Works with Tyrus 1.3.5 (WebLogic 12.1.3), Tyrus 1.7 (GlassFish 4.1.0), + * Tyrus 1.11 (WebLogic 12.2.1), and Tyrus 1.12 (GlassFish 4.1.1). * * @author Rossen Stoyanchev * @author Brian Clozel @@ -113,7 +114,7 @@ public abstract class AbstractTyrusRequestUpgradeStrategy extends AbstractStanda success = SUCCESS.equals(upgradeInfo.getStatus()); if (success) { if (logger.isTraceEnabled()) { - logger.trace("Successful upgrade: " + upgradeResponse.getHeaders()); + logger.trace("Successful request upgrade: " + upgradeResponse.getHeaders()); } handleSuccess(servletRequest, servletResponse, upgradeInfo, upgradeResponse); } @@ -231,6 +232,7 @@ public abstract class AbstractTyrusRequestUpgradeStrategy extends AbstractStanda Object clusterContext = accessor.getPropertyValue("clusterContext"); try { if (constructorWithBooleanArgument) { + // Tyrus 1.11+ return constructor.newInstance(registration.getEndpoint(), registration, provider, container, "/", registration.getConfigurator(), sessionListener, clusterContext, null, Boolean.TRUE); } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/server/standard/WebLogicRequestUpgradeStrategy.java b/spring-websocket/src/main/java/org/springframework/web/socket/server/standard/WebLogicRequestUpgradeStrategy.java index 64f1057f6a..c16d747a80 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/server/standard/WebLogicRequestUpgradeStrategy.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/server/standard/WebLogicRequestUpgradeStrategy.java @@ -30,9 +30,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.websocket.CloseReason; -import org.glassfish.tyrus.core.TyrusEndpointWrapper; import org.glassfish.tyrus.core.TyrusUpgradeResponse; -import org.glassfish.tyrus.core.TyrusWebSocketEngine; import org.glassfish.tyrus.core.Utils; import org.glassfish.tyrus.spi.Connection; import org.glassfish.tyrus.spi.WebSocketEngine.UpgradeInfo; @@ -40,45 +38,34 @@ import org.glassfish.tyrus.spi.Writer; import org.springframework.beans.BeanWrapper; import org.springframework.beans.BeanWrapperImpl; -import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; import org.springframework.web.socket.server.HandshakeFailureException; /** * A WebSocket {@code RequestUpgradeStrategy} for Oracle's WebLogic. - * Supports 12.1.3 and 12.2.1.0. + * Supports 12.1.3 as well as 12.2.1, as of Spring Framework 4.2.3. * * @author Rossen Stoyanchev * @since 4.1 */ public class WebLogicRequestUpgradeStrategy extends AbstractTyrusRequestUpgradeStrategy { - private static ClassLoader classLoader = WebLogicRequestUpgradeStrategy.class.getClassLoader(); - private static final boolean WLS_12_1_3 = isWebLogic1213(); - private static final TyrusEndpointHelper endpointHelper = WLS_12_1_3 ? - new Tyrus135EndpointHelper() : new Tyrus17EndpointHelper(); + private static final TyrusEndpointHelper endpointHelper = + (WLS_12_1_3 ? new Tyrus135EndpointHelper() : new Tyrus17EndpointHelper()); private static final TyrusMuxableWebSocketHelper webSocketHelper = new TyrusMuxableWebSocketHelper(); private static final WebLogicServletWriterHelper servletWriterHelper = new WebLogicServletWriterHelper(); + private static final Connection.CloseListener noOpCloseListener = new Connection.CloseListener() { - - private static boolean isWebLogic1213() { - try { - type("weblogic.websocket.tyrus.TyrusMuxableWebSocket").getDeclaredConstructor( - type("weblogic.servlet.internal.MuxableSocketHTTP")); - return true; - } - catch (NoSuchMethodException e) { - return false; - } - catch (ClassNotFoundException ex) { - throw new IllegalStateException("No compatible WebSocket version found", ex); + @Override + public void close(CloseReason reason) { } - } + }; + @Override @@ -114,15 +101,23 @@ public class WebLogicRequestUpgradeStrategy extends AbstractTyrusRequestUpgradeS webSocketHelper.registerForReadEvent(webSocket); } - private static Object getNativeRequest(ServletRequest request) { - while (request instanceof ServletRequestWrapper) { - request = ((ServletRequestWrapper) request).getRequest(); + + private static boolean isWebLogic1213() { + try { + type("weblogic.websocket.tyrus.TyrusMuxableWebSocket").getDeclaredConstructor( + type("weblogic.servlet.internal.MuxableSocketHTTP")); + return true; + } + catch (NoSuchMethodException ex) { + return false; + } + catch (ClassNotFoundException ex) { + throw new IllegalStateException("No compatible WebSocket version found", ex); } - return request; } private static Class type(String className) throws ClassNotFoundException { - return classLoader.loadClass(className); + return WebLogicRequestUpgradeStrategy.class.getClassLoader().loadClass(className); } private static Method method(String className, String method, Class... paramTypes) @@ -131,13 +126,12 @@ public class WebLogicRequestUpgradeStrategy extends AbstractTyrusRequestUpgradeS return type(className).getDeclaredMethod(method, paramTypes); } - - private static final Connection.CloseListener noOpCloseListener = new Connection.CloseListener() { - - @Override - public void close(CloseReason reason) { + private static Object getNativeRequest(ServletRequest request) { + while (request instanceof ServletRequestWrapper) { + request = ((ServletRequestWrapper) request).getRequest(); } - }; + return request; + } /** @@ -158,6 +152,7 @@ public class WebLogicRequestUpgradeStrategy extends AbstractTyrusRequestUpgradeS static { try { type = type("weblogic.websocket.tyrus.TyrusMuxableWebSocket"); + if (WLS_12_1_3) { constructor = type.getDeclaredConstructor(type("weblogic.servlet.internal.MuxableSocketHTTP")); subjectHelper = null; @@ -171,7 +166,6 @@ public class WebLogicRequestUpgradeStrategy extends AbstractTyrusRequestUpgradeS } upgradeMethod = type.getMethod("upgrade", type("weblogic.socket.MuxableSocket"), ServletContext.class); - readEventMethod = type.getMethod("registerForReadEvent"); } catch (Exception ex) { @@ -181,10 +175,8 @@ public class WebLogicRequestUpgradeStrategy extends AbstractTyrusRequestUpgradeS private Object newInstance(HttpServletRequest request, Object httpSocket) { try { - Object[] args = (WLS_12_1_3 ? - new Object[] {httpSocket} : + Object[] args = (WLS_12_1_3 ? new Object[] {httpSocket} : new Object[] {httpSocket, null, subjectHelper.getSubject(request)}); - return constructor.newInstance(args); } catch (Exception ex) { @@ -211,6 +203,7 @@ public class WebLogicRequestUpgradeStrategy extends AbstractTyrusRequestUpgradeS } } + private static class SubjectHelper { private final Method securityContextMethod; @@ -221,7 +214,6 @@ public class WebLogicRequestUpgradeStrategy extends AbstractTyrusRequestUpgradeS private final Method anonymousSubjectMethod; - public SubjectHelper() { try { String className = "weblogic.servlet.internal.WebAppServletContext"; @@ -258,6 +250,7 @@ public class WebLogicRequestUpgradeStrategy extends AbstractTyrusRequestUpgradeS } } + /** * Helps to create and invoke {@code weblogic.websocket.tyrus.TyrusServletWriter}. */