https://github.com/abhirockzz/websocket-http-session
How to access HttpSession in WebSocket endpoint
https://github.com/abhirockzz/websocket-http-session
httpsession javaee7 jsr356 servlet websocket
Last synced: 9 months ago
JSON representation
How to access HttpSession in WebSocket endpoint
- Host: GitHub
- URL: https://github.com/abhirockzz/websocket-http-session
- Owner: abhirockzz
- License: mit
- Created: 2017-04-16T18:11:34.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-04-16T18:23:29.000Z (over 8 years ago)
- Last Synced: 2025-03-24T00:24:34.167Z (9 months ago)
- Topics: httpsession, javaee7, jsr356, servlet, websocket
- Language: Java
- Homepage: https://abhirockzz.wordpress.com/2017/06/03/accessing-http-session-in-websocket-endpoint/
- Size: 9.77 KB
- Stars: 2
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## To run
- `git clone` the project and execute `mvn clean install`
- Deploy `websocket-http-session.war` in `target` directory to any of the [Java EE 7 containers](http://www.oracle.com/technetwork/java/javaee/overview/compatibility-jsp-136984.html)
## To check
- Connect to the WebSocket endpoint `ws://localhost:8080/websocket-http-session/abhi/` (`abhi` is the user). You'll see a [response](https://github.com/abhirockzz/websocket-http-session/blob/master/src/main/java/com/wordpress/abhirockzz/websocket/http_session/Service.java#L21) such as `User abhi | WebSocket session ID 6e4b4986-2f25-4fb7-8a48-d08d8aeec66e | HTTP session ID 7cabd435d20caf3d2a6a1c6a95a4`
- Simulate another user (gitu) `ws://localhost:8080/websocket-http-session/abhi/`. You'll get back details of the HTTP and WebSocket session IDs e.g. `User gitu | WebSocket session ID 8b61fc99-efb7-476b-a12f-2c0d9d432395 | HTTP session ID 7d521c624aaca2127c6331f87253`
## Test
You can also execute a simple test located in the [`test`](https://github.com/abhirockzz/websocket-http-session/blob/master/test/src/test/java/com/wordpress/abhirockzz/websocket/http_session/test/WebSocketEndpointConcurrencyTest.java#L58) project. It's built using the WebSocket client API
- `cd \test`
- `mvn test`