org.springframework.web.socket.adapter

## Class AbstractWebSocketSession<T>

- java.lang.Object
- - org.springframework.web.socket.adapter.AbstractWebSocketSession<T>

- All Implemented Interfaces:
    NativeWebSocketSession, WebSocketSession
  Direct Known Subclasses:
    JettyWebSocketSession, StandardWebSocketSession

      public abstract class AbstractWebSocketSession<T>
      extends Object
      implements NativeWebSocketSession

  An abstract base class for implementations of `WebSocketSession`.
  Since:
    4.0
  Author:
    Rossen Stoyanchev

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected Log` | `logger`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractWebSocketSession(Map<String,Object> attributes)` Create a new instance and associate the given attributes with it.

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `checkNativeSessionInitialized()`
    `void` | `close()` Close the WebSocket connection with status 1000, i.e.
    `void` | `close(CloseStatus status)` Close the WebSocket connection with the given close status.
    `protected abstract void` | `closeInternal(CloseStatus status)`
    `Map<String,Object>` | `getAttributes()` Return the map with attributes associated with the WebSocket session.
    `T` | `getNativeSession()` Return the underlying native WebSocketSession, if available.
    `<R> R` | `getNativeSession(Class<R> requiredType)` Return the underlying native WebSocketSession, if available.
    `void` | `initializeNativeSession(T session)`
    `protected abstract void` | `sendBinaryMessage(BinaryMessage message)`
    `void` | `sendMessage(WebSocketMessage<?> message)` Send a WebSocket message either `TextMessage` or `BinaryMessage`.
    `protected abstract void` | `sendPingMessage(PingMessage message)`
    `protected abstract void` | `sendPongMessage(PongMessage message)`
    `protected abstract void` | `sendTextMessage(TextMessage message)`
    `String` | `toString()`

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

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

    - ### Methods inherited from interface org.springframework.web.socket.WebSocketSession

      `getAcceptedProtocol, getBinaryMessageSizeLimit, getExtensions, getHandshakeHeaders, getId, getLocalAddress, getPrincipal, getRemoteAddress, getTextMessageSizeLimit, getUri, isOpen, setBinaryMessageSizeLimit, setTextMessageSizeLimit`

- - ### Field Detail

    - #### logger

          protected final Log logger

  - ### Constructor Detail

    - #### AbstractWebSocketSession

          public AbstractWebSocketSession(Map<String,Object> attributes)

      Create a new instance and associate the given attributes with it.
      Parameters:
        `attributes` - attributes from the HTTP handshake to associate with the WebSocket session; the provided attributes are copied, the original map is not used.

  - ### Method Detail

    - #### getAttributes

          public Map<String,Object> getAttributes()

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

      When the WebSocketSession is created, on the server side, the map can be through a `HandshakeInterceptor`. On the client side, the map can be populated by passing attributes to the `WebSocketClient` handshake methods.

      Specified by:
        `getAttributes` in interface `WebSocketSession`

    - #### getNativeSession

          public T getNativeSession()

      Description copied from interface: `NativeWebSocketSession`
      Return the underlying native WebSocketSession, if available.
      Specified by:
        `getNativeSession` in interface `NativeWebSocketSession`
      Returns:
        the native session or `null`

    - #### getNativeSession

          public <R> R getNativeSession(Class<R> requiredType)

      Description copied from interface: `NativeWebSocketSession`
      Return the underlying native WebSocketSession, if available.
      Specified by:
        `getNativeSession` in interface `NativeWebSocketSession`
      Parameters:
        `requiredType` - the required type of the session
      Returns:
        the native session of the required type or `null`

    - #### initializeNativeSession

          public void initializeNativeSession(T session)

    - #### checkNativeSessionInitialized

          protected final void checkNativeSessionInitialized()

    - #### sendMessage

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

      Description copied from interface: `WebSocketSession`
      Send a WebSocket message either `TextMessage` or `BinaryMessage`.
      Specified by:
        `sendMessage` in interface `WebSocketSession`
      Throws:
        `IOException`

    - #### sendTextMessage

          protected abstract void sendTextMessage(TextMessage message)
                                           throws IOException

      Throws:
        `IOException`

    - #### sendBinaryMessage

          protected abstract void sendBinaryMessage(BinaryMessage message)
                                             throws IOException

      Throws:
        `IOException`

    - #### sendPingMessage

          protected abstract void sendPingMessage(PingMessage message)
                                           throws IOException

      Throws:
        `IOException`

    - #### sendPongMessage

          protected abstract void sendPongMessage(PongMessage message)
                                           throws IOException

      Throws:
        `IOException`

    - #### close

          public final 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 `WebSocketSession`
      Throws:
        `IOException`

    - #### close

          public final 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`

    - #### closeInternal

          protected abstract void closeInternal(CloseStatus status)
                                         throws IOException

      Throws:
        `IOException`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`