public class StompSubProtocolHandler extends java.lang.Object implements SubProtocolHandler, ApplicationEventPublisherAware
SubProtocolHandler
for STOMP that supports versions 1.0, 1.1, and 1.2
of the STOMP specification.Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CONNECTED_USER_HEADER
The name of the header set on the CONNECTED frame indicating the name
of the user authenticated on the WebSocket session.
|
static int |
MINIMUM_WEBSOCKET_MESSAGE_SIZE
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 and Description |
---|
StompSubProtocolHandler() |
Modifier and Type | Method and Description |
---|---|
void |
afterSessionEnded(WebSocketSession session,
CloseStatus closeStatus,
MessageChannel outputChannel)
Invoked after a
WebSocketSession has ended. |
void |
afterSessionStarted(WebSocketSession session,
MessageChannel outputChannel)
Invoked after a
WebSocketSession has started. |
StompSubProtocolErrorHandler |
getErrorHandler()
Return the configured error handler.
|
MessageHeaderInitializer |
getHeaderInitializer()
Return the configured header initializer.
|
int |
getMessageSizeLimit()
Get the configured message buffer size limit in bytes.
|
java.lang.String |
getStatsInfo()
Return a String describing internal state and counters.
|
java.util.List<java.lang.String> |
getSupportedProtocols()
Return the list of sub-protocols supported by this handler (never
null ). |
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.
|
java.lang.String |
resolveSessionId(Message<?> message)
Resolve the session id from the given message or return
null . |
void |
setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher)
Set the ApplicationEventPublisher that this object runs in.
|
void |
setDecoder(StompDecoder decoder)
Configure a
StompDecoder for decoding STOMP frames |
void |
setEncoder(StompEncoder encoder)
Configure a
StompEncoder 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 a
MessageHeaderInitializer 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) |
java.lang.String |
toString() |
public static final int MINIMUM_WEBSOCKET_MESSAGE_SIZE
public static final java.lang.String CONNECTED_USER_HEADER
public void setErrorHandler(StompSubProtocolErrorHandler errorHandler)
By default this isn't configured in which case an ERROR frame is sent with a message header reflecting the error.
errorHandler
- the error handler@Nullable public StompSubProtocolErrorHandler getErrorHandler()
public void setMessageSizeLimit(int messageSizeLimit)
By default this property is set to 64K.
public int getMessageSizeLimit()
public void setEncoder(StompEncoder encoder)
StompEncoder
for encoding STOMP framespublic void setDecoder(StompDecoder decoder)
StompDecoder
for decoding STOMP framespublic void setHeaderInitializer(@Nullable MessageHeaderInitializer headerInitializer)
MessageHeaderInitializer
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.
@Nullable public MessageHeaderInitializer getHeaderInitializer()
public java.util.List<java.lang.String> getSupportedProtocols()
SubProtocolHandler
null
).getSupportedProtocols
in interface SubProtocolHandler
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher)
ApplicationEventPublisherAware
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.
setApplicationEventPublisher
in interface ApplicationEventPublisherAware
applicationEventPublisher
- event publisher to be used by this objectpublic java.lang.String getStatsInfo()
public void handleMessageFromClient(WebSocketSession session, WebSocketMessage<?> webSocketMessage, MessageChannel outputChannel)
handleMessageFromClient
in interface SubProtocolHandler
session
- the client sessionwebSocketMessage
- the client messageoutputChannel
- an output channel to send messages topublic void handleMessageToClient(WebSocketSession session, Message<?> message)
handleMessageToClient
in interface SubProtocolHandler
session
- the client sessionmessage
- the client messageprotected StompHeaderAccessor toMutableAccessor(StompHeaderAccessor headerAccessor, Message<?> message)
@Nullable public java.lang.String resolveSessionId(Message<?> message)
SubProtocolHandler
null
.resolveSessionId
in interface SubProtocolHandler
message
- the message to resolve the session id frompublic void afterSessionStarted(WebSocketSession session, MessageChannel outputChannel)
SubProtocolHandler
WebSocketSession
has started.afterSessionStarted
in interface SubProtocolHandler
session
- the client sessionoutputChannel
- a channelpublic void afterSessionEnded(WebSocketSession session, CloseStatus closeStatus, MessageChannel outputChannel)
SubProtocolHandler
WebSocketSession
has ended.afterSessionEnded
in interface SubProtocolHandler
session
- the client sessioncloseStatus
- the reason why the session was closedoutputChannel
- a channelpublic java.lang.String toString()
toString
in class java.lang.Object