org.springframework.web.socket.sockjs.transport.handler

## Class SockJsWebSocketHandler

- java.lang.Object
- - org.springframework.web.socket.handler.AbstractWebSocketHandler
  - - org.springframework.web.socket.handler.TextWebSocketHandler
    - - org.springframework.web.socket.sockjs.transport.handler.SockJsWebSocketHandler

All Implemented Interfaces:
  SubProtocolCapable, WebSocketHandler

    public class SockJsWebSocketHandler
    extends TextWebSocketHandler
    implements SubProtocolCapable

An implementation of `WebSocketHandler` that adds SockJS messages frames, sends SockJS heartbeat messages, and delegates lifecycle events and messages to a target `WebSocketHandler`.

Methods in this class allow exceptions from the wrapped `WebSocketHandler` to propagate. However, any exceptions resulting from SockJS message handling (e.g. while sending SockJS frames or heartbeat messages) are caught and treated as transport errors, i.e. routed to the `handleTransportError` method of the wrapped handler and the session closed.

Since:
  4.0
Author:
  Rossen Stoyanchev

### Constructor Summary

Constructors
Constructor and Description
`SockJsWebSocketHandler(SockJsServiceConfig serviceConfig, WebSocketHandler webSocketHandler, WebSocketServerSockJsSession sockJsSession)`

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `afterConnectionClosed(WebSocketSession wsSession, CloseStatus status)` Invoked after the WebSocket connection has been closed by either side, or after a transport error has occurred.
`void` `afterConnectionEstablished(WebSocketSession wsSession)` Invoked after WebSocket negotiation has succeeded and the WebSocket connection is opened and ready for use.
`protected SockJsServiceConfig` `getSockJsConfig()`
`List<String>` `getSubProtocols()` Return the list of supported sub-protocols.
`void` `handleTextMessage(WebSocketSession wsSession, TextMessage message)`
`void` `handleTransportError(WebSocketSession webSocketSession, Throwable exception)` Handle an error from the underlying WebSocket message transport.

### Methods inherited from class org.springframework.web.socket.handler.TextWebSocketHandler

`handleBinaryMessage`

### Methods inherited from class org.springframework.web.socket.handler.AbstractWebSocketHandler

`handleMessage, handlePongMessage, supportsPartialMessages`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### SockJsWebSocketHandler

    public SockJsWebSocketHandler(SockJsServiceConfig serviceConfig,
                                  WebSocketHandler webSocketHandler,
                                  WebSocketServerSockJsSession sockJsSession)

### Method Detail

#### getSubProtocols

    public List<String> getSubProtocols()

Description copied from interface: `SubProtocolCapable`
Return the list of supported sub-protocols.

Specified by:
  `getSubProtocols` in interface `SubProtocolCapable`

#### getSockJsConfig

    protected SockJsServiceConfig getSockJsConfig()

#### afterConnectionEstablished

    public void afterConnectionEstablished(WebSocketSession wsSession)
                                    throws Exception

Description copied from interface: `WebSocketHandler`
Invoked after WebSocket negotiation has succeeded and the WebSocket connection is opened and ready for use.

Specified by:
  `afterConnectionEstablished` in interface `WebSocketHandler`
Overrides:
  `afterConnectionEstablished` in class `AbstractWebSocketHandler`
Throws:
  `Exception` - this method can handle or propagate exceptions; see class-level Javadoc for details.

#### handleTextMessage

    public void handleTextMessage(WebSocketSession wsSession,
                                  TextMessage message)
                           throws Exception

Overrides:
  `handleTextMessage` in class `AbstractWebSocketHandler`
Throws:
  `Exception`

#### afterConnectionClosed

    public void afterConnectionClosed(WebSocketSession wsSession,
                                      CloseStatus status)
                               throws Exception

Description copied from interface: `WebSocketHandler`
Invoked after the WebSocket connection has been closed by either side, or after a transport error has occurred. Although the session may technically still be open, depending on the underlying implementation, sending messages at this point is discouraged and most likely will not succeed.

Specified by:
  `afterConnectionClosed` in interface `WebSocketHandler`
Overrides:
  `afterConnectionClosed` in class `AbstractWebSocketHandler`
Throws:
  `Exception` - this method can handle or propagate exceptions; see class-level Javadoc for details.

#### handleTransportError

    public void handleTransportError(WebSocketSession webSocketSession,
                                     Throwable exception)
                              throws Exception

Description copied from interface: `WebSocketHandler`
Handle an error from the underlying WebSocket message transport.

Specified by:
  `handleTransportError` in interface `WebSocketHandler`
Overrides:
  `handleTransportError` in class `AbstractWebSocketHandler`
Throws:
  `Exception` - this method can handle or propagate exceptions; see class-level Javadoc for details.