Class HandshakeWebSocketService
- All Implemented Interfaces:
Lifecycle
,WebSocketService
WebSocketService
implementation that handles a WebSocket HTTP
handshake request by delegating to a RequestUpgradeStrategy
which
is either auto-detected (no-arg constructor) from the classpath but can
also be explicitly configured.- Since:
- 5.0
- Author:
- Rossen Stoyanchev
-
Field Summary
-
Constructor Summary
ConstructorDescriptionDefault constructor automatic, classpath detection based discovery of theRequestUpgradeStrategy
to use.HandshakeWebSocketService
(RequestUpgradeStrategy upgradeStrategy) Alternative constructor with theRequestUpgradeStrategy
to use. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
doStart()
protected void
doStop()
Return the configured predicate for initialization WebSocket session attributes fromWebSession
attributes.Return theRequestUpgradeStrategy
for WebSocket requests.reactor.core.publisher.Mono<Void>
handleRequest
(ServerWebExchange exchange, WebSocketHandler handler) Handle the request with the givenWebSocketHandler
.boolean
Check whether this component is currently running.void
setSessionAttributePredicate
(Predicate<String> predicate) Configure a predicate to use to extractWebSession
attributes and use them to initialize the WebSocket session with.void
start()
Start this component.void
stop()
Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method.
-
Field Details
-
logger
-
-
Constructor Details
-
HandshakeWebSocketService
public HandshakeWebSocketService()Default constructor automatic, classpath detection based discovery of theRequestUpgradeStrategy
to use. -
HandshakeWebSocketService
Alternative constructor with theRequestUpgradeStrategy
to use.- Parameters:
upgradeStrategy
- the strategy to use
-
-
Method Details
-
getUpgradeStrategy
Return theRequestUpgradeStrategy
for WebSocket requests. -
setSessionAttributePredicate
Configure a predicate to use to extractWebSession
attributes and use them to initialize the WebSocket session with.By default this is not set in which case no attributes are passed.
- Parameters:
predicate
- the predicate- Since:
- 5.1
-
getSessionAttributePredicate
Return the configured predicate for initialization WebSocket session attributes fromWebSession
attributes.- Since:
- 5.1
-
start
public void start()Description copied from interface:Lifecycle
Start this component.Should not throw an exception if the component is already running.
In the case of a container, this will propagate the start signal to all components that apply.
-
doStart
protected void doStart() -
stop
public void stop()Description copied from interface:Lifecycle
Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method. Consider implementingSmartLifecycle
and itsstop(Runnable)
variant when asynchronous stop behavior is necessary.Note that this stop notification is not guaranteed to come before destruction: On regular shutdown,
Lifecycle
beans will first receive a stop notification before the general destruction callbacks are being propagated; however, on hot refresh during a context's lifetime or on aborted refresh attempts, a given bean's destroy method will be called without any consideration of stop signals upfront.Should not throw an exception if the component is not running (not started yet).
In the case of a container, this will propagate the stop signal to all components that apply.
-
doStop
protected void doStop() -
isRunning
public boolean isRunning()Description copied from interface:Lifecycle
Check whether this component is currently running.In the case of a container, this will return
true
only if all components that apply are currently running. -
handleRequest
public reactor.core.publisher.Mono<Void> handleRequest(ServerWebExchange exchange, WebSocketHandler handler) Description copied from interface:WebSocketService
Handle the request with the givenWebSocketHandler
.- Specified by:
handleRequest
in interfaceWebSocketService
- Parameters:
exchange
- the current exchangehandler
- handler for WebSocket session- Returns:
- a
Mono<Void>
that completes when application handling of the WebSocket session completes.
-