Giter VIP home page Giter VIP logo

Comments (8)

jfarcand avatar jfarcand commented on May 28, 2024

@amy-b-cheng Can you share an app or a test case on github?

from atmosphere.

amy-b-cheng avatar amy-b-cheng commented on May 28, 2024

@jfarcand Hi Jeanfrancois, it's going to take me some time to assemble a testcase since I'm unable to share my application with you. But in the meantime here are some code examples of what I'm talking about, for your clarity.

Here's JSR356Endpoint.java not setting the local attribute:

request = new AtmosphereRequestImpl.Builder()

Here's an example where ProtocolUtil uses the same AtmosphereRequestImpl.Builder but copies the attributes over:

If you were to use AtmosphereRequestImpl#wrap, it would take into account the local attributes:
https://github.com/Atmosphere/atmosphere/blob/atmosphere-2.7.x/modules/cpr/src/main/java/org/atmosphere/cpr/AtmosphereRequestImpl.java#L1409C1-L1423C6

Let me know if that helps you or if you still need a test case to understand this issue.

from atmosphere.

vaslabs avatar vaslabs commented on May 28, 2024

wow, thanks @amy-b-cheng , I have the same issue with Tomcat, I've spent hours on this. indeed the attributes are not copied over. I'll test locally and send a PR if it works out

from atmosphere.

jfarcand avatar jfarcand commented on May 28, 2024

@vaslabs That would be perfect if you can start a PR. I will look at it and integrate/release ASAP.

from atmosphere.

vaslabs avatar vaslabs commented on May 28, 2024

hello, thanks @jfarcand for your response.

It looks to me that there's no way to get the request attributes in the JSR356 implementation, as the HandshakeRequest doesn't require them . For my case tomcat's WsHandshakeRequest doesn't use them as they are of course not required by HandshakeRequest.

So, it seems not possible for servlet filters to add attributes to the HttpServletRequest right now and the only solution I can see is setting Session attributes instead.

This doesn't seem to be a problem for atmosphere but the way javax.websocket.server.HandshakeRequest is defined, it doesn't concern itself with request attributes.

from atmosphere.

amy-b-cheng avatar amy-b-cheng commented on May 28, 2024

@vaslabs are the attributes not in the HandshakeRequest#getHttpSession? I'm trying to see right now if copying over those will fix my problem

i.e.

index 425e5422c..75800de4a 100644
--- a/modules/cpr/src/main/java/org/atmosphere/container/JSR356Endpoint.java
+++ b/modules/cpr/src/main/java/org/atmosphere/container/JSR356Endpoint.java
@@ -43,12 +43,14 @@ import java.net.InetSocketAddress;
 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;
 
@@ -224,6 +226,13 @@ public class JSR356Endpoint extends Endpoint {
                     cookies.addAll(CookieUtil.ServerCookieDecoder.STRICT.decode(cookieHeader));
             }
 
+            final Enumeration<String> attributeNames = handshakeSession.getAttributeNames();
+            final 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)
@@ -237,6 +246,7 @@ public class JSR356Endpoint extends Endpoint {
                     .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());```

from atmosphere.

amy-b-cheng avatar amy-b-cheng commented on May 28, 2024

Yes, the above code is copying the handshakeSession attributes to the AtmosphereRequestImpl. With this change + if inside my ServletFilter I set my custom attributes (which were previously going on the HTTP request) to now go on the session itself, I'm able to read the attributes off the AtmosphereResource downstream.

@jfarcand should I open a pull request?

from atmosphere.

jfarcand avatar jfarcand commented on May 28, 2024

@amy-b-cheng Yes, will take a look!

from atmosphere.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.