@@ -65,7 +65,8 @@ public class JSR356Endpoint extends Endpoint {
65
65
private final AtmosphereFramework framework ;
66
66
private WebSocket webSocket ;
67
67
private final int webSocketWriteTimeout ;
68
- private HandshakeRequest handshakeRequest ;
68
+ private HttpSession handshakeSession ;
69
+ private Map <String , List <String >> handshakeHeaders ;
69
70
70
71
public JSR356Endpoint (AtmosphereFramework framework , WebSocketProcessor webSocketProcessor ) {
71
72
this .framework = framework ;
@@ -98,7 +99,12 @@ public JSR356Endpoint(AtmosphereFramework framework, WebSocketProcessor webSocke
98
99
}
99
100
100
101
public JSR356Endpoint handshakeRequest (HandshakeRequest handshakeRequest ) {
101
- this .handshakeRequest = handshakeRequest ;
102
+ this .handshakeSession = (HttpSession ) handshakeRequest .getHttpSession ();
103
+ this .handshakeHeaders = new HashMap <>();
104
+ for (Map .Entry <String , List <String >> e : handshakeRequest .getHeaders ()
105
+ .entrySet ()) {
106
+ handshakeHeaders .put (e .getKey (), e .getValue ());
107
+ }
102
108
return this ;
103
109
}
104
110
@@ -120,7 +126,7 @@ public void onOpen(Session session, final EndpointConfig endpointConfig) {
120
126
121
127
Map <String , String > headers = new HashMap <String , String >();
122
128
// TODO: We don't support multi map header, which cause => https://github.com/Atmosphere/atmosphere/issues/1945
123
- for (Map .Entry <String , List <String >> e : handshakeRequest . getHeaders () .entrySet ()) {
129
+ for (Map .Entry <String , List <String >> e : handshakeHeaders .entrySet ()) {
124
130
headers .put (e .getKey (), !e .getValue ().isEmpty () ? e .getValue ().get (0 ) : "" );
125
131
}
126
132
@@ -182,25 +188,25 @@ public void onOpen(Session session, final EndpointConfig endpointConfig) {
182
188
// https://java.net/jira/browse/WEBSOCKET_SPEC-228
183
189
if ((!requestURL .startsWith ("http://" )) || (!requestURL .startsWith ("https://" ))) {
184
190
if (requestURL .startsWith ("/" )) {
185
- List <String > l = handshakeRequest . getHeaders () .get ("origin" );
191
+ List <String > l = handshakeHeaders .get ("origin" );
186
192
if (l == null ) {
187
193
// https://issues.jboss.org/browse/UNDERTOW-252
188
- l = handshakeRequest . getHeaders () .get ("Origin" );
194
+ l = handshakeHeaders .get ("Origin" );
189
195
}
190
196
String origin = null ;
191
197
if (l != null && !l .isEmpty ()) {
192
198
origin = l .get (0 );
193
- }
194
-
195
- // There is a weird use case when 'Origin' header may contain
199
+ }
200
+
201
+ // There is a weird use case when 'Origin' header may contain
196
202
// 'null', not as value but as a string. In this case the requestURL
197
203
// become something like 'null/path/to/resource'.
198
204
if (origin == null || origin .equalsIgnoreCase ("null" )) {
199
205
// Broken WebSocket Spec
200
206
logger .trace ("Unable to retrieve the `origin` header for websocket {}" , session );
201
207
origin = new StringBuilder ("http" ).append (session .isSecure () ? "s" : "" ).append ("://0.0.0.0:80" ).toString ();
202
208
}
203
-
209
+
204
210
requestURL = new StringBuilder (origin ).append (requestURL ).toString ();
205
211
} else if (requestURL .startsWith ("ws://" )) {
206
212
requestURL = requestURL .replace ("ws://" , "http://" );
@@ -209,20 +215,20 @@ public void onOpen(Session session, final EndpointConfig endpointConfig) {
209
215
}
210
216
}
211
217
212
- List <String > cookieHeaders = handshakeRequest . getHeaders () .get ("Cookie" );
218
+ List <String > cookieHeaders = handshakeHeaders .get ("Cookie" );
213
219
Set <Cookie > cookies = null ;
214
220
if (cookieHeaders != null ) {
215
221
cookies = new HashSet <Cookie >();
216
222
for (String cookieHeader : cookieHeaders )
217
- cookies .addAll (CookieUtil .ServerCookieDecoder .STRICT .decode (cookieHeader ));
223
+ cookies .addAll (CookieUtil .ServerCookieDecoder .STRICT .decode (cookieHeader ));
218
224
}
219
-
225
+
220
226
request = new AtmosphereRequestImpl .Builder ()
221
227
.requestURI (uri .getPath ())
222
228
.requestURL (requestURL )
223
229
.headers (headers )
224
230
.cookies (cookies )
225
- .session (( HttpSession ) handshakeRequest . getHttpSession () )
231
+ .session (handshakeSession )
226
232
.servletPath (servletPath )
227
233
.contextPath (framework .getServletContext ().getContextPath ())
228
234
.pathInfo (pathInfo )
@@ -280,7 +286,7 @@ public void onMessage(ByteBuffer bb) {
280
286
onClose (session , new CloseReason (CloseReason .CloseCodes .GOING_AWAY , "Session closed already" ));
281
287
}
282
288
} catch (Throwable e ) {
283
- if (session .isOpen ()){
289
+ if (session .isOpen ()) {
284
290
logger .error ("" , e );
285
291
} else {
286
292
logger .trace ("Session closed during onOpen" , e );
0 commit comments