类 StompSubProtocolHandler
- java.lang.Object
- org.springframework.web.socket.messaging.StompSubProtocolHandler
public class StompSubProtocolHandler extends Object implements SubProtocolHandler, ApplicationEventPublisherAware
ASubProtocolHandlerfor STOMP that supports versions 1.0, 1.1, and 1.2 of the STOMP specification.- 从以下版本开始:
- 4.0
- 作者:
- Rossen Stoyanchev, Andy Wilkinson
字段概要
字段 修饰符和类型 字段 说明 static StringCONNECTED_USER_HEADERThe name of the header set on the CONNECTED frame indicating the name of the user authenticated on the WebSocket session.static intMINIMUM_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.
构造器概要
构造器 构造器 说明 StompSubProtocolHandler()
方法概要
所有方法 实例方法 具体方法 已过时的方法 修饰符和类型 方法 说明 voidafterSessionEnded(WebSocketSession session, CloseStatus closeStatus, MessageChannel outputChannel)Invoked after aWebSocketSessionhas ended.voidafterSessionStarted(WebSocketSession session, MessageChannel outputChannel)Invoked after aWebSocketSessionhas started.StompSubProtocolErrorHandlergetErrorHandler()Return the configured error handler.MessageHeaderInitializergetHeaderInitializer()Return the configured header initializer.intgetMessageSizeLimit()Get the configured message buffer size limit in bytes.StringgetStatsInfo()Return a String describing internal state and counters.List<String>getSupportedProtocols()Return the list of sub-protocols supported by this handler (nevernull).UserSessionRegistrygetUserSessionRegistry()已过时。as of 4.2voidhandleMessageFromClient(WebSocketSession session, WebSocketMessage<?> webSocketMessage, MessageChannel outputChannel)Handle incoming WebSocket messages from clients.voidhandleMessageToClient(WebSocketSession session, Message<?> message)Handle STOMP messages going back out to WebSocket clients.StringresolveSessionId(Message<?> message)Resolve the session id from the given message or returnnull.protected voidsendErrorMessage(WebSocketSession session, Throwable error)已过时。as of Spring 4.2, in favor ofconfiguringaStompSubProtocolErrorHandlervoidsetApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher)Set the ApplicationEventPublisher that this object runs in.voidsetDecoder(StompDecoder decoder)Configure aStompDecoderfor decoding STOMP framesvoidsetEncoder(StompEncoder encoder)Configure aStompEncoderfor encoding STOMP framesvoidsetErrorHandler(StompSubProtocolErrorHandler errorHandler)Configure a handler for error messages sent to clients which allows customizing the error messages or preventing them from being sent.voidsetHeaderInitializer(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.voidsetUserSessionRegistry(UserSessionRegistry registry)已过时。as of 4.2 in favor ofDefaultSimpUserRegistrywhich relies on the ApplicationContext events published by this class and is created viaWebSocketMessageBrokerConfigurationSupport.createLocalUserRegistryprotected StompHeaderAccessortoMutableAccessor(StompHeaderAccessor headerAccessor, Message<?> message)StringtoString()
字段详细资料
MINIMUM_WEBSOCKET_MESSAGE_SIZE
public static final 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. Therefore the WebSocket server input message buffer size must allow 16K at least plus a little extra for SockJS framing.- 另请参阅:
- 常量字段值
CONNECTED_USER_HEADER
public static final 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.- 另请参阅:
- 常量字段值
构造器详细资料
StompSubProtocolHandler
public StompSubProtocolHandler()
方法详细资料
setErrorHandler
public 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.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
getErrorHandler
public StompSubProtocolErrorHandler 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.
- 从以下版本开始:
- 4.0.3
getMessageSizeLimit
public int getMessageSizeLimit()
Get the configured message buffer size limit in bytes.- 从以下版本开始:
- 4.0.3
setUserSessionRegistry
@Deprecated public void setUserSessionRegistry(UserSessionRegistry registry)
已过时。as of 4.2 in favor ofDefaultSimpUserRegistrywhich relies on the ApplicationContext events published by this class and is created viaWebSocketMessageBrokerConfigurationSupport.createLocalUserRegistryProvide a registry with which to register active user session ids.
getUserSessionRegistry
@Deprecated public UserSessionRegistry getUserSessionRegistry()
已过时。as of 4.2
setEncoder
public void setEncoder(StompEncoder encoder)
Configure aStompEncoderfor encoding STOMP frames- 从以下版本开始:
- 4.3.5
setDecoder
public void setDecoder(StompDecoder decoder)
Configure aStompDecoderfor decoding STOMP frames- 从以下版本开始:
- 4.3.5
setHeaderInitializer
public void setHeaderInitializer(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.By default this property is not set.
getHeaderInitializer
public MessageHeaderInitializer getHeaderInitializer()
Return the configured header initializer.
getSupportedProtocols
public List<String> getSupportedProtocols()
从接口复制的说明:SubProtocolHandlerReturn the list of sub-protocols supported by this handler (nevernull).- 指定者:
getSupportedProtocols在接口中SubProtocolHandler
setApplicationEventPublisher
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher)
从接口复制的说明: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.
- 指定者:
setApplicationEventPublisher在接口中ApplicationEventPublisherAware- 参数:
applicationEventPublisher- event publisher to be used by this object
getStatsInfo
public String getStatsInfo()
Return a String describing internal state and counters.
handleMessageFromClient
public void handleMessageFromClient(WebSocketSession session, WebSocketMessage<?> webSocketMessage, MessageChannel outputChannel)
Handle incoming WebSocket messages from clients.- 指定者:
handleMessageFromClient在接口中SubProtocolHandler- 参数:
session- the client sessionwebSocketMessage- the client messageoutputChannel- an output channel to send messages to
sendErrorMessage
@Deprecated protected void sendErrorMessage(WebSocketSession session, Throwable error)
已过时。as of Spring 4.2, in favor ofconfiguringaStompSubProtocolErrorHandlerInvoked when noerrorHandleris configured to send an ERROR frame to the client.
handleMessageToClient
public void handleMessageToClient(WebSocketSession session, Message<?> message)
Handle STOMP messages going back out to WebSocket clients.- 指定者:
handleMessageToClient在接口中SubProtocolHandler- 参数:
session- the client sessionmessage- the client message
toMutableAccessor
protected StompHeaderAccessor toMutableAccessor(StompHeaderAccessor headerAccessor, Message<?> message)
resolveSessionId
public String resolveSessionId(Message<?> message)
从接口复制的说明:SubProtocolHandlerResolve the session id from the given message or returnnull.- 指定者:
resolveSessionId在接口中SubProtocolHandler- 参数:
message- the message to resolve the session id from
afterSessionStarted
public void afterSessionStarted(WebSocketSession session, MessageChannel outputChannel)
从接口复制的说明:SubProtocolHandlerInvoked after aWebSocketSessionhas started.- 指定者:
afterSessionStarted在接口中SubProtocolHandler- 参数:
session- the client sessionoutputChannel- a channel
afterSessionEnded
public void afterSessionEnded(WebSocketSession session, CloseStatus closeStatus, MessageChannel outputChannel)
从接口复制的说明:SubProtocolHandlerInvoked after aWebSocketSessionhas ended.- 指定者:
afterSessionEnded在接口中SubProtocolHandler- 参数:
session- the client sessioncloseStatus- the reason why the session was closedoutputChannel- a channel