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
-
Field Summary
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor that creates and uses aHandshakeWebSocketService.WebSocketHandlerAdapter(WebSocketService webSocketService) Alternative constructor with theWebSocketServiceto use. -
Method Summary
Modifier and TypeMethodDescriptionintgetOrder()Return theconfiguredorder for this instance.Return the configuredWebSocketServiceto handle requests.reactor.core.publisher.Mono<HandlerResult>handle(ServerWebExchange exchange, Object handler) Handle the request with the given handler, previously checked viaHandlerAdapter.supports(Object).voidsetOrder(int order) Set the order value for this adapter.booleanWhether thisHandlerAdaptersupports the givenhandler.
-
Constructor Details
-
WebSocketHandlerAdapter
public WebSocketHandlerAdapter()Default constructor that creates and uses aHandshakeWebSocketService. -
WebSocketHandlerAdapter
Alternative constructor with theWebSocketServiceto use.
-
-
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 theconfiguredorder for this instance. -
getWebSocketService
Return the configuredWebSocketServiceto handle requests. -
supports
Description copied from interface:HandlerAdapterWhether thisHandlerAdaptersupports the givenhandler.- Specified by:
supportsin interfaceHandlerAdapter- 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:HandlerAdapterHandle the request with the given handler, previously checked viaHandlerAdapter.supports(Object).Implementations should consider the following for exception handling:
- Handle invocation exceptions within this method.
Set an exception handleron the returnedHandlerResultto handle deferred exceptions from asynchronous return values, and to handle exceptions from response rendering.- Implement
DispatchExceptionHandlerto extend exception handling to exceptions that occur before a handler is selected.
- Specified by:
handlein interfaceHandlerAdapter- Parameters:
exchange- current server exchangehandler- the selected handler which must have been previously checked viaHandlerAdapter.supports(Object)- Returns:
Monothat emits aHandlerResult, or completes empty if the request is fully handled; any error signal would not be handled within theDispatcherHandler, and would instead be processed by the chain of registeredWebExceptionHandlers at the end of theWebFilterchain
-