接口 WebSocketHandler
- 所有已知实现类:
AbstractWebSocketHandler
,BinaryWebSocketHandler
,ExceptionWebSocketHandlerDecorator
,LoggingWebSocketHandlerDecorator
,PerConnectionWebSocketHandler
,SockJsWebSocketHandler
,SubProtocolWebSocketHandler
,TextWebSocketHandler
,WebSocketHandlerDecorator
public interface WebSocketHandler
A handler for WebSocket messages and lifecycle events.Implementations of this interface are encouraged to handle exceptions locally where it makes sense or alternatively let the exception bubble up in which case by default the exception is logged and the session closed with
SERVER_ERROR(1011)
. The exception handling strategy is provided byExceptionWebSocketHandlerDecorator
and it can be customized or replaced by decorating theWebSocketHandler
with a different decorator.- 从以下版本开始:
- 4.0
- 作者:
- Rossen Stoyanchev, Phillip Webb
方法概要
所有方法 实例方法 抽象方法 修饰符和类型 方法 说明 void
afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus)
Invoked after the WebSocket connection has been closed by either side, or after a transport error has occurred.void
afterConnectionEstablished(WebSocketSession session)
Invoked after WebSocket negotiation has succeeded and the WebSocket connection is opened and ready for use.void
handleMessage(WebSocketSession session, WebSocketMessage<?> message)
Invoked when a new WebSocket message arrives.void
handleTransportError(WebSocketSession session, Throwable exception)
Handle an error from the underlying WebSocket message transport.boolean
supportsPartialMessages()
Whether the WebSocketHandler handles partial messages.
方法详细资料
afterConnectionEstablished
void afterConnectionEstablished(WebSocketSession session) throws Exception
Invoked after WebSocket negotiation has succeeded and the WebSocket connection is opened and ready for use.- 抛出:
Exception
- this method can handle or propagate exceptions; see class-level Javadoc for details.
handleMessage
void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception
Invoked when a new WebSocket message arrives.- 抛出:
Exception
- this method can handle or propagate exceptions; see class-level Javadoc for details.
handleTransportError
void handleTransportError(WebSocketSession session, Throwable exception) throws Exception
Handle an error from the underlying WebSocket message transport.- 抛出:
Exception
- this method can handle or propagate exceptions; see class-level Javadoc for details.
afterConnectionClosed
void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws Exception
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.- 抛出:
Exception
- this method can handle or propagate exceptions; see class-level Javadoc for details.
supportsPartialMessages
boolean supportsPartialMessages()
Whether the WebSocketHandler handles partial messages. If this flag is set totrue
and the underlying WebSocket server supports partial messages, then a large WebSocket message, or one of an unknown size may be split and maybe received over multiple calls tohandleMessage(WebSocketSession, WebSocketMessage)
. The flagWebSocketMessage.isLast()
indicates if the message is partial and whether it is the last part.