org.springframework.web.reactive.socket.server.support

## Class WebSocketHandlerAdapter

- java.lang.Object
- - org.springframework.web.reactive.socket.server.support.WebSocketHandlerAdapter

- All Implemented Interfaces:
    Ordered, HandlerAdapter

      public class WebSocketHandlerAdapter
      extends Object
      implements HandlerAdapter, Ordered

  `HandlerAdapter` that allows `DispatcherHandler` to support handlers of type `WebSocketHandler` with such handlers mapped to URL patterns via `SimpleUrlHandlerMapping`.

  Requests are handled by delegating to a `WebSocketService`, by default `HandshakeWebSocketService`, which checks the WebSocket handshake request parameters, upgrades to a WebSocket interaction, and uses the `WebSocketHandler` to handle it.

  As of 5.3 the WebFlux Java configuration, imported via `@EnableWebFlux`, includes a declaration of this adapter and therefore it no longer needs to be present in application configuration.

  Since:
    5.0
  Author:
    Rossen Stoyanchev

- - ### Field Summary

    - ### Fields inherited from interface org.springframework.core.Ordered

      `HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `WebSocketHandlerAdapter()` Default constructor that creates and uses a `HandshakeWebSocketService`.
    `WebSocketHandlerAdapter(WebSocketService webSocketService)` Alternative constructor with the `WebSocketService` to use.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `getOrder()` Return the `configured` order for this instance.
    `WebSocketService` | `getWebSocketService()` Return the configured `WebSocketService` to handle requests.
    `reactor.core.publisher.Mono<HandlerResult>` | `handle(ServerWebExchange exchange, Object handler)` Handle the request with the given handler.
    `void` | `setOrder(int order)` Set the order value for this adapter.
    `boolean` | `supports(Object handler)` Whether this `HandlerAdapter` supports the given `handler`.

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

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

- - ### Constructor Detail

    - #### WebSocketHandlerAdapter

          public WebSocketHandlerAdapter()

      Default constructor that creates and uses a `HandshakeWebSocketService`.

    - #### WebSocketHandlerAdapter

          public WebSocketHandlerAdapter(WebSocketService webSocketService)

      Alternative constructor with the `WebSocketService` to use.

  - ### Method Detail

    - #### setOrder

          public void setOrder(int order)

      Set the order value for this adapter.

      By default this is set to 2.

      Parameters:
        `order` - the value to set to
      Since:
        5.3

    - #### getOrder

          public int getOrder()

      Return the `configured` order for this instance.
      Specified by:
        `getOrder` in interface `Ordered`
      Returns:
        the order value
      Since:
        5.3
      See Also:
        `Ordered.HIGHEST_PRECEDENCE`, `Ordered.LOWEST_PRECEDENCE`

    - #### getWebSocketService

          public WebSocketService getWebSocketService()

      Return the configured `WebSocketService` to handle requests.

    - #### supports

          public boolean supports(Object handler)

      Description copied from interface: `HandlerAdapter`
      Whether this `HandlerAdapter` supports the given `handler`.
      Specified by:
        `supports` in interface `HandlerAdapter`
      Parameters:
        `handler` - the handler object to check
      Returns:
        whether the handler is supported

    - #### handle

          public reactor.core.publisher.Mono<HandlerResult> handle(ServerWebExchange exchange,
                                                                   Object handler)

      Description copied from interface: `HandlerAdapter`
      Handle the request with the given handler.

      Implementations are encouraged to handle exceptions resulting from the invocation of a handler in order and if necessary to return an alternate result that represents an error response.

      Furthermore since an async `HandlerResult` may produce an error later during result handling implementations are also encouraged to `set an exception handler` on the `HandlerResult` so that may also be applied later after result handling.

      Specified by:
        `handle` in interface `HandlerAdapter`
      Parameters:
        `exchange` - current server exchange
        `handler` - the selected handler which must have been previously checked via `HandlerAdapter.supports(Object)`
      Returns:
        `Mono` that emits a single `HandlerResult` or none if the request has been fully handled and doesn't require further handling.