Class StompSubProtocolHandler
- All Implemented Interfaces:
- Aware, ApplicationEventPublisherAware, SubProtocolHandler
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 SummaryNested ClassesModifier and TypeClassDescriptionstatic interfaceContract for access to session counters.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final StringThe name of the header set on the CONNECTED frame indicating the name of the user authenticated on the WebSocket session.static final intThis 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 SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidafterSessionEnded(WebSocketSession session, CloseStatus closeStatus, MessageChannel outputChannel) Invoked after aWebSocketSessionhas ended.voidafterSessionStarted(WebSocketSession session, MessageChannel outputChannel) Invoked after aWebSocketSessionhas started.Return the configured error handler.Return the configured header initializer.intGet 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).voidhandleMessageFromClient(WebSocketSession session, WebSocketMessage<?> webSocketMessage, MessageChannel channel) Handle incoming WebSocket messages from clients.voidhandleMessageToClient(WebSocketSession session, Message<?> message) Handle STOMP messages going back out to WebSocket clients.booleanWhether the handler is configured to handle inbound messages in the order in which they were received.resolveSessionId(Message<?> message) Resolve the session id from the given message or returnnull.voidsetApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) Set the ApplicationEventPublisher that this object runs in.voidsetDecoder(StompDecoder decoder) Configure aStompDecoderfor decoding STOMP frames.voidsetEncoder(StompEncoder encoder) Configure aStompEncoderfor encoding STOMP frames.voidsetErrorHandler(StompSubProtocolErrorHandler errorHandler) Configure a handler for error messages sent to clients which allows customizing the error messages or preventing them from being sent.voidsetHeaderInitializer(@Nullable MessageHeaderInitializer headerInitializer) Configure aMessageHeaderInitializerto apply to the headers of all messages created from decoded STOMP frames and other messages sent to the client inbound channel.voidsetMessageSizeLimit(int messageSizeLimit) Configure the maximum size allowed for an incoming STOMP message.voidsetPreserveReceiveOrder(boolean preserveReceiveOrder) Whether client messages must be handled in the order received.protected StompHeaderAccessortoMutableAccessor(StompHeaderAccessor headerAccessor, Message<?> message) toString()
- 
Field Details- 
MINIMUM_WEBSOCKET_MESSAGE_SIZEpublic 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_HEADERThe name of the header set on the CONNECTED frame indicating the name of the user authenticated on the WebSocket session.- See Also:
 
 
- 
- 
Constructor Details- 
StompSubProtocolHandlerpublic StompSubProtocolHandler()
 
- 
- 
Method Details- 
setErrorHandlerConfigure 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
 
- 
getErrorHandlerReturn the configured error handler.
- 
setMessageSizeLimitpublic 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
 
- 
getMessageSizeLimitpublic int getMessageSizeLimit()Get the configured message buffer size limit in bytes.- Since:
- 4.0.3
 
- 
setEncoderConfigure aStompEncoderfor encoding STOMP frames.- Since:
- 4.3.5
 
- 
setDecoderConfigure aStompDecoderfor decoding STOMP frames.- Since:
- 4.3.5
 
- 
setHeaderInitializerConfigure aMessageHeaderInitializerto 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. 
- 
getHeaderInitializerReturn the configured header initializer.
- 
setPreserveReceiveOrderpublic void setPreserveReceiveOrder(boolean preserveReceiveOrder) Whether client messages must be handled in the order received.By default messages sent to the "clientInboundChannel"may not be handled in the same order because the channel is backed by a ThreadPoolExecutor that in turn does not guarantee processing in order.When this flag is set to truemessages within the same session will be sent to the"clientInboundChannel"one at a time to preserve the order in which they were received.- Parameters:
- preserveReceiveOrder- whether to publish in order
- Since:
- 6.1
 
- 
isPreserveReceiveOrderpublic boolean isPreserveReceiveOrder()Whether the handler is configured to handle inbound messages in the order in which they were received.- Since:
- 6.1
 
- 
getSupportedProtocolsDescription copied from interface:SubProtocolHandlerReturn the list of sub-protocols supported by this handler (nevernull).- Specified by:
- getSupportedProtocolsin interface- SubProtocolHandler
 
- 
setApplicationEventPublisherDescription copied from interface:ApplicationEventPublisherAwareSet 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:
- setApplicationEventPublisherin interface- ApplicationEventPublisherAware
- Parameters:
- applicationEventPublisher- event publisher to be used by this object
 
- 
getStatsInfoReturn a String describing internal state and counters. EffectivelytoString()ongetStats().
- 
getStatsReturn a structured object with internal state and counters.- Since:
- 5.2
 
- 
handleMessageFromClientpublic void handleMessageFromClient(WebSocketSession session, WebSocketMessage<?> webSocketMessage, MessageChannel channel) Handle incoming WebSocket messages from clients.- Specified by:
- handleMessageFromClientin interface- SubProtocolHandler
- Parameters:
- session- the client session
- webSocketMessage- the client message
- channel- an output channel to send messages to
 
- 
handleMessageToClientHandle STOMP messages going back out to WebSocket clients.- Specified by:
- handleMessageToClientin interface- SubProtocolHandler
- Parameters:
- session- the client session
- message- the client message
 
- 
toMutableAccessorprotected StompHeaderAccessor toMutableAccessor(StompHeaderAccessor headerAccessor, Message<?> message) 
- 
resolveSessionIdDescription copied from interface:SubProtocolHandlerResolve the session id from the given message or returnnull.- Specified by:
- resolveSessionIdin interface- SubProtocolHandler
- Parameters:
- message- the message to resolve the session id from
 
- 
afterSessionStartedDescription copied from interface:SubProtocolHandlerInvoked after aWebSocketSessionhas started.- Specified by:
- afterSessionStartedin interface- SubProtocolHandler
- Parameters:
- session- the client session
- outputChannel- a channel
 
- 
afterSessionEndedpublic void afterSessionEnded(WebSocketSession session, CloseStatus closeStatus, MessageChannel outputChannel) Description copied from interface:SubProtocolHandlerInvoked after aWebSocketSessionhas ended.- Specified by:
- afterSessionEndedin interface- SubProtocolHandler
- Parameters:
- session- the client session
- closeStatus- the reason why the session was closed
- outputChannel- a channel
 
- 
toString
 
-