org.springframework.web.socket.sockjs.client

Class AbstractClientSockJsSession

  • java.lang.Object
    • org.springframework.web.socket.sockjs.client.AbstractClientSockJsSession
  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, WebSocketSession
    Direct Known Subclasses:
    WebSocketClientSockJsSession, XhrClientSockJsSession


    public abstract class AbstractClientSockJsSession
    extends java.lang.Object
    implements WebSocketSession
    Base class for SockJS client implementations of WebSocketSession. Provides processing of incoming SockJS message frames and delegates lifecycle events and messages to the (application) WebSocketHandler. Sub-classes implement actual send as well as disconnect logic.
    Since:
    4.1
    Author:
    Rossen Stoyanchev, Juergen Hoeller
    • Field Detail

      • logger

        protected final Log logger
    • Method Detail

      • getUri

        public java.net.URI getUri()
        Description copied from interface: WebSocketSession
        Return the URI used to open the WebSocket connection.
        Specified by:
        getUri in interface WebSocketSession
      • getAttributes

        public java.util.Map<java.lang.String,java.lang.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 java.security.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
      • isDisconnected

        public boolean isDisconnected()
      • sendInternal

        protected abstract void sendInternal(TextMessage textMessage)
                                      throws java.io.IOException
        Throws:
        java.io.IOException
      • close

        public final void close()
                         throws java.io.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 java.io.Closeable
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface WebSocketSession
        Throws:
        java.io.IOException
      • close

        public final void close(CloseStatus status)
                         throws java.io.IOException
        Description copied from interface: WebSocketSession
        Close the WebSocket connection with the given close status.
        Specified by:
        close in interface WebSocketSession
        Throws:
        java.io.IOException
      • closeInternal

        protected void closeInternal(CloseStatus status)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • disconnect

        protected abstract void disconnect(CloseStatus status)
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • handleFrame

        public void handleFrame(java.lang.String payload)
      • handleTransportError

        public void handleTransportError(java.lang.Throwable error)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object