30
30
import javax .servlet .http .HttpServletResponse ;
31
31
import javax .websocket .CloseReason ;
32
32
33
- import org .glassfish .tyrus .core .TyrusEndpointWrapper ;
34
33
import org .glassfish .tyrus .core .TyrusUpgradeResponse ;
35
- import org .glassfish .tyrus .core .TyrusWebSocketEngine ;
36
34
import org .glassfish .tyrus .core .Utils ;
37
35
import org .glassfish .tyrus .spi .Connection ;
38
36
import org .glassfish .tyrus .spi .WebSocketEngine .UpgradeInfo ;
39
37
import org .glassfish .tyrus .spi .Writer ;
40
38
41
39
import org .springframework .beans .BeanWrapper ;
42
40
import org .springframework .beans .BeanWrapperImpl ;
43
- import org .springframework .util .ClassUtils ;
44
41
import org .springframework .util .ReflectionUtils ;
45
42
import org .springframework .web .socket .server .HandshakeFailureException ;
46
43
47
44
/**
48
45
* 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 .
50
47
*
51
48
* @author Rossen Stoyanchev
52
49
* @since 4.1
53
50
*/
54
51
public class WebLogicRequestUpgradeStrategy extends AbstractTyrusRequestUpgradeStrategy {
55
52
56
- private static ClassLoader classLoader = WebLogicRequestUpgradeStrategy .class .getClassLoader ();
57
-
58
53
private static final boolean WLS_12_1_3 = isWebLogic1213 ();
59
54
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 () );
62
57
63
58
private static final TyrusMuxableWebSocketHelper webSocketHelper = new TyrusMuxableWebSocketHelper ();
64
59
65
60
private static final WebLogicServletWriterHelper servletWriterHelper = new WebLogicServletWriterHelper ();
66
61
62
+ private static final Connection .CloseListener noOpCloseListener = new Connection .CloseListener () {
67
63
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 ) {
80
66
}
81
- }
67
+ };
68
+
82
69
83
70
84
71
@ Override
@@ -114,15 +101,23 @@ protected void handleSuccess(HttpServletRequest request, HttpServletResponse res
114
101
webSocketHelper .registerForReadEvent (webSocket );
115
102
}
116
103
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 );
120
116
}
121
- return request ;
122
117
}
123
118
124
119
private static Class <?> type (String className ) throws ClassNotFoundException {
125
- return classLoader .loadClass (className );
120
+ return WebLogicRequestUpgradeStrategy . class . getClassLoader () .loadClass (className );
126
121
}
127
122
128
123
private static Method method (String className , String method , Class <?>... paramTypes )
@@ -131,13 +126,12 @@ private static Method method(String className, String method, Class<?>... paramT
131
126
return type (className ).getDeclaredMethod (method , paramTypes );
132
127
}
133
128
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 ();
139
132
}
140
- };
133
+ return request ;
134
+ }
141
135
142
136
143
137
/**
@@ -158,6 +152,7 @@ private static class TyrusMuxableWebSocketHelper {
158
152
static {
159
153
try {
160
154
type = type ("weblogic.websocket.tyrus.TyrusMuxableWebSocket" );
155
+
161
156
if (WLS_12_1_3 ) {
162
157
constructor = type .getDeclaredConstructor (type ("weblogic.servlet.internal.MuxableSocketHTTP" ));
163
158
subjectHelper = null ;
@@ -171,7 +166,6 @@ private static class TyrusMuxableWebSocketHelper {
171
166
}
172
167
173
168
upgradeMethod = type .getMethod ("upgrade" , type ("weblogic.socket.MuxableSocket" ), ServletContext .class );
174
-
175
169
readEventMethod = type .getMethod ("registerForReadEvent" );
176
170
}
177
171
catch (Exception ex ) {
@@ -181,10 +175,8 @@ private static class TyrusMuxableWebSocketHelper {
181
175
182
176
private Object newInstance (HttpServletRequest request , Object httpSocket ) {
183
177
try {
184
- Object [] args = (WLS_12_1_3 ?
185
- new Object [] {httpSocket } :
178
+ Object [] args = (WLS_12_1_3 ? new Object [] {httpSocket } :
186
179
new Object [] {httpSocket , null , subjectHelper .getSubject (request )});
187
-
188
180
return constructor .newInstance (args );
189
181
}
190
182
catch (Exception ex ) {
@@ -211,6 +203,7 @@ private void registerForReadEvent(Object webSocket) {
211
203
}
212
204
}
213
205
206
+
214
207
private static class SubjectHelper {
215
208
216
209
private final Method securityContextMethod ;
@@ -221,7 +214,6 @@ private static class SubjectHelper {
221
214
222
215
private final Method anonymousSubjectMethod ;
223
216
224
-
225
217
public SubjectHelper () {
226
218
try {
227
219
String className = "weblogic.servlet.internal.WebAppServletContext" ;
@@ -258,6 +250,7 @@ public Object getSubject(HttpServletRequest request) {
258
250
}
259
251
}
260
252
253
+
261
254
/**
262
255
* Helps to create and invoke {@code weblogic.websocket.tyrus.TyrusServletWriter}.
263
256
*/
0 commit comments