Top Description Methods
org.springframework.web.socket.messaging

public Interface SubProtocolHandler

Known Direct Implementers
org.springframework.web.socket.messaging.StompSubProtocolHandler
Imports
java.util.List, org.springframework.lang.Nullable, org.springframework.messaging.Message, .MessageChannel, org.springframework.web.socket.CloseStatus, .WebSocketMessage, .WebSocketSession

A contract for handling WebSocket messages as part of a higher level protocol, referred to as "sub-protocol" in the WebSocket RFC specification. Handles both WebSocketMessages from a client as well as Messages to a client.

Implementations of this interface can be configured on a SubProtocolWebSocketHandler which selects a sub-protocol handler to delegate messages to based on the sub-protocol requested by the client through the Sec-WebSocket-Protocol request header.

Authors
Andy Wilkinson, Rossen Stoyanchev
Since
4.0

Method Summary

Modifier and TypeMethod and Description
public void
afterSessionEnded(WebSocketSession
the client session
session
,
CloseStatus
the reason why the session was closed
closeStatus
,
MessageChannel
a channel
outputChannel
)

Invoked after a WebSocketSession has ended.

public void
afterSessionStarted(WebSocketSession
the client session
session
,
MessageChannel
a channel
outputChannel
)

Invoked after a WebSocketSession has started.

public List<String>
getSupportedProtocols()

Return the list of sub-protocols supported by this handler (never null).

public void
handleMessageFromClient(WebSocketSession
the client session
session
,
WebSocketMessage<?>
the client message
message
,
MessageChannel
an output channel to send messages to
outputChannel
)

Handle the given WebSocketMessage received from a client.

public void
handleMessageToClient(WebSocketSession
the client session
session
,
Message<?>
the client message
message
)

Handle the given Message to the client associated with the given WebSocket session.

public String
resolveSessionId(Message<?>
the message to resolve the session id from
message
)

Resolve the session id from the given message or return null.

Method Detail

afterSessionEndedback to summary
public void afterSessionEnded(WebSocketSession session, CloseStatus closeStatus, MessageChannel outputChannel) throws Exception

Invoked after a WebSocketSession has ended.

Parameters
session:WebSocketSession

the client session

closeStatus:CloseStatus

the reason why the session was closed

outputChannel:MessageChannel

a channel

afterSessionStartedback to summary
public void afterSessionStarted(WebSocketSession session, MessageChannel outputChannel) throws Exception

Invoked after a WebSocketSession has started.

Parameters
session:WebSocketSession

the client session

outputChannel:MessageChannel

a channel

getSupportedProtocolsback to summary
public List<String> getSupportedProtocols()

Return the list of sub-protocols supported by this handler (never null).

handleMessageFromClientback to summary
public void handleMessageFromClient(WebSocketSession session, WebSocketMessage<?> message, MessageChannel outputChannel) throws Exception

Handle the given WebSocketMessage received from a client.

Parameters
session:WebSocketSession

the client session

message:WebSocketMessage<?>

the client message

outputChannel:MessageChannel

an output channel to send messages to

handleMessageToClientback to summary
public void handleMessageToClient(WebSocketSession session, Message<?> message) throws Exception

Handle the given Message to the client associated with the given WebSocket session.

Parameters
session:WebSocketSession

the client session

message:Message<?>

the client message

resolveSessionIdback to summary
public String resolveSessionId(Message<?> message)

Resolve the session id from the given message or return null.

Parameters
message:Message<?>

the message to resolve the session id from

Annotations
@Nullable