Skip to content

Commit d5b0269

Browse files
committed
JSR356Endpoint to read attributes from the handshake session into the AtmosphereRequest
1 parent 09a9fa7 commit d5b0269

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

modules/cpr/src/main/java/org/atmosphere/container/JSR356Endpoint.java

+10
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@
4343
import java.net.URI;
4444
import java.nio.Buffer;
4545
import java.nio.ByteBuffer;
46+
import java.util.Enumeration;
4647
import java.util.HashMap;
4748
import java.util.HashSet;
4849
import java.util.List;
4950
import java.util.Map;
5051
import java.util.Set;
5152
import java.util.concurrent.Callable;
53+
import java.util.concurrent.ConcurrentHashMap;
5254

5355
import static org.atmosphere.cpr.ApplicationConfig.ALLOW_QUERYSTRING_AS_REQUEST;
5456

@@ -224,6 +226,13 @@ public void onOpen(Session session, final EndpointConfig endpointConfig) {
224226
cookies.addAll(CookieUtil.ServerCookieDecoder.STRICT.decode(cookieHeader));
225227
}
226228

229+
Enumeration<String> attributeNames = handshakeSession.getAttributeNames();
230+
Map<String, Object> attributes = new ConcurrentHashMap<>();
231+
while (attributeNames.hasMoreElements()) {
232+
String attributeName = attributeNames.nextElement();
233+
attributes.put(attributeName, handshakeSession.getAttribute(attributeName));
234+
}
235+
227236
request = new AtmosphereRequestImpl.Builder()
228237
.requestURI(uri.getPath())
229238
.requestURL(requestURL)
@@ -237,6 +246,7 @@ public void onOpen(Session session, final EndpointConfig endpointConfig) {
237246
.userPrincipal(session.getUserPrincipal())
238247
.remoteInetSocketAddress((Callable<InetSocketAddress>) () -> (InetSocketAddress) endpointConfig.getUserProperties().get(JAVAX_WEBSOCKET_ENDPOINT_REMOTE_ADDRESS))
239248
.localInetSocketAddress((Callable<InetSocketAddress>) () -> (InetSocketAddress) endpointConfig.getUserProperties().get(JAVAX_WEBSOCKET_ENDPOINT_LOCAL_ADDRESS))
249+
.attributes(attributes)
240250
.build()
241251
.queryString(session.getQueryString());
242252

0 commit comments

Comments
 (0)