org.springframework.web.socket.messaging

## 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

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static 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 Summary

    Constructors
    Constructor and Description
    `StompSubProtocolHandler()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    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.
    `int` | `getMessageSizeLimit()` Get the configured message buffer size limit in bytes.
    `List<String>` | `getSupportedProtocols()` Return the list of sub-protocols supported by this handler, never `null`.
    `UserSessionRegistry` | `getUserSessionRegistry()`
    `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.
    `String` | `resolveSessionId(Message<?> message)` Resolve the session id from the given message or return `null`.
    `protected void` | `sendErrorMessage(WebSocketSession session, Throwable error)`
    `void` | `setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher)` Set the ApplicationEventPublisher that this object runs in.
    `void` | `setMessageSizeLimit(int messageSizeLimit)` Configure the maximum size allowed for an incoming STOMP message.
    `void` | `setUserSessionRegistry(UserSessionRegistry registry)` Provide a registry with which to register active user session ids.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### 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.
      See Also:
        Constant Field Values

    - #### 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.
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### StompSubProtocolHandler

          public StompSubProtocolHandler()

  - ### Method Detail

    - #### 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

    - #### setUserSessionRegistry

          public void setUserSessionRegistry(UserSessionRegistry registry)

      Provide a registry with which to register active user session ids.
      See Also:
        `UserDestinationMessageHandler`

    - #### getUserSessionRegistry

          public UserSessionRegistry getUserSessionRegistry()

      Returns:
        the configured UserSessionRegistry.

    - #### getSupportedProtocols

          public List<String> getSupportedProtocols()

      Description copied from interface: `SubProtocolHandler`
      Return the list of sub-protocols supported by this handler, never `null`.
      Specified by:
        `getSupportedProtocols` in interface `SubProtocolHandler`

    - #### setApplicationEventPublisher

          public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher)

      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 interface `ApplicationEventPublisherAware`
      Parameters:
        `applicationEventPublisher` - event publisher to be used by this object

    - #### handleMessageFromClient

          public void handleMessageFromClient(WebSocketSession session,
                                              WebSocketMessage<?> webSocketMessage,
                                              MessageChannel outputChannel)

      Handle incoming WebSocket messages from clients.
      Specified by:
        `handleMessageFromClient` in interface `SubProtocolHandler`
      Parameters:
        `session` - the client session
        `webSocketMessage` - the client message
        `outputChannel` - an output channel to send messages to

    - #### sendErrorMessage

          protected void sendErrorMessage(WebSocketSession session,
                                          Throwable error)

    - #### handleMessageToClient

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

      Handle STOMP messages going back out to WebSocket clients.
      Specified by:
        `handleMessageToClient` in interface `SubProtocolHandler`
      Parameters:
        `session` - the client session
        `message` - the client message

    - #### resolveSessionId

          public String resolveSessionId(Message<?> message)

      Description copied from interface: `SubProtocolHandler`
      Resolve the session id from the given message or return `null`.
      Specified by:
        `resolveSessionId` in interface `SubProtocolHandler`
      Parameters:
        `message` - the message to resolve the session id from

    - #### afterSessionStarted

          public void afterSessionStarted(WebSocketSession session,
                                          MessageChannel outputChannel)

      Description copied from interface: `SubProtocolHandler`
      Invoked after a `WebSocketSession` has started.
      Specified by:
        `afterSessionStarted` in interface `SubProtocolHandler`
      Parameters:
        `session` - the client session
        `outputChannel` - a channel

    - #### afterSessionEnded

          public void afterSessionEnded(WebSocketSession session,
                                        CloseStatus closeStatus,
                                        MessageChannel outputChannel)

      Description copied from interface: `SubProtocolHandler`
      Invoked after a `WebSocketSession` has ended.
      Specified by:
        `afterSessionEnded` in interface `SubProtocolHandler`
      Parameters:
        `session` - the client session
        `closeStatus` - the reason why the session was closed
        `outputChannel` - a channel