org.springframework.web.socket.messaging

## Interface SubProtocolHandler

All Known Implementing Classes:
  StompSubProtocolHandler

    public interface SubProtocolHandler

A contract for handling WebSocket messages as part of a higher level protocol, referred to as "sub-protocol" in the WebSocket RFC specification. Handles both `WebSocketMessages` from a client as well as `Messages` to a client.

Implementations of this interface can be configured on a `SubProtocolWebSocketHandler` which selects a sub-protocol handler to delegate messages to based on the sub-protocol requested by the client through the `Sec-WebSocket-Protocol` request header.

Since:
  4.0
Author:
  Andy Wilkinson, Rossen Stoyanchev

### Method Summary

All Methods Instance Methods Abstract Methods
`void` `afterSessionEnded(WebSocketSession session, CloseStatus closeStatus, org.springframework.messaging.MessageChannel outputChannel)` Invoked after a `WebSocketSession` has ended.
`void` `afterSessionStarted(WebSocketSession session, org.springframework.messaging.MessageChannel outputChannel)` Invoked after a `WebSocketSession` has started.
`List<String>` `getSupportedProtocols()` Return the list of sub-protocols supported by this handler (never `null`).
`void` `handleMessageFromClient(WebSocketSession session, WebSocketMessage<?> message, org.springframework.messaging.MessageChannel outputChannel)` Handle the given `WebSocketMessage` received from a client.
`void` `handleMessageToClient(WebSocketSession session, org.springframework.messaging.Message<?> message)` Handle the given `Message` to the client associated with the given WebSocket session.
`String` `resolveSessionId(org.springframework.messaging.Message<?> message)` Resolve the session id from the given message or return `null`.

### Method Detail

#### getSupportedProtocols

    List<String> getSupportedProtocols()

Return the list of sub-protocols supported by this handler (never `null`).

#### handleMessageFromClient

    void handleMessageFromClient(WebSocketSession session,
                                 WebSocketMessage<?> message,
                                 org.springframework.messaging.MessageChannel outputChannel)
                          throws Exception

Handle the given `WebSocketMessage` received from a client.

Parameters:
  `session` - the client session
  `message` - the client message
  `outputChannel` - an output channel to send messages to
Throws:
  `Exception`

#### handleMessageToClient

    void handleMessageToClient(WebSocketSession session,
                               org.springframework.messaging.Message<?> message)
                        throws Exception

Handle the given `Message` to the client associated with the given WebSocket session.

Parameters:
  `session` - the client session
  `message` - the client message
Throws:
  `Exception`

#### resolveSessionId

    @Nullable
    String resolveSessionId(org.springframework.messaging.Message<?> message)

Resolve the session id from the given message or return `null`.

Parameters:
  `message` - the message to resolve the session id from

#### afterSessionStarted

    void afterSessionStarted(WebSocketSession session,
                             org.springframework.messaging.MessageChannel outputChannel)
                      throws Exception

Invoked after a `WebSocketSession` has started.

Parameters:
  `session` - the client session
  `outputChannel` - a channel
Throws:
  `Exception`

#### afterSessionEnded

    void afterSessionEnded(WebSocketSession session,
                           CloseStatus closeStatus,
                           org.springframework.messaging.MessageChannel outputChannel)
                    throws Exception

Invoked after a `WebSocketSession` has ended.

Parameters:
  `session` - the client session
  `closeStatus` - the reason why the session was closed
  `outputChannel` - a channel
Throws:
  `Exception`