Skip to content

Commit 5d454d5

Browse files
committed
Polishing
1 parent 9e03e0e commit 5d454d5

File tree

2 files changed

+35
-40
lines changed

2 files changed

+35
-40
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,14 @@
5353
import org.springframework.web.socket.WebSocketExtension;
5454
import org.springframework.web.socket.server.HandshakeFailureException;
5555

56-
import static org.glassfish.tyrus.spi.WebSocketEngine.UpgradeStatus.SUCCESS;
56+
import static org.glassfish.tyrus.spi.WebSocketEngine.UpgradeStatus.*;
5757

5858
/**
5959
* A base class for {@code RequestUpgradeStrategy} implementations on top of
6060
* JSR-356 based servers which include Tyrus as their WebSocket engine.
6161
*
62-
* <p>Works with Tyrus 1.3.5 (WebLogic 12.1.3) and Tyrus 1.7+ (GlassFish 4.1.x).
62+
* <p>Works with Tyrus 1.3.5 (WebLogic 12.1.3), Tyrus 1.7 (GlassFish 4.1.0),
63+
* Tyrus 1.11 (WebLogic 12.2.1), and Tyrus 1.12 (GlassFish 4.1.1).
6364
*
6465
* @author Rossen Stoyanchev
6566
* @author Brian Clozel
@@ -113,7 +114,7 @@ public void upgradeInternal(ServerHttpRequest request, ServerHttpResponse respon
113114
success = SUCCESS.equals(upgradeInfo.getStatus());
114115
if (success) {
115116
if (logger.isTraceEnabled()) {
116-
logger.trace("Successful upgrade: " + upgradeResponse.getHeaders());
117+
logger.trace("Successful request upgrade: " + upgradeResponse.getHeaders());
117118
}
118119
handleSuccess(servletRequest, servletResponse, upgradeInfo, upgradeResponse);
119120
}
@@ -231,6 +232,7 @@ public Object createdEndpoint(ServerEndpointRegistration registration, Component
231232
Object clusterContext = accessor.getPropertyValue("clusterContext");
232233
try {
233234
if (constructorWithBooleanArgument) {
235+
// Tyrus 1.11+
234236
return constructor.newInstance(registration.getEndpoint(), registration, provider, container,
235237
"/", registration.getConfigurator(), sessionListener, clusterContext, null, Boolean.TRUE);
236238
}

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

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -30,55 +30,42 @@
3030
import javax.servlet.http.HttpServletResponse;
3131
import javax.websocket.CloseReason;
3232

33-
import org.glassfish.tyrus.core.TyrusEndpointWrapper;
3433
import org.glassfish.tyrus.core.TyrusUpgradeResponse;
35-
import org.glassfish.tyrus.core.TyrusWebSocketEngine;
3634
import org.glassfish.tyrus.core.Utils;
3735
import org.glassfish.tyrus.spi.Connection;
3836
import org.glassfish.tyrus.spi.WebSocketEngine.UpgradeInfo;
3937
import org.glassfish.tyrus.spi.Writer;
4038

4139
import org.springframework.beans.BeanWrapper;
4240
import org.springframework.beans.BeanWrapperImpl;
43-
import org.springframework.util.ClassUtils;
4441
import org.springframework.util.ReflectionUtils;
4542
import org.springframework.web.socket.server.HandshakeFailureException;
4643

4744
/**
4845
* A WebSocket {@code RequestUpgradeStrategy} for Oracle's WebLogic.
49-
* Supports 12.1.3 and 12.2.1.0.
46+
* Supports 12.1.3 as well as 12.2.1, as of Spring Framework 4.2.3.
5047
*
5148
* @author Rossen Stoyanchev
5249
* @since 4.1
5350
*/
5451
public class WebLogicRequestUpgradeStrategy extends AbstractTyrusRequestUpgradeStrategy {
5552

56-
private static ClassLoader classLoader = WebLogicRequestUpgradeStrategy.class.getClassLoader();
57-
5853
private static final boolean WLS_12_1_3 = isWebLogic1213();
5954

60-
private static final TyrusEndpointHelper endpointHelper = WLS_12_1_3 ?
61-
new Tyrus135EndpointHelper() : new Tyrus17EndpointHelper();
55+
private static final TyrusEndpointHelper endpointHelper =
56+
(WLS_12_1_3 ? new Tyrus135EndpointHelper() : new Tyrus17EndpointHelper());
6257

6358
private static final TyrusMuxableWebSocketHelper webSocketHelper = new TyrusMuxableWebSocketHelper();
6459

6560
private static final WebLogicServletWriterHelper servletWriterHelper = new WebLogicServletWriterHelper();
6661

62+
private static final Connection.CloseListener noOpCloseListener = new Connection.CloseListener() {
6763

68-
69-
private static boolean isWebLogic1213() {
70-
try {
71-
type("weblogic.websocket.tyrus.TyrusMuxableWebSocket").getDeclaredConstructor(
72-
type("weblogic.servlet.internal.MuxableSocketHTTP"));
73-
return true;
74-
}
75-
catch (NoSuchMethodException e) {
76-
return false;
77-
}
78-
catch (ClassNotFoundException ex) {
79-
throw new IllegalStateException("No compatible WebSocket version found", ex);
64+
@Override
65+
public void close(CloseReason reason) {
8066
}
81-
}
67+
};
68+
8269

8370

8471
@Override
@@ -114,15 +101,23 @@ protected void handleSuccess(HttpServletRequest request, HttpServletResponse res
114101
webSocketHelper.registerForReadEvent(webSocket);
115102
}
116103

117-
private static Object getNativeRequest(ServletRequest request) {
118-
while (request instanceof ServletRequestWrapper) {
119-
request = ((ServletRequestWrapper) request).getRequest();
104+
105+
private static boolean isWebLogic1213() {
106+
try {
107+
type("weblogic.websocket.tyrus.TyrusMuxableWebSocket").getDeclaredConstructor(
108+
type("weblogic.servlet.internal.MuxableSocketHTTP"));
109+
return true;
110+
}
111+
catch (NoSuchMethodException ex) {
112+
return false;
113+
}
114+
catch (ClassNotFoundException ex) {
115+
throw new IllegalStateException("No compatible WebSocket version found", ex);
120116
}
121-
return request;
122117
}
123118

124119
private static Class<?> type(String className) throws ClassNotFoundException {
125-
return classLoader.loadClass(className);
120+
return WebLogicRequestUpgradeStrategy.class.getClassLoader().loadClass(className);
126121
}
127122

128123
private static Method method(String className, String method, Class<?>... paramTypes)
@@ -131,13 +126,12 @@ private static Method method(String className, String method, Class<?>... paramT
131126
return type(className).getDeclaredMethod(method, paramTypes);
132127
}
133128

134-
135-
private static final Connection.CloseListener noOpCloseListener = new Connection.CloseListener() {
136-
137-
@Override
138-
public void close(CloseReason reason) {
129+
private static Object getNativeRequest(ServletRequest request) {
130+
while (request instanceof ServletRequestWrapper) {
131+
request = ((ServletRequestWrapper) request).getRequest();
139132
}
140-
};
133+
return request;
134+
}
141135

142136

143137
/**
@@ -158,6 +152,7 @@ private static class TyrusMuxableWebSocketHelper {
158152
static {
159153
try {
160154
type = type("weblogic.websocket.tyrus.TyrusMuxableWebSocket");
155+
161156
if (WLS_12_1_3) {
162157
constructor = type.getDeclaredConstructor(type("weblogic.servlet.internal.MuxableSocketHTTP"));
163158
subjectHelper = null;
@@ -171,7 +166,6 @@ private static class TyrusMuxableWebSocketHelper {
171166
}
172167

173168
upgradeMethod = type.getMethod("upgrade", type("weblogic.socket.MuxableSocket"), ServletContext.class);
174-
175169
readEventMethod = type.getMethod("registerForReadEvent");
176170
}
177171
catch (Exception ex) {
@@ -181,10 +175,8 @@ private static class TyrusMuxableWebSocketHelper {
181175

182176
private Object newInstance(HttpServletRequest request, Object httpSocket) {
183177
try {
184-
Object[] args = (WLS_12_1_3 ?
185-
new Object[] {httpSocket} :
178+
Object[] args = (WLS_12_1_3 ? new Object[] {httpSocket} :
186179
new Object[] {httpSocket, null, subjectHelper.getSubject(request)});
187-
188180
return constructor.newInstance(args);
189181
}
190182
catch (Exception ex) {
@@ -211,6 +203,7 @@ private void registerForReadEvent(Object webSocket) {
211203
}
212204
}
213205

206+
214207
private static class SubjectHelper {
215208

216209
private final Method securityContextMethod;
@@ -221,7 +214,6 @@ private static class SubjectHelper {
221214

222215
private final Method anonymousSubjectMethod;
223216

224-
225217
public SubjectHelper() {
226218
try {
227219
String className = "weblogic.servlet.internal.WebAppServletContext";
@@ -258,6 +250,7 @@ public Object getSubject(HttpServletRequest request) {
258250
}
259251
}
260252

253+
261254
/**
262255
* Helps to create and invoke {@code weblogic.websocket.tyrus.TyrusServletWriter}.
263256
*/

0 commit comments

Comments
 (0)