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