Top Description Fields Constructors Methods
org.springframework.web.reactive.socket.server.support

public Class WebSocketHandlerAdapter

extends Object
implements HandlerAdapter, Ordered
Class Inheritance
All Implemented Interfaces
org.springframework.core.Ordered, org.springframework.web.reactive.HandlerAdapter
Annotations
@ImportRuntimeHints:HandshakeWebSocketServiceRuntimeHints
Imports
reactor.core.publisher.Mono, org.springframework.context.annotation.ImportRuntimeHints, org.springframework.core.Ordered, org.springframework.util.Assert, org.springframework.web.reactive.HandlerAdapter, .HandlerResult, org.springframework.web.reactive.socket.WebSocketHandler, org.springframework.web.reactive.socket.server.WebSocketService, org.springframework.web.server.ServerWebExchange

HandlerAdapter that allows org.springframework.web.reactive.DispatcherHandler to support handlers of type WebSocketHandler with such handlers mapped to URL patterns via org.springframework.web.reactive.handler.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.

Author
Rossen Stoyanchev
Since
5.0

Field Summary

Modifier and TypeField and Description
private int
private final WebSocketService

Constructor Summary

AccessConstructor and Description
public
WebSocketHandlerAdapter()

Default constructor that creates and uses a HandshakeWebSocketService.

public
WebSocketHandlerAdapter(WebSocketService webSocketService)

Alternative constructor with the WebSocketService to use.

Method Summary

Modifier and TypeMethod and Description
public int
getOrder()

Implements org.springframework.core.Ordered.getOrder.

Return the configured order for this instance.

public WebSocketService
getWebSocketService()

Return the configured WebSocketService to handle requests.

public Mono<HandlerResult>
handle(ServerWebExchange
current server exchange
exchange
,
Object
the selected handler which must have been previously checked via supports(Object)
handler
)

Implements org.springframework.web.reactive.HandlerAdapter.handle.

Handle the request with the given handler, previously checked via supports(Object).

public void
setOrder(int
the value to set to
order
)

Set the order value for this adapter.

public boolean
supports(Object
the handler object to check
handler
)

Implements org.springframework.web.reactive.HandlerAdapter.supports.

Whether this HandlerAdapter supports the given handler.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

orderback to summary
private int order
webSocketServiceback to summary
private final WebSocketService webSocketService

Constructor Detail

WebSocketHandlerAdapterback to summary
public WebSocketHandlerAdapter()

Default constructor that creates and uses a HandshakeWebSocketService.

WebSocketHandlerAdapterback to summary
public WebSocketHandlerAdapter(WebSocketService webSocketService)

Alternative constructor with the WebSocketService to use.

Method Detail

getOrderback to summary
public int getOrder()

Implements org.springframework.core.Ordered.getOrder.

Return the configured order for this instance.

Returns:int

Doc from org.springframework.core.Ordered.getOrder.

the order value

Annotations
@Override
Since
5.3
getWebSocketServiceback to summary
public WebSocketService getWebSocketService()

Return the configured WebSocketService to handle requests.

handleback to summary
public Mono<HandlerResult> handle(ServerWebExchange exchange, Object handler)

Implements org.springframework.web.reactive.HandlerAdapter.handle.

Doc from org.springframework.web.reactive.HandlerAdapter.handle.

Handle the request with the given handler, previously checked via 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.
Parameters
exchange:ServerWebExchange

current server exchange

handler:Object

the selected handler which must have been previously checked via supports(Object)

Returns:Mono<HandlerResult>

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 org.springframework.web.server.WebExceptionHandlers at the end of the org.springframework.web.server.WebFilter chain

Annotations
@Override
setOrderback to summary
public void setOrder(int order)

Set the order value for this adapter.

By default this is set to 2.

Parameters
order:int

the value to set to

Since
5.3
supportsback to summary
public boolean supports(Object handler)

Implements org.springframework.web.reactive.HandlerAdapter.supports.

Doc from org.springframework.web.reactive.HandlerAdapter.supports.

Whether this HandlerAdapter supports the given handler.

Parameters
handler:Object

the handler object to check

Returns:boolean

whether the handler is supported

Annotations
@Override