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
ConstructorsConstructorDescriptionSockJsWebSocketHandler(SockJsServiceConfig serviceConfig, WebSocketHandler webSocketHandler, WebSocketServerSockJsSession sockJsSession) -
Method Summary
Modifier and TypeMethodDescriptionvoidafterConnectionClosed(WebSocketSession wsSession, CloseStatus status) Invoked after the WebSocket connection has been closed by either side, or after a transport error has occurred.voidafterConnectionEstablished(WebSocketSession wsSession) Invoked after WebSocket negotiation has succeeded and the WebSocket connection is opened and ready for use.protected SockJsServiceConfigReturn the list of supported sub-protocols.voidhandleTextMessage(WebSocketSession wsSession, TextMessage message) voidhandleTransportError(WebSocketSession webSocketSession, Throwable exception) Handle an error from the underlying WebSocket message transport.Methods inherited from class org.springframework.web.socket.handler.TextWebSocketHandler
handleBinaryMessageMethods 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:SubProtocolCapableReturn the list of supported sub-protocols.- Specified by:
getSubProtocolsin interfaceSubProtocolCapable
-
getSockJsConfig
-
afterConnectionEstablished
Description copied from interface:WebSocketHandlerInvoked after WebSocket negotiation has succeeded and the WebSocket connection is opened and ready for use.- Specified by:
afterConnectionEstablishedin interfaceWebSocketHandler- Overrides:
afterConnectionEstablishedin classAbstractWebSocketHandler- Throws:
Exception- this method can handle or propagate exceptions; see class-level Javadoc for details.
-
handleTextMessage
- Overrides:
handleTextMessagein classAbstractWebSocketHandler- Throws:
Exception
-
afterConnectionClosed
Description copied from interface:WebSocketHandlerInvoked 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:
afterConnectionClosedin interfaceWebSocketHandler- Overrides:
afterConnectionClosedin 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:WebSocketHandlerHandle an error from the underlying WebSocket message transport.- Specified by:
handleTransportErrorin interfaceWebSocketHandler- Overrides:
handleTransportErrorin classAbstractWebSocketHandler- Throws:
Exception- this method can handle or propagate exceptions; see class-level Javadoc for details.
-