Class HandshakeWebSocketService
java.lang.Object
org.springframework.web.reactive.socket.server.support.HandshakeWebSocketService
- All Implemented Interfaces:
org.springframework.context.Lifecycle,WebSocketService
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.- Since:
- 5.0
- Author:
- Rossen Stoyanchev, Juergen Hoeller
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor automatic, classpath detection based discovery of theRequestUpgradeStrategyto use.HandshakeWebSocketService(RequestUpgradeStrategy upgradeStrategy) Alternative constructor with theRequestUpgradeStrategyto use. -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddoStart()protected voiddoStop()Return the configured predicate for initialization WebSocket session attributes fromWebSessionattributes.Return theRequestUpgradeStrategyfor WebSocket requests.reactor.core.publisher.Mono<Void>handleRequest(org.springframework.web.server.ServerWebExchange exchange, WebSocketHandler handler) Handle the request with the givenWebSocketHandler.booleanvoidsetSessionAttributePredicate(Predicate<String> predicate) Configure a predicate to use to extractWebSessionattributes and use them to initialize the WebSocket session with.voidstart()voidstop()
-
Constructor Details
-
HandshakeWebSocketService
public HandshakeWebSocketService()Default constructor automatic, classpath detection based discovery of theRequestUpgradeStrategyto use. -
HandshakeWebSocketService
Alternative constructor with theRequestUpgradeStrategyto use.- Parameters:
upgradeStrategy- the strategy to use
-
-
Method Details
-
getUpgradeStrategy
Return theRequestUpgradeStrategyfor WebSocket requests. -
setSessionAttributePredicate
Configure a predicate to use to extractWebSessionattributes 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 fromWebSessionattributes.- Since:
- 5.1
-
start
public void start()- Specified by:
startin interfaceorg.springframework.context.Lifecycle
-
doStart
protected void doStart() -
stop
public void stop()- Specified by:
stopin interfaceorg.springframework.context.Lifecycle
-
doStop
protected void doStop() -
isRunning
public boolean isRunning()- Specified by:
isRunningin interfaceorg.springframework.context.Lifecycle
-
handleRequest
public reactor.core.publisher.Mono<Void> handleRequest(org.springframework.web.server.ServerWebExchange exchange, WebSocketHandler handler) Description copied from interface:WebSocketServiceHandle the request with the givenWebSocketHandler.- Specified by:
handleRequestin interfaceWebSocketService- Parameters:
exchange- the current exchangehandler- handler for WebSocket session- Returns:
- a
Mono<Void>that completes when application handling of the WebSocket session completes.
-