Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The HttpSession and ServletContext are hard to retrieve: Add argument types for @OnOpen, @OnMessage, @OnError, and @OnClose methods #219

Closed
glassfishrobot opened this issue Dec 7, 2013 · 5 comments
Labels
duplicate This issue or pull request already exists

Comments

@glassfishrobot
Copy link

The HTTP session (HttpSession) and application context (ServletContext) are hard to retrieve within a server endpoint right now. The HTTP session can only be retrieved as described in #218. The ServletContext can only be retrieved if the HTTP session exists and if it is HttpSession, and requires retrieving the HttpSession and calling its getServletContext method.

#217 and #218 describe enhancements to make retrieving the HTTP session and application context easier. However, there's an even easier approach that can be implemented.

@onopen, @OnMessage, @onerror, and @onclose methods can have several different types of arguments that the container automatically supplies, such as the Session and various @PathParam arguments, EndpointConfig for @onopen, CloseReason for @onclose, Throwable for @onerror, and various message objects for @OnMessage. I recommend adding the following valid method parameters for all four annotations:

  • The application context for the deployed application (in a Servlet container, this is a javax.servlet.ServletContext parameter), never null.
  • The HTTP session object linked to the handshake request for this Session (in a Servlet container, this is a javax.servlet.http.HttpSession parameter), null if no HTTP session existed for the handshake request.

This would make generically retrieving the application context (ServletContext) and HTTP session (HttpSession) much easier.

Affected Versions

[2.0]

@glassfishrobot
Copy link
Author

@glassfishrobot Commented
Reported by beamerblvd

@glassfishrobot
Copy link
Author

@glassfishrobot Commented
This issue was imported from java.net JIRA WEBSOCKET_SPEC-219

@glassfishrobot
Copy link
Author

@joakime
Copy link
Contributor

joakime commented Apr 16, 2020

I generally an OK with this proposal, but ONLY for @OnOpen, as HttpSession and ServletContext are not valid once the websocket has been upgraded past the HTTP layer (where both HttpSession and ServletContext reside)

@markt-asf markt-asf added duplicate This issue or pull request already exists and removed Priority: Major Type: Improvement httpsession servlet-context labels May 6, 2020
@markt-asf
Copy link
Contributor

See #238

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants