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
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
ConstructorDescriptionSockJsWebSocketHandler
(SockJsServiceConfig serviceConfig, WebSocketHandler webSocketHandler, WebSocketServerSockJsSession sockJsSession) -
Method Summary
Modifier and TypeMethodDescriptionvoid
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
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 Details
-
SockJsWebSocketHandler
public SockJsWebSocketHandler(SockJsServiceConfig serviceConfig, WebSocketHandler webSocketHandler, WebSocketServerSockJsSession sockJsSession)
-
-
Method Details
-
getSubProtocols
Description copied from interface:SubProtocolCapable
Return the list of supported sub-protocols.- Specified by:
getSubProtocols
in interfaceSubProtocolCapable
-
getSockJsConfig
-
afterConnectionEstablished
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
- Overrides:
handleTextMessage
in classAbstractWebSocketHandler
- Throws:
Exception
-
afterConnectionClosed
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.
-