public class SubProtocolWebSocketHandler extends Object implements WebSocketHandler, SubProtocolCapable, org.springframework.messaging.MessageHandler, org.springframework.context.SmartLifecycle
WebSocketHandler that delegates incoming WebSocket
messages to a SubProtocolHandler along with a MessageChannel to which
the sub-protocol handler can send messages from WebSocket clients to the application.
Also an implementation of MessageHandler that finds the WebSocket session
associated with the Message and passes it, along with the message, to the
sub-protocol handler to send messages from the application back to the client.
| Constructor and Description |
|---|
SubProtocolWebSocketHandler(org.springframework.messaging.MessageChannel clientInboundChannel,
org.springframework.messaging.SubscribableChannel clientOutboundChannel)
Create a new
SubProtocolWebSocketHandler for the given inbound and outbound channels. |
| Modifier and Type | Method and Description |
|---|---|
void |
addProtocolHandler(SubProtocolHandler handler)
Register a sub-protocol handler.
|
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.
|
protected SubProtocolHandler |
findProtocolHandler(WebSocketSession session) |
SubProtocolHandler |
getDefaultProtocolHandler()
Return the default sub-protocol handler to use.
|
int |
getPhase() |
Map<String,SubProtocolHandler> |
getProtocolHandlerMap()
Return the sub-protocols keyed by protocol name.
|
List<SubProtocolHandler> |
getProtocolHandlers() |
int |
getSendBufferSizeLimit()
Return the buffer-size limit (number of bytes).
|
int |
getSendTimeLimit()
Return the send-time limit (milliseconds).
|
String |
getStatsInfo()
Return a String describing internal state and counters.
|
List<String> |
getSubProtocols()
Return all supported protocols.
|
void |
handleMessage(org.springframework.messaging.Message<?> message)
Handle an outbound Spring Message to a WebSocket client.
|
void |
handleMessage(WebSocketSession session,
WebSocketMessage<?> message)
Handle an inbound message from a WebSocket client.
|
void |
handleTransportError(WebSocketSession session,
Throwable exception)
Handle an error from the underlying WebSocket message transport.
|
boolean |
isAutoStartup() |
boolean |
isRunning() |
void |
setDefaultProtocolHandler(SubProtocolHandler defaultProtocolHandler)
Set the
SubProtocolHandler to use when the client did not request a
sub-protocol. |
void |
setProtocolHandlers(List<SubProtocolHandler> protocolHandlers)
Configure one or more handlers to use depending on the sub-protocol requested by
the client in the WebSocket handshake request.
|
void |
setSendBufferSizeLimit(int sendBufferSizeLimit)
Specify the buffer-size limit (number of bytes).
|
void |
setSendTimeLimit(int sendTimeLimit)
Specify the send-time limit (milliseconds).
|
void |
start() |
void |
stop() |
void |
stop(Runnable callback) |
boolean |
supportsPartialMessages()
Whether the WebSocketHandler handles partial messages.
|
String |
toString() |
public SubProtocolWebSocketHandler(org.springframework.messaging.MessageChannel clientInboundChannel,
org.springframework.messaging.SubscribableChannel clientOutboundChannel)
SubProtocolWebSocketHandler for the given inbound and outbound channels.clientInboundChannel - the inbound MessageChannelclientOutboundChannel - the outbound MessageChannelpublic void setProtocolHandlers(List<SubProtocolHandler> protocolHandlers)
protocolHandlers - the sub-protocol handlers to usepublic List<SubProtocolHandler> getProtocolHandlers()
public void addProtocolHandler(SubProtocolHandler handler)
public Map<String,SubProtocolHandler> getProtocolHandlerMap()
public void setDefaultProtocolHandler(SubProtocolHandler defaultProtocolHandler)
SubProtocolHandler to use when the client did not request a
sub-protocol.defaultProtocolHandler - the default handlerpublic SubProtocolHandler getDefaultProtocolHandler()
public List<String> getSubProtocols()
getSubProtocols in interface SubProtocolCapablepublic void setSendTimeLimit(int sendTimeLimit)
ConcurrentWebSocketSessionDecoratorpublic int getSendTimeLimit()
public void setSendBufferSizeLimit(int sendBufferSizeLimit)
ConcurrentWebSocketSessionDecoratorpublic int getSendBufferSizeLimit()
public String getStatsInfo()
public boolean isAutoStartup()
isAutoStartup in interface org.springframework.context.SmartLifecyclepublic int getPhase()
getPhase in interface org.springframework.context.Phasedpublic final boolean isRunning()
isRunning in interface org.springframework.context.Lifecyclepublic final void start()
start in interface org.springframework.context.Lifecyclepublic final void stop()
stop in interface org.springframework.context.Lifecyclepublic final void stop(Runnable callback)
stop in interface org.springframework.context.SmartLifecyclepublic void afterConnectionEstablished(WebSocketSession session) throws Exception
WebSocketHandlerafterConnectionEstablished in interface WebSocketHandlerException - this method can handle or propagate exceptions; see class-level
Javadoc for details.public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception
handleMessage in interface WebSocketHandlerException - this method can handle or propagate exceptions; see class-level
Javadoc for details.public void handleMessage(org.springframework.messaging.Message<?> message)
throws org.springframework.messaging.MessagingException
handleMessage in interface org.springframework.messaging.MessageHandlerorg.springframework.messaging.MessagingExceptionpublic void handleTransportError(WebSocketSession session, Throwable exception) throws Exception
WebSocketHandlerhandleTransportError in interface WebSocketHandlerException - this method can handle or propagate exceptions; see class-level
Javadoc for details.public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws Exception
WebSocketHandlerafterConnectionClosed in interface WebSocketHandlerException - this method can handle or propagate exceptions; see class-level
Javadoc for details.public boolean supportsPartialMessages()
WebSocketHandlertrue 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 to
WebSocketHandler.handleMessage(WebSocketSession, WebSocketMessage). The flag
WebSocketMessage.isLast() indicates if
the message is partial and whether it is the last part.supportsPartialMessages in interface WebSocketHandlerprotected final SubProtocolHandler findProtocolHandler(WebSocketSession session)