public class HandshakeWebSocketService extends Object implements WebSocketService, org.springframework.context.Lifecycle
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.| Constructor and Description |
|---|
HandshakeWebSocketService()
Default constructor automatic, classpath detection based discovery of the
RequestUpgradeStrategy to use. |
HandshakeWebSocketService(RequestUpgradeStrategy upgradeStrategy)
Alternative constructor with the
RequestUpgradeStrategy to use. |
| Modifier and Type | Method and Description |
|---|---|
protected void |
doStart() |
protected void |
doStop() |
Predicate<String> |
getSessionAttributePredicate()
Return the configured predicate for initialization WebSocket session
attributes from
WebSession attributes. |
RequestUpgradeStrategy |
getUpgradeStrategy()
Return the
RequestUpgradeStrategy for WebSocket requests. |
reactor.core.publisher.Mono<Void> |
handleRequest(org.springframework.web.server.ServerWebExchange exchange,
WebSocketHandler handler)
Handle the request with the given
WebSocketHandler. |
boolean |
isRunning() |
void |
setSessionAttributePredicate(Predicate<String> predicate)
Configure a predicate to use to extract
WebSession attributes
and use them to initialize the WebSocket session with. |
void |
start() |
void |
stop() |
protected static final Log logger
public HandshakeWebSocketService()
RequestUpgradeStrategy to use.public HandshakeWebSocketService(RequestUpgradeStrategy upgradeStrategy)
RequestUpgradeStrategy to use.upgradeStrategy - the strategy to usepublic RequestUpgradeStrategy getUpgradeStrategy()
RequestUpgradeStrategy for WebSocket requests.public void setSessionAttributePredicate(@Nullable
Predicate<String> predicate)
WebSession attributes
and use them to initialize the WebSocket session with.
By default this is not set in which case no attributes are passed.
predicate - the predicate@Nullable public Predicate<String> getSessionAttributePredicate()
WebSession attributes.public void start()
start in interface org.springframework.context.Lifecycleprotected void doStart()
public void stop()
stop in interface org.springframework.context.Lifecycleprotected void doStop()
public boolean isRunning()
isRunning in interface org.springframework.context.Lifecyclepublic reactor.core.publisher.Mono<Void> handleRequest(org.springframework.web.server.ServerWebExchange exchange, WebSocketHandler handler)
WebSocketServiceWebSocketHandler.handleRequest in interface WebSocketServiceexchange - the current exchangehandler - handler for WebSocket sessionMono<Void> that completes when application handling of
the WebSocket session completes.