Skip to content

Commit

Permalink
Merge pull request #2504 from amy-b-cheng/read-session-attributes
Browse files Browse the repository at this point in the history
JSR356Endpoint to read attributes from the handshake session
  • Loading branch information
jfarcand committed Mar 21, 2024
2 parents 09a9fa7 + d5b0269 commit d54e08e
Showing 1 changed file with 10 additions and 0 deletions.
Expand Up @@ -43,12 +43,14 @@
import java.net.URI;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;

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

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

Enumeration<String> attributeNames = handshakeSession.getAttributeNames();
Map<String, Object> attributes = new ConcurrentHashMap<>();
while (attributeNames.hasMoreElements()) {
String attributeName = attributeNames.nextElement();
attributes.put(attributeName, handshakeSession.getAttribute(attributeName));
}

request = new AtmosphereRequestImpl.Builder()
.requestURI(uri.getPath())
.requestURL(requestURL)
Expand All @@ -237,6 +246,7 @@ public void onOpen(Session session, final EndpointConfig endpointConfig) {
.userPrincipal(session.getUserPrincipal())
.remoteInetSocketAddress((Callable<InetSocketAddress>) () -> (InetSocketAddress) endpointConfig.getUserProperties().get(JAVAX_WEBSOCKET_ENDPOINT_REMOTE_ADDRESS))
.localInetSocketAddress((Callable<InetSocketAddress>) () -> (InetSocketAddress) endpointConfig.getUserProperties().get(JAVAX_WEBSOCKET_ENDPOINT_LOCAL_ADDRESS))
.attributes(attributes)
.build()
.queryString(session.getQueryString());

Expand Down

0 comments on commit d54e08e

Please sign in to comment.