Spring websocket: SubProtocolWebSocketHandler

I'm having stability issues with Spring websockets. Sometimes I have a similar exception described at https://jira.spring.io/browse/SPR-12812 .

No patch available, then I implemented my own code using a custom SubProtocolWebSocketHandler.

public class WBSSubProtocolWebSocketHandler extends SubProtocolWebSocketHandler {

    private static final Logger LOG = LoggerFactory.getLogger (WBSSubProtocolWebSocketHandler.class);

    public WBSSubProtocolWebSocketHandler (MessageChannel clientInboundChannel, SubscribableChannel clientOutboundChannel) {
        super (clientInboundChannel, clientOutboundChannel);
    }

    @Override
    public void afterConnectionClosed (WebSocketSession session, CloseStatus status) throws Exception {
        super.afterConnectionClosed (session, status);
        LOG.debug ("WebSocket Connection closed for client with session ID {}", session.getId ());
    }

    @Override
    public void afterConnectionEstablished (WebSocketSession session) throws Exception {
        // WebSocketHandlerDecorator could close the session
        // https://jira.spring.io/browse/SPR-12812
        if (! session.isOpen ()) {
            LOG.warn ("WebSocket Connection established for client with session ID {} ​​was closed.", Session.getId ());
            return;
        }

        super.afterConnectionEstablished (session);
        LOG.debug ("WebSocket Connection established for client with session ID {}", session.getId ());
    }

    @Override
    public void handleTransportError (WebSocketSession session, Throwable exception) throws Exception {
        super.handleTransportError (session, exception);
        LOG.warn ("WebSocket transport error for client with session ID {}", session.getId ());
    }

    @Override
    public void handleMessage (WebSocketSession session, WebSocketMessage message) throws Exception {
        super.handleMessage (session, message);
        LOG.debug ("Websocket incoming message ({}) from client with session ID {}", message.getPayload (). ToString (), session.getId ());
    }

    @Override
    public void handleMessage (Message message) throws MessagingException {
        super.handleMessage (message);
        LOG.debug ("Websocket incoming message: {}, header {}", message);
    }

}

Now my problem is to reproduce the exception to see if the problem is resolved. I have tried different ways with no success. I cannot reproduce the closing of the connection. Anyone have an idea?

We also have a second problem. The client app (angularjs app) sometimes reports that the socket network connection is lost. But I don't understand why, because on the server I have no errors / warnings in the logs. How can I identify the problem and reproduce it?

+3


source to share





All Articles