org.springframework.web.socket.adapter

Class AbstractWebSocketSession<T>

  • java.lang.Object
    • org.springframework.web.socket.adapter.AbstractWebSocketSession<T>
    • Field Detail

      • idGenerator

        protected static final IdGenerator idGenerator
      • logger

        protected static final Log logger
    • Constructor Detail

      • AbstractWebSocketSession

        public AbstractWebSocketSession(@Nullable
                                        java.util.Map<java.lang.String,java.lang.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 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)
      • getNativeSession

        @Nullable
        public <R> R getNativeSession(@Nullable
                                                java.lang.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 if not available
      • initializeNativeSession

        public void initializeNativeSession(T session)
      • checkNativeSessionInitialized

        protected final void checkNativeSessionInitialized()
      • sendTextMessage

        protected abstract void sendTextMessage(TextMessage message)
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • sendBinaryMessage

        protected abstract void sendBinaryMessage(BinaryMessage message)
                                           throws java.io.IOException
        Throws:
        java.io.IOException
      • sendPingMessage

        protected abstract void sendPingMessage(PingMessage message)
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • sendPongMessage

        protected abstract void sendPongMessage(PongMessage message)
                                         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 abstract void closeInternal(CloseStatus status)
                                       throws java.io.IOException
        Throws:
        java.io.IOException
      • toString

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