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 ofWebSocketHandler
that adds SockJS messages frames, sends SockJS heartbeat messages, and delegates lifecycle events and messages to a targetWebSocketHandler
.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 thehandleTransportError
method of the wrapped handler and the session closed.- Since:
- 4.0
- Author:
- Rossen Stoyanchev
Constructor Summary
Constructors Constructor Description SockJsWebSocketHandler(SockJsServiceConfig serviceConfig, WebSocketHandler webSocketHandler, WebSocketServerSockJsSession sockJsSession)
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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
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 interfaceSubProtocolCapable
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 interfaceWebSocketHandler
- Overrides:
afterConnectionEstablished
in classAbstractWebSocketHandler
- 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 classAbstractWebSocketHandler
- 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 interfaceWebSocketHandler
- Overrides:
afterConnectionClosed
in classAbstractWebSocketHandler
- 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 interfaceWebSocketHandler
- Overrides:
handleTransportError
in classAbstractWebSocketHandler
- Throws:
Exception
- this method can handle or propagate exceptions; see class-level Javadoc for details.