0

I have a JSP-type servlet that registers a WebSocket Endpoint with the Servlet container.

I want to pass a reference of that servlet, and/or some of its objects, to the WebSocket Endpoint, so that I can use the code from that servlet, e.g. for Authentication or Session management (the servlet has its own non-Java EE Session management).

I was hoping that I could set some attribute somewhere when I call addEndpoint() on ServerContainer, because at that point I have access to the objects that I want to use later, but none of the classes that I've seen at that point have an attribute collection, e.g.

objectThatWillBeAvailableAtWebSocket.addAttribute("some.custom.object", someObject);

By the time my code reaches an ServletRequestListener, ServerEndpointConfig.Configurator, or the registered Endpoint, I do not have any reference to the original servlet that added the Endpoint.

How can I pass an Object to the WebSocket servlet? I'm running my test code in Embedded Jetty, but I'm aiming for Container-agnostic code.

isapir
  • 21,295
  • 13
  • 115
  • 116
  • 1
    Seems like you could use the techniques outlined in http://stackoverflow.com/a/15649791/775715 – Joakim Erdfelt Sep 27 '16 at 18:56
  • Thanks @JoakimErdfelt -- It'd be much easier if there were Request Attributes at the Handshake, but I think that I'm able to get something to work based on the link that you posted. – isapir Sep 28 '16 at 20:39

0 Answers0