title: spring websocket : SubProtocolWebSocketHandler
body: <p>I have stability problems with Spring web-sockets. Sometimes I have a similar exception to that describe in <a href="https://jira.spring.io/browse/SPR-12812" rel="nofollow">https://jira.spring.io/browse/SPR-12812</a>.</p>
  
  <p>The patch is not available, then I have implemented my own code with a custom SubProtocolWebSocketHandler.</p>
  
  <pre>
  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);
      }
  
  }
  </pre>
  
  <p>Now my problem is to reproduce the exception to see if the problem is solved. I tried various ways, but without success. I can not reproduce the closing of the connection. Does anyone have an idea?</p>
  
  <p>We also have a second problem. The client application (angularjs application) sometimes reports that the socket-web connection is lost. But I do not understand why because on the server I have no error / warning in the logs.
  How can I identify the problem and reproduce it?</p>