org.springframework.web.socket.server.support

## Class HttpSessionHandshakeInterceptor

- java.lang.Object
- - org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor

- All Implemented Interfaces:
    HandshakeInterceptor

      public class HttpSessionHandshakeInterceptor
      extends Object
      implements HandshakeInterceptor

  An interceptor to copy HTTP session attributes into the map of "handshake attributes" made available through `WebSocketSession.getAttributes()`.
  Since:
    4.0
  Author:
    Rossen Stoyanchev

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `HttpSessionHandshakeInterceptor()` A constructor for copying all available HTTP session attributes.
    `HttpSessionHandshakeInterceptor(Collection<String> attributeNames)` A constructor for copying a subset of HTTP session attributes.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `afterHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Exception ex)` Invoked after the handshake is done.
    `boolean` | `beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String,Object> attributes)` Invoked before the handshake is processed.

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

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

- - ### Constructor Detail

    - #### HttpSessionHandshakeInterceptor

          public HttpSessionHandshakeInterceptor()

      A constructor for copying all available HTTP session attributes.

    - #### HttpSessionHandshakeInterceptor

          public HttpSessionHandshakeInterceptor(Collection<String> attributeNames)

      A constructor for copying a subset of HTTP session attributes.
      Parameters:
        `attributeNames` - the HTTP session attributes to copy

  - ### Method Detail

    - #### beforeHandshake

          public boolean beforeHandshake(ServerHttpRequest request,
                                         ServerHttpResponse response,
                                         WebSocketHandler wsHandler,
                                         Map<String,Object> attributes)
                                  throws Exception

      Description copied from interface: `HandshakeInterceptor`
      Invoked before the handshake is processed.
      Specified by:
        `beforeHandshake` in interface `HandshakeInterceptor`
      Parameters:
        `request` - the current request
        `response` - the current response
        `wsHandler` - the target WebSocket handler
        `attributes` - attributes from the HTTP handshake to associate with the WebSocket session; the provided attributes are copied, the original map is not used.
      Returns:
        whether to proceed with the handshake `true` or abort `false`
      Throws:
        `Exception`

    - #### afterHandshake

          public void afterHandshake(ServerHttpRequest request,
                                     ServerHttpResponse response,
                                     WebSocketHandler wsHandler,
                                     Exception ex)

      Description copied from interface: `HandshakeInterceptor`
      Invoked after the handshake is done. The response status and headers indicate the results of the handshake, i.e. whether it was successful or not.
      Specified by:
        `afterHandshake` in interface `HandshakeInterceptor`
      Parameters:
        `request` - the current request
        `response` - the current response
        `wsHandler` - the target WebSocket handler
        `ex` - an exception raised during the handshake, or `null`