Class StompSubProtocolHandler
java.lang.Object
org.springframework.web.socket.messaging.StompSubProtocolHandler
- All Implemented Interfaces:
Aware
,ApplicationEventPublisherAware
,SubProtocolHandler
public class StompSubProtocolHandler
extends Object
implements SubProtocolHandler, ApplicationEventPublisherAware
A
SubProtocolHandler
for STOMP that supports versions 1.0, 1.1, and 1.2
of the STOMP specification.- Since:
- 4.0
- Author:
- Rossen Stoyanchev, Andy Wilkinson
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Contract for access to session counters. -
Field Summary
Modifier and TypeFieldDescriptionstatic final String
The name of the header set on the CONNECTED frame indicating the name of the user authenticated on the WebSocket session.static final int
This handler supports assembling large STOMP messages split into multiple WebSocket messages and STOMP clients (like stomp.js) indeed split large STOMP messages at 16K boundaries. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
afterSessionEnded
(WebSocketSession session, CloseStatus closeStatus, MessageChannel outputChannel) Invoked after aWebSocketSession
has ended.void
afterSessionStarted
(WebSocketSession session, MessageChannel outputChannel) Invoked after aWebSocketSession
has started.Return the configured error handler.Return the configured header initializer.int
Get the configured message buffer size limit in bytes.getStats()
Return a structured object with internal state and counters.Return a String describing internal state and counters.Return the list of sub-protocols supported by this handler (nevernull
).void
handleMessageFromClient
(WebSocketSession session, WebSocketMessage<?> webSocketMessage, MessageChannel outputChannel) Handle incoming WebSocket messages from clients.void
handleMessageToClient
(WebSocketSession session, Message<?> message) Handle STOMP messages going back out to WebSocket clients.resolveSessionId
(Message<?> message) Resolve the session id from the given message or returnnull
.void
setApplicationEventPublisher
(ApplicationEventPublisher applicationEventPublisher) Set the ApplicationEventPublisher that this object runs in.void
setDecoder
(StompDecoder decoder) Configure aStompDecoder
for decoding STOMP frames.void
setEncoder
(StompEncoder encoder) Configure aStompEncoder
for encoding STOMP frames.void
setErrorHandler
(StompSubProtocolErrorHandler errorHandler) Configure a handler for error messages sent to clients which allows customizing the error messages or preventing them from being sent.void
setHeaderInitializer
(MessageHeaderInitializer headerInitializer) Configure aMessageHeaderInitializer
to apply to the headers of all messages created from decoded STOMP frames and other messages sent to the client inbound channel.void
setMessageSizeLimit
(int messageSizeLimit) Configure the maximum size allowed for an incoming STOMP message.protected StompHeaderAccessor
toMutableAccessor
(StompHeaderAccessor headerAccessor, Message<?> message) toString()
-
Field Details
-
MINIMUM_WEBSOCKET_MESSAGE_SIZE
public static final int MINIMUM_WEBSOCKET_MESSAGE_SIZEThis handler supports assembling large STOMP messages split into multiple WebSocket messages and STOMP clients (like stomp.js) indeed split large STOMP messages at 16K boundaries. Therefore the WebSocket server input message buffer size must allow 16K at least plus a little extra for SockJS framing.- See Also:
-
CONNECTED_USER_HEADER
The name of the header set on the CONNECTED frame indicating the name of the user authenticated on the WebSocket session.- See Also:
-
-
Constructor Details
-
StompSubProtocolHandler
public StompSubProtocolHandler()
-
-
Method Details
-
setErrorHandler
Configure a handler for error messages sent to clients which allows customizing the error messages or preventing them from being sent.By default this isn't configured in which case an ERROR frame is sent with a message header reflecting the error.
- Parameters:
errorHandler
- the error handler
-
getErrorHandler
Return the configured error handler. -
setMessageSizeLimit
public void setMessageSizeLimit(int messageSizeLimit) Configure the maximum size allowed for an incoming STOMP message. Since a STOMP message can be received in multiple WebSocket messages, buffering may be required and therefore it is necessary to know the maximum allowed message size.By default this property is set to 64K.
- Since:
- 4.0.3
-
getMessageSizeLimit
public int getMessageSizeLimit()Get the configured message buffer size limit in bytes.- Since:
- 4.0.3
-
setEncoder
Configure aStompEncoder
for encoding STOMP frames.- Since:
- 4.3.5
-
setDecoder
Configure aStompDecoder
for decoding STOMP frames.- Since:
- 4.3.5
-
setHeaderInitializer
Configure aMessageHeaderInitializer
to apply to the headers of all messages created from decoded STOMP frames and other messages sent to the client inbound channel.By default this property is not set.
-
getHeaderInitializer
Return the configured header initializer. -
getSupportedProtocols
Description copied from interface:SubProtocolHandler
Return the list of sub-protocols supported by this handler (nevernull
).- Specified by:
getSupportedProtocols
in interfaceSubProtocolHandler
-
setApplicationEventPublisher
Description copied from interface:ApplicationEventPublisherAware
Set the ApplicationEventPublisher that this object runs in.Invoked after population of normal bean properties but before an init callback like InitializingBean's afterPropertiesSet or a custom init-method. Invoked before ApplicationContextAware's setApplicationContext.
- Specified by:
setApplicationEventPublisher
in interfaceApplicationEventPublisherAware
- Parameters:
applicationEventPublisher
- event publisher to be used by this object
-
getStatsInfo
Return a String describing internal state and counters. EffectivelytoString()
ongetStats()
. -
getStats
Return a structured object with internal state and counters.- Since:
- 5.2
-
handleMessageFromClient
public void handleMessageFromClient(WebSocketSession session, WebSocketMessage<?> webSocketMessage, MessageChannel outputChannel) Handle incoming WebSocket messages from clients.- Specified by:
handleMessageFromClient
in interfaceSubProtocolHandler
- Parameters:
session
- the client sessionwebSocketMessage
- the client messageoutputChannel
- an output channel to send messages to
-
handleMessageToClient
Handle STOMP messages going back out to WebSocket clients.- Specified by:
handleMessageToClient
in interfaceSubProtocolHandler
- Parameters:
session
- the client sessionmessage
- the client message
-
toMutableAccessor
protected StompHeaderAccessor toMutableAccessor(StompHeaderAccessor headerAccessor, Message<?> message) -
resolveSessionId
Description copied from interface:SubProtocolHandler
Resolve the session id from the given message or returnnull
.- Specified by:
resolveSessionId
in interfaceSubProtocolHandler
- Parameters:
message
- the message to resolve the session id from
-
afterSessionStarted
Description copied from interface:SubProtocolHandler
Invoked after aWebSocketSession
has started.- Specified by:
afterSessionStarted
in interfaceSubProtocolHandler
- Parameters:
session
- the client sessionoutputChannel
- a channel
-
afterSessionEnded
public void afterSessionEnded(WebSocketSession session, CloseStatus closeStatus, MessageChannel outputChannel) Description copied from interface:SubProtocolHandler
Invoked after aWebSocketSession
has ended.- Specified by:
afterSessionEnded
in interfaceSubProtocolHandler
- Parameters:
session
- the client sessioncloseStatus
- the reason why the session was closedoutputChannel
- a channel
-
toString
-