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:
Closeable, AutoCloseable, NativewebSocketSession, webSocketSession

public class JettywebSocketSession extends AbstractwebSocketSession<org.eclipse.jetty.websocket.api.Session>
A webSocketSession for use with the Jetty webSocket API.
Since:
4.0
Author:
Phillip webb, Rossen Stoyanchev, Brian Clozel, Juergen Hoeller
  • Constructor Details

    • JettywebSocketSession

      public JettywebSocketSession(Map<String,Object> attributes)
      Create a new JettywebSocketSession instance.
      Parameters:
      attributes - the attributes from the HTTP handshake to associate with the webSocket session
    • JettywebSocketSession

      public JettywebSocketSession(Map<String,Object> attributes, @Nullable Principal user)
      Create a new JettywebSocketSession instance associated with the given user.
      Parameters:
      attributes - the 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 fall back on the user available via Session.getUpgradeRequest()
  • Method Details

    • getId

      public String getId()
      Description copied from interface: webSocketSession
      Return a unique session identifier.
    • getUri

      public @Nullable 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 (never null).
    • getAcceptedProtocol

      public @Nullable String getAcceptedProtocol()
      Description copied from interface: webSocketSession
      Return the negotiated sub-protocol.
      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.
      Returns:
      the list of extensions, or an empty list if no extension was specified or negotiated successfully
    • getPrincipal

      public @Nullable 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.

      Note: The localAddress is not always possible to access, which is the case with the Standard webSocket client API, and accordingly StandardwebSocketClient returns null.

    • getRemoteAddress

      public InetSocketAddress getRemoteAddress()
      Description copied from interface: webSocketSession
      Return the address of the remote client.
    • 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.
    • isOpen

      public boolean isOpen()
      Description copied from interface: webSocketSession
      Whether the underlying connection is open.
    • initializeNativeSession

      public void initializeNativeSession(org.eclipse.jetty.websocket.api.Session session)
      Overrides:
      initializeNativeSession in class AbstractwebSocketSession<org.eclipse.jetty.websocket.api.Session>
    • 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