org.springframework.web.socket.handler

## Class WebSocketSessionDecorator

- java.lang.Object
- - org.springframework.web.socket.handler.WebSocketSessionDecorator

- All Implemented Interfaces:
    Closeable, AutoCloseable, WebSocketSession
  Direct Known Subclasses:
    ConcurrentWebSocketSessionDecorator

      public class WebSocketSessionDecorator
      extends Object
      implements WebSocketSession

  Wraps another `WebSocketSession` instance and delegates to it.

  Also provides a `getDelegate()` method to return the decorated session as well as a `getLastSession()` method to go through all nested delegates and return the "last" session.

  Since:
    4.0.3
  Author:
    Rossen Stoyanchev

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `WebSocketSessionDecorator(WebSocketSession session)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()` Close the WebSocket connection with status 1000, i.e.
    `void` | `close(CloseStatus status)` Close the WebSocket connection with the given close status.
    `String` | `getAcceptedProtocol()` Return the negotiated sub-protocol.
    `Map<String,Object>` | `getAttributes()` Return the map with attributes associated with the WebSocket session.
    `int` | `getBinaryMessageSizeLimit()` Get the configured maximum size for an incoming binary message.
    `WebSocketSession` | `getDelegate()`
    `List<WebSocketExtension>` | `getExtensions()` Determine the negotiated extensions.
    `HttpHeaders` | `getHandshakeHeaders()` Return the headers used in the handshake request (never `null`).
    `String` | `getId()` Return a unique session identifier.
    `WebSocketSession` | `getLastSession()`
    `InetSocketAddress` | `getLocalAddress()` Return the address on which the request was received.
    `Principal` | `getPrincipal()` Return a `Principal` instance containing the name of the authenticated user.
    `InetSocketAddress` | `getRemoteAddress()` Return the address of the remote client.
    `int` | `getTextMessageSizeLimit()` Get the configured maximum size for an incoming text message.
    `URI` | `getUri()` Return the URI used to open the WebSocket connection.
    `boolean` | `isOpen()` Whether the underlying connection is open.
    `void` | `sendMessage(WebSocketMessage<?> message)` Send a WebSocket message: either `TextMessage` or `BinaryMessage`.
    `void` | `setBinaryMessageSizeLimit(int messageSizeLimit)` Configure the maximum size for an incoming binary message.
    `void` | `setTextMessageSizeLimit(int messageSizeLimit)` Configure the maximum size for an incoming text message.
    `String` | `toString()`
    `static WebSocketSession` | `unwrap(WebSocketSession session)`

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

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

- - ### Constructor Detail

    - #### WebSocketSessionDecorator

          public WebSocketSessionDecorator(WebSocketSession session)

  - ### Method Detail

    - #### getDelegate

          public WebSocketSession getDelegate()

    - #### getLastSession

          public WebSocketSession getLastSession()

    - #### unwrap

          public static WebSocketSession unwrap(WebSocketSession session)

    - #### getId

          public String getId()

      Description copied from interface: `WebSocketSession`
      Return a unique session identifier.
      Specified by:
        `getId` in interface `WebSocketSession`

    - #### getUri

          @Nullable
          public URI getUri()

      Description copied from interface: `WebSocketSession`
      Return the URI used to open the WebSocket connection.
      Specified by:
        `getUri` in interface `WebSocketSession`

    - #### getHandshakeHeaders

          public HttpHeaders getHandshakeHeaders()

      Description copied from interface: `WebSocketSession`
      Return the headers used in the handshake request (never `null`).
      Specified by:
        `getHandshakeHeaders` in interface `WebSocketSession`

    - #### getAttributes

          public Map<String,Object> getAttributes()

      Description copied from interface: `WebSocketSession`
      Return the map with attributes associated with the WebSocket session.

      On the server side the map can be populated initially through a `HandshakeInterceptor`. On the client side the map can be populated via `WebSocketClient` handshake methods.

      Specified by:
        `getAttributes` in interface `WebSocketSession`
      Returns:
        a Map with the session attributes (never `null`)

    - #### getPrincipal

          public Principal getPrincipal()

      Description copied from interface: `WebSocketSession`
      Return a `Principal` instance containing the name of the authenticated user.

      If the user has not been authenticated, the method returns `null`.

      Specified by:
        `getPrincipal` in interface `WebSocketSession`

    - #### getLocalAddress

          public InetSocketAddress getLocalAddress()

      Description copied from interface: `WebSocketSession`
      Return the address on which the request was received.
      Specified by:
        `getLocalAddress` in interface `WebSocketSession`

    - #### getRemoteAddress

          public InetSocketAddress getRemoteAddress()

      Description copied from interface: `WebSocketSession`
      Return the address of the remote client.
      Specified by:
        `getRemoteAddress` in interface `WebSocketSession`

    - #### getAcceptedProtocol

          public String getAcceptedProtocol()

      Description copied from interface: `WebSocketSession`
      Return the negotiated sub-protocol.
      Specified by:
        `getAcceptedProtocol` in interface `WebSocketSession`
      Returns:
        the protocol identifier, or `null` if no protocol was specified or negotiated successfully

    - #### getExtensions

          public List<WebSocketExtension> getExtensions()

      Description copied from interface: `WebSocketSession`
      Determine the negotiated extensions.
      Specified by:
        `getExtensions` in interface `WebSocketSession`
      Returns:
        the list of extensions, or an empty list if no extension was specified or negotiated successfully

    - #### setTextMessageSizeLimit

          public void setTextMessageSizeLimit(int messageSizeLimit)

      Description copied from interface: `WebSocketSession`
      Configure the maximum size for an incoming text message.
      Specified by:
        `setTextMessageSizeLimit` in interface `WebSocketSession`

    - #### getTextMessageSizeLimit

          public int getTextMessageSizeLimit()

      Description copied from interface: `WebSocketSession`
      Get the configured maximum size for an incoming text message.
      Specified by:
        `getTextMessageSizeLimit` in interface `WebSocketSession`

    - #### setBinaryMessageSizeLimit

          public void setBinaryMessageSizeLimit(int messageSizeLimit)

      Description copied from interface: `WebSocketSession`
      Configure the maximum size for an incoming binary message.
      Specified by:
        `setBinaryMessageSizeLimit` in interface `WebSocketSession`

    - #### getBinaryMessageSizeLimit

          public int getBinaryMessageSizeLimit()

      Description copied from interface: `WebSocketSession`
      Get the configured maximum size for an incoming binary message.
      Specified by:
        `getBinaryMessageSizeLimit` in interface `WebSocketSession`

    - #### isOpen

          public boolean isOpen()

      Description copied from interface: `WebSocketSession`
      Whether the underlying connection is open.
      Specified by:
        `isOpen` in interface `WebSocketSession`

    - #### sendMessage

          public void sendMessage(WebSocketMessage<?> message)
                           throws IOException

      Description copied from interface: `WebSocketSession`
      Send a WebSocket message: either `TextMessage` or `BinaryMessage`.

      Note: The underlying standard WebSocket session (JSR-356) does not allow concurrent sending. Therefore, sending must be synchronized. To ensure that, one option is to wrap the `WebSocketSession` with the `ConcurrentWebSocketSessionDecorator`.

      Specified by:
        `sendMessage` in interface `WebSocketSession`
      Throws:
        `IOException`
      See Also:
        `ConcurrentWebSocketSessionDecorator`

    - #### close

          public void close()
                     throws IOException

      Description copied from interface: `WebSocketSession`
      Close the WebSocket connection with status 1000, i.e. equivalent to:

           session.close(CloseStatus.NORMAL);

      Specified by:
        `close` in interface `Closeable`
      Specified by:
        `close` in interface `AutoCloseable`
      Specified by:
        `close` in interface `WebSocketSession`
      Throws:
        `IOException`

    - #### close

          public void close(CloseStatus status)
                     throws IOException

      Description copied from interface: `WebSocketSession`
      Close the WebSocket connection with the given close status.
      Specified by:
        `close` in interface `WebSocketSession`
      Throws:
        `IOException`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`