Comments (8)
@amy-b-cheng Can you share an app or a test case on github?
from atmosphere.
@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:
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.
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.
@vaslabs That would be perfect if you can start a PR. I will look at it and integrate/release ASAP.
from atmosphere.
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.
@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.
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.
@amy-b-cheng Yes, will take a look!
from atmosphere.
Related Issues (20)
- Jetty 9.4+/10 is throwing and exception when javax.session.Session.addMessageHandler(MessageHandler handler) is called HOT 1
- Potential Refactoring Estimate HOT 1
- SSE doesn't output error bodies, just spaces
- Compress JSON messages with atmosphere
- Compression websocket messages HOT 8
- Provide runtime hints for Spring Boot 3 native applications HOT 1
- Support atmosphere-spring for Jakarta 3.0 jakarta.servlet HOT 8
- Broadcasters with names that contain both { and } are never cleaned up HOT 1
- Websocket trying to reconnect every 30 seconds HOT 1
- AtmosphereResource getting removed from resources list permanently while using Transport.SSE. HOT 3
- Websocket Closing Connection Again and Again HOT 1
- HTTP/3 WebTransport API
- JDK17 breaks working Atmosphere HOT 1
- Long-polling requests show XML parsing syntax error in Firefox console HOT 1
- "org.atmosphere.container.Jetty9AsyncSupportWithWebSocket" does not exist HOT 1
- Is there any security concerns because of query string in request URI
- NPE in AtmosphereRequestImpl because of race condition HOT 1
- NPE in AtmosphereRequestImpl.wrap
- Double string length prepended to cached heartbeat messages HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from atmosphere.