codeminders / socket.io-server-java

Java Backend for Socket.IO (http://socket.io/)
36 stars 18 forks source link

Http session isn't available from com.codeminders.socketio.server.Socket with websocket transport at least in Jetty 9.4.7 #22

Open Geminist opened 5 years ago

Geminist commented 5 years ago

Http session isn't available from com.codeminders.socketio.server.Socket with websocket transport at least in Jetty 9.4.7 because of method org.eclipse.jetty.websocket.servlet.UpgradeHttpServletRequest#complete :

public void complete()
{
    request = null;
} 

As a workaround I have overridden WebsocketConfigurator#modifyHandshake :

    @Override
    public void modifyHandshake(
            ServerEndpointConfig config,
            HandshakeRequest request,
            HandshakeResponse response
    ){
        request.getHttpSession(); // it causes session "caching" in UpgradeHttpServletRequest
        super.modifyHandshake(config, request, response);
    }

But it looks like a hack and it isn't so reliable. And more, @ServerEndpoint(value="/socket.io/", configurator = WebsocketConfigurator.class) on WebsocketTransportConnection does not allow easy override configurator.

Geminist commented 5 years ago

It would be great if to make WebsocketTransportConnection non final or create abstract base class with all its functionality to allow easy annotation configuration