public class SubProtocolWebSocketHandler extends Object implements org.springframework.web.socket.WebSocketHandler, MessageHandler
WebSocketHandler
that delegates messages to a SubProtocolHandler
based on the sub-protocol value requested by the client through the
Sec-WebSocket-Protocol
request header A default handler can also be configured
to use if the client does not request a specific sub-protocol.Constructor and Description |
---|
SubProtocolWebSocketHandler(MessageChannel outputChannel) |
Modifier and Type | Method and Description |
---|---|
void |
addProtocolHandler(SubProtocolHandler handler)
Register a sub-protocol handler.
|
void |
afterConnectionClosed(org.springframework.web.socket.WebSocketSession session,
org.springframework.web.socket.CloseStatus closeStatus) |
void |
afterConnectionEstablished(org.springframework.web.socket.WebSocketSession session) |
protected SubProtocolHandler |
findProtocolHandler(org.springframework.web.socket.WebSocketSession session) |
SubProtocolHandler |
getDefaultProtocolHandler() |
Map<String,SubProtocolHandler> |
getProtocolHandlers() |
Set<String> |
getSupportedProtocols()
Return all supported protocols.
|
void |
handleMessage(Message<?> message)
Handles the message if possible.
|
void |
handleMessage(org.springframework.web.socket.WebSocketSession session,
org.springframework.web.socket.WebSocketMessage<?> message) |
void |
handleTransportError(org.springframework.web.socket.WebSocketSession session,
Throwable exception) |
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.
|
boolean |
supportsPartialMessages() |
public SubProtocolWebSocketHandler(MessageChannel outputChannel)
outputChannel
- public void setProtocolHandlers(List<SubProtocolHandler> protocolHandlers)
protocolHandlers
- the sub-protocol handlers to usepublic void addProtocolHandler(SubProtocolHandler handler)
public Map<String,SubProtocolHandler> getProtocolHandlers()
public void setDefaultProtocolHandler(SubProtocolHandler defaultProtocolHandler)
SubProtocolHandler
to use when the client did not request a
sub-protocol.defaultProtocolHandler
- the default handlerpublic SubProtocolHandler getDefaultProtocolHandler()
public void afterConnectionEstablished(org.springframework.web.socket.WebSocketSession session) throws Exception
afterConnectionEstablished
in interface org.springframework.web.socket.WebSocketHandler
Exception
protected final SubProtocolHandler findProtocolHandler(org.springframework.web.socket.WebSocketSession session)
public void handleMessage(org.springframework.web.socket.WebSocketSession session, org.springframework.web.socket.WebSocketMessage<?> message) throws Exception
handleMessage
in interface org.springframework.web.socket.WebSocketHandler
Exception
public void handleMessage(Message<?> message) throws MessagingException
MessageHandler
MessageRejectedException
e.g.
in case of a Selective Consumer. When a consumer tries to handle a
message, but fails to do so, a MessageHandlingException
is
thrown. In the last case it is recommended to treat the message as tainted
and go into an error scenario.
When the handling results in a failure of another message being sent
(e.g. a "reply" message), that failure will trigger a
MessageDeliveryException
.
handleMessage
in interface MessageHandler
message
- the message to be handled
reply related to the handling of the messageMessagingException
public void handleTransportError(org.springframework.web.socket.WebSocketSession session, Throwable exception) throws Exception
handleTransportError
in interface org.springframework.web.socket.WebSocketHandler
Exception
public void afterConnectionClosed(org.springframework.web.socket.WebSocketSession session, org.springframework.web.socket.CloseStatus closeStatus) throws Exception
afterConnectionClosed
in interface org.springframework.web.socket.WebSocketHandler
Exception
public boolean supportsPartialMessages()
supportsPartialMessages
in interface org.springframework.web.socket.WebSocketHandler