org.springframework.web.socket.adapter.jetty

## Class JettyWebSocketSession

- java.lang.Object
- - org.springframework.web.socket.adapter.AbstractWebSocketSession<org.eclipse.jetty.websocket.api.Session>
  - - org.springframework.web.socket.adapter.jetty.JettyWebSocketSession

- All Implemented Interfaces:
    NativeWebSocketSession, WebSocketSession

      public class JettyWebSocketSession
      extends AbstractWebSocketSession<org.eclipse.jetty.websocket.api.Session>

  A `WebSocketSession` for use with the Jetty 9 WebSocket API.
  Since:
    4.0
  Author:
    Phillip Webb, Rossen Stoyanchev

- - ### Field Summary

    - ### Fields inherited from class org.springframework.web.socket.adapter.AbstractWebSocketSession

      `logger`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `JettyWebSocketSession(Map<String,Object> attributes)` Create a new `JettyWebSocketSession` instance.
    `JettyWebSocketSession(Map<String,Object> attributes, Principal user)` Create a new `JettyWebSocketSession` instance associated with the given user.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `closeInternal(CloseStatus status)`
    `String` | `getAcceptedProtocol()` Return the negotiated sub-protocol or `null` if none was specified or negotiated successfully.
    `int` | `getBinaryMessageSizeLimit()` Get the configured maximum size for an incoming binary message.
    `List<WebSocketExtension>` | `getExtensions()` Return the negotiated extensions or `null` if none was specified or negotiated successfully.
    `HttpHeaders` | `getHandshakeHeaders()` Return the headers used in the handshake request.
    `String` | `getId()` Return a unique session identifier.
    `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()` Return whether the connection is still open.
    `protected void` | `sendBinaryMessage(BinaryMessage message)`
    `protected void` | `sendPingMessage(PingMessage message)`
    `protected void` | `sendPongMessage(PongMessage message)`
    `protected void` | `sendTextMessage(TextMessage message)`
    `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.

    - ### Methods inherited from class org.springframework.web.socket.adapter.AbstractWebSocketSession

      `checkNativeSessionInitialized, close, close, getAttributes, getNativeSession, getNativeSession, initializeNativeSession, sendMessage, toString`

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

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

- - ### Constructor Detail

    - #### JettyWebSocketSession

          public JettyWebSocketSession(Map<String,Object> attributes)

      Create a new `JettyWebSocketSession` instance.
      Parameters:
        `attributes` - attributes from the HTTP handshake to associate with the WebSocket session

    - #### JettyWebSocketSession

          public JettyWebSocketSession(Map<String,Object> attributes,
                                       Principal user)

      Create a new `JettyWebSocketSession` instance associated with the given user.
      Parameters:
        `attributes` - attributes from the HTTP handshake to associate with the WebSocket session; the provided attributes are copied, the original map is not used.
        `user` - the user associated with the session; if `null` we'll fallback on the user available via `Session.getUpgradeRequest()`

  - ### Method Detail

    - #### getId

          public String getId()

      Description copied from interface: `WebSocketSession`
      Return a unique session identifier.

    - #### getUri

          public URI getUri()

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

    - #### getHandshakeHeaders

          public HttpHeaders getHandshakeHeaders()

      Description copied from interface: `WebSocketSession`
      Return the headers used in the handshake request.

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

    - #### getLocalAddress

          public InetSocketAddress getLocalAddress()

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

    - #### getRemoteAddress

          public InetSocketAddress getRemoteAddress()

      Description copied from interface: `WebSocketSession`
      Return the address of the remote client.

    - #### getAcceptedProtocol

          public String getAcceptedProtocol()

      Description copied from interface: `WebSocketSession`
      Return the negotiated sub-protocol or `null` if none 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.

    - #### getTextMessageSizeLimit

          public int getTextMessageSizeLimit()

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

    - #### setBinaryMessageSizeLimit

          public void setBinaryMessageSizeLimit(int messageSizeLimit)

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

    - #### getBinaryMessageSizeLimit

          public int getBinaryMessageSizeLimit()

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

    - #### getExtensions

          public List<WebSocketExtension> getExtensions()

      Description copied from interface: `WebSocketSession`
      Return the negotiated extensions or `null` if none was specified or negotiated successfully.

    - #### isOpen

          public boolean isOpen()

      Description copied from interface: `WebSocketSession`
      Return whether the connection is still open.

    - #### sendTextMessage

          protected void sendTextMessage(TextMessage message)
                                  throws IOException

      Specified by:
        `sendTextMessage` in class `AbstractWebSocketSession<org.eclipse.jetty.websocket.api.Session>`
      Throws:
        `IOException`

    - #### sendBinaryMessage

          protected void sendBinaryMessage(BinaryMessage message)
                                    throws IOException

      Specified by:
        `sendBinaryMessage` in class `AbstractWebSocketSession<org.eclipse.jetty.websocket.api.Session>`
      Throws:
        `IOException`

    - #### sendPingMessage

          protected void sendPingMessage(PingMessage message)
                                  throws IOException

      Specified by:
        `sendPingMessage` in class `AbstractWebSocketSession<org.eclipse.jetty.websocket.api.Session>`
      Throws:
        `IOException`

    - #### sendPongMessage

          protected void sendPongMessage(PongMessage message)
                                  throws IOException

      Specified by:
        `sendPongMessage` in class `AbstractWebSocketSession<org.eclipse.jetty.websocket.api.Session>`
      Throws:
        `IOException`

    - #### closeInternal

          protected void closeInternal(CloseStatus status)
                                throws IOException

      Specified by:
        `closeInternal` in class `AbstractWebSocketSession<org.eclipse.jetty.websocket.api.Session>`
      Throws:
        `IOException`