Class WebSocketHandlerAdapter

java.lang.Object
org.springframework.web.reactive.socket.server.support.WebSocketHandlerAdapter
All Implemented Interfaces:
Ordered, HandlerAdapter

@ImportRuntimeHints(org.springframework.web.reactive.socket.server.support.HandshakeWebSocketServiceRuntimeHints.class) 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
  • Constructor Details

  • Method Details

    • 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:
    • 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, previously checked via HandlerAdapter.supports(Object).

      Implementations should consider the following for exception handling:

      • Handle invocation exceptions within this method.
      • Set an exception handler on the returned HandlerResult to handle deferred exceptions from asynchronous return values, and to handle exceptions from response rendering.
      • Implement DispatchExceptionHandler to extend exception handling to exceptions that occur before a handler is selected.
      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 HandlerResult, or completes empty if the request is fully handled; any error signal would not be handled within the DispatcherHandler, and would instead be processed by the chain of registered WebExceptionHandlers at the end of the WebFilter chain