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

public Class HandshakeWebSocketService

extends Object
implements WebSocketService, Lifecycle
Class Inheritance
All Implemented Interfaces
org.springframework.context.Lifecycle, org.springframework.web.reactive.socket.server.WebSocketService
Imports
java.net.InetSocketAddress, .URI, java.security.Principal, java.util.Collections, .List, .Map, java.util.function.Predicate, java.util.stream.Collectors, org.apache.commons.logging.Log, .LogFactory, reactor.core.publisher.Mono, org.springframework.context.Lifecycle, org.springframework.http.HttpCookie, .HttpHeaders, .HttpMethod, org.springframework.http.server.reactive.ServerHttpRequest, org.springframework.lang.Nullable, org.springframework.util.Assert, .ClassUtils, .MultiValueMap, .StringUtils, org.springframework.web.reactive.socket.HandshakeInfo, .WebSocketHandler, org.springframework.web.reactive.socket.server.RequestUpgradeStrategy, .WebSocketService, org.springframework.web.reactive.socket.server.upgrade.JettyRequestUpgradeStrategy, .ReactorNetty2RequestUpgradeStrategy, .ReactorNettyRequestUpgradeStrategy, .StandardWebSocketUpgradeStrategy, .TomcatRequestUpgradeStrategy, .UndertowRequestUpgradeStrategy, org.springframework.web.server.MethodNotAllowedException, .ServerWebExchange, .ServerWebInputException

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.
Authors
Rossen Stoyanchev, Juergen Hoeller
Since
5.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
HandshakeWebSocketService.ReactorNettyStrategyDelegate

Inner class to avoid a reachable dependency on Reactor Netty API.

Field Summary

Modifier and TypeField and Description
private static final Mono<Map<String, Object>>
private static final boolean
private static final Log
private static final boolean
private static final boolean
private volatile boolean
private static final String
private static final String
private Predicate<String>
private static final boolean
private static final boolean
private final RequestUpgradeStrategy

Constructor Summary

AccessConstructor and Description
public
HandshakeWebSocketService()

Default constructor automatic, classpath detection based discovery of the RequestUpgradeStrategy to use.

public
HandshakeWebSocketService(RequestUpgradeStrategy
the strategy to use
upgradeStrategy
)

Alternative constructor with the RequestUpgradeStrategy to use.

Method Summary

Modifier and TypeMethod and Description
private HandshakeInfo
createHandshakeInfo(ServerWebExchange exchange, ServerHttpRequest request, String protocol, Map<String, Object> attributes)

protected void
protected void
public Predicate<String>
getSessionAttributePredicate()

Return the configured predicate for initialization WebSocket session attributes from WebSession attributes.

public RequestUpgradeStrategy
getUpgradeStrategy()

Return the RequestUpgradeStrategy for WebSocket requests.

private Mono<Void>
public Mono<Void>
handleRequest(ServerWebExchange
the current exchange
exchange
,
WebSocketHandler
handler for WebSocket session
handler
)

Implements org.springframework.web.reactive.socket.server.WebSocketService.handleRequest.

Handle the request with the given WebSocketHandler.

private Mono<Map<String, Object>>
pack-priv static RequestUpgradeStrategy
public boolean
isRunning()

Implements org.springframework.context.Lifecycle.isRunning.

Check whether this component is currently running.

private String
public void
setSessionAttributePredicate(Predicate<String>
the predicate
predicate
)

Configure a predicate to use to extract WebSession attributes and use them to initialize the WebSocket session with.

public void
start()

Implements org.springframework.context.Lifecycle.start.

Start this component.

public void
stop()

Implements org.springframework.context.Lifecycle.stop.

Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

EMPTY_ATTRIBUTESback to summary
private static final Mono<Map<String, Object>> EMPTY_ATTRIBUTES
jettyWsPresentback to summary
private static final boolean jettyWsPresent
loggerback to summary
private static final Log logger
reactorNetty2Presentback to summary
private static final boolean reactorNetty2Present
reactorNettyPresentback to summary
private static final boolean reactorNettyPresent
runningback to summary
private volatile boolean running
SEC_WEBSOCKET_KEYback to summary
private static final String SEC_WEBSOCKET_KEY
SEC_WEBSOCKET_PROTOCOLback to summary
private static final String SEC_WEBSOCKET_PROTOCOL
sessionAttributePredicateback to summary
private Predicate<String> sessionAttributePredicate
Annotations
@Nullable
tomcatWsPresentback to summary
private static final boolean tomcatWsPresent
undertowWsPresentback to summary
private static final boolean undertowWsPresent
upgradeStrategyback to summary
private final RequestUpgradeStrategy upgradeStrategy

Constructor Detail

HandshakeWebSocketServiceback to summary
public HandshakeWebSocketService()

Default constructor automatic, classpath detection based discovery of the RequestUpgradeStrategy to use.

HandshakeWebSocketServiceback to summary
public HandshakeWebSocketService(RequestUpgradeStrategy upgradeStrategy)

Alternative constructor with the RequestUpgradeStrategy to use.

Parameters
upgradeStrategy:RequestUpgradeStrategy

the strategy to use

Method Detail

createHandshakeInfoback to summary
private HandshakeInfo createHandshakeInfo(ServerWebExchange exchange, ServerHttpRequest request, String protocol, Map<String, Object> attributes)
doStartback to summary
protected void doStart()
doStopback to summary
protected void doStop()
getSessionAttributePredicateback to summary
public Predicate<String> getSessionAttributePredicate()

Return the configured predicate for initialization WebSocket session attributes from WebSession attributes.

Annotations
@Nullable
Since
5.1
getUpgradeStrategyback to summary
public RequestUpgradeStrategy getUpgradeStrategy()

Return the RequestUpgradeStrategy for WebSocket requests.

handleBadRequestback to summary
private Mono<Void> handleBadRequest(ServerWebExchange exchange, String reason)
handleRequestback to summary
public Mono<Void> handleRequest(ServerWebExchange exchange, WebSocketHandler handler)

Implements org.springframework.web.reactive.socket.server.WebSocketService.handleRequest.

Doc from org.springframework.web.reactive.socket.server.WebSocketService.handleRequest.

Handle the request with the given WebSocketHandler.

Parameters
exchange:ServerWebExchange

the current exchange

handler:WebSocketHandler

handler for WebSocket session

Returns:Mono<Void>

a Mono<Void> that completes when application handling of the WebSocket session completes.

Annotations
@Override
initAttributesback to summary
private Mono<Map<String, Object>> initAttributes(ServerWebExchange exchange)
initUpgradeStrategyback to summary
pack-priv static RequestUpgradeStrategy initUpgradeStrategy()
isRunningback to summary
public boolean isRunning()

Implements org.springframework.context.Lifecycle.isRunning.

Doc from org.springframework.context.Lifecycle.isRunning.

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.

Returns:boolean

whether the component is currently running

Annotations
@Override
selectProtocolback to summary
private String selectProtocol(HttpHeaders headers, WebSocketHandler handler)
Annotations
@Nullable
setSessionAttributePredicateback to summary
public void setSessionAttributePredicate(Predicate<String> predicate)

Configure a predicate to use to extract WebSession 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:Predicate<String>

the predicate

Since
5.1
startback to summary
public void start()

Implements org.springframework.context.Lifecycle.start.

Doc from org.springframework.context.Lifecycle.start.

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.

Annotations
@Override
stopback to summary
public void stop()

Implements org.springframework.context.Lifecycle.stop.

Doc from org.springframework.context.Lifecycle.stop.

Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method. Consider implementing SmartLifecycle and its stop(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.

Annotations
@Override
org.springframework.web.reactive.socket.server.support back to summary

private Class HandshakeWebSocketService.ReactorNettyStrategyDelegate

extends Object
Class Inheritance
  • java.lang.Object
  • org.springframework.web.reactive.socket.server.support.HandshakeWebSocketService.ReactorNettyStrategyDelegate

Inner class to avoid a reachable dependency on Reactor Netty API.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static RequestUpgradeStrategy
public static RequestUpgradeStrategy
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ReactorNettyStrategyDelegateback to summary
private ReactorNettyStrategyDelegate()

Method Detail

forReactorNetty1back to summary
public static RequestUpgradeStrategy forReactorNetty1()
forReactorNetty2back to summary
public static RequestUpgradeStrategy forReactorNetty2()