websocket-spec
  1. websocket-spec
  2. WEBSOCKET_SPEC-219

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

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.0
    • Fix Version/s: None
    • Labels:
      None

      Description

      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 WEBSOCKET_SPEC-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.

      WEBSOCKET_SPEC-217 and WEBSOCKET_SPEC-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.

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Unassigned
            Reporter:
            Nick Williams
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: