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

public Class ReactorNettyRequestUpgradeStrategy

extends Object
implements RequestUpgradeStrategy
Class Inheritance
All Implemented Interfaces
org.springframework.web.reactive.socket.server.RequestUpgradeStrategy
Imports
java.net.URI, java.util.function.Supplier, reactor.core.publisher.Mono, reactor.netty.http.server.HttpServerResponse, .WebsocketServerSpec, org.springframework.core.io.buffer.NettyDataBufferFactory, org.springframework.http.server.reactive.ServerHttpResponse, .ServerHttpResponseDecorator, org.springframework.lang.Nullable, org.springframework.util.Assert, org.springframework.web.reactive.socket.HandshakeInfo, .WebSocketHandler, org.springframework.web.reactive.socket.adapter.ReactorNettyWebSocketSession, org.springframework.web.reactive.socket.server.RequestUpgradeStrategy, org.springframework.web.server.ServerWebExchange

A WebSocket RequestUpgradeStrategy for Reactor Netty.
Author
Rossen Stoyanchev
Since
5.0

Field Summary

Modifier and TypeField and Description
private Boolean
private Integer
private final Supplier<WebsocketServerSpec.Builder>

Constructor Summary

AccessConstructor and Description
public
public
ReactorNettyRequestUpgradeStrategy(Supplier<WebsocketServerSpec.Builder> builderSupplier)

Create an instance with a pre-configured reactor.netty.http.server.WebsocketServerSpec.Builder to use for WebSocket upgrades.

Method Summary

Modifier and TypeMethod and Description
pack-priv WebsocketServerSpec
buildSpec(String subProtocol)

public boolean
getHandlePing()
Deprecated as of 5.2.6 in favor of getWebsocketServerSpec()

Return the configured setHandlePing(boolean).

public int
getMaxFramePayloadLength()
Deprecated as of 5.2.6 in favor of getWebsocketServerSpec()

Return the configured max length for frames.

public WebsocketServerSpec
getWebsocketServerSpec()

Build an instance of WebsocketServerSpec that reflects the current configuration.

public void
setHandlePing(boolean
whether to let Ping frames through for handling
handlePing
)
Deprecated as of 5.2.6 in favor of providing a supplier of reactor.netty.http.server.WebsocketServerSpec.Builder with a constructor argument

Configure whether to let ping frames through to be handled by the WebSocketHandler given to the upgrade method.

public void
setMaxFramePayloadLength(Integer
the max length for frames.
maxFramePayloadLength
)
Deprecated as of 5.2.6 in favor of providing a supplier of reactor.netty.http.server.WebsocketServerSpec.Builder with a constructor argument

Configure the maximum allowable frame payload length.

public Mono<Void>
upgrade(ServerWebExchange
the current exchange
exchange
,
WebSocketHandler
handler for the WebSocket session
handler
,
String
the selected sub-protocol got the handler
subProtocol
,
Supplier<HandshakeInfo>
factory to create HandshakeInfo for the WebSocket session
handshakeInfoFactory
)

Implements org.springframework.web.reactive.socket.server.RequestUpgradeStrategy.upgrade.

Upgrade to a WebSocket session and handle it with the given handler.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

handlePingback to summary
private Boolean handlePing
Annotations
@Nullable
maxFramePayloadLengthback to summary
private Integer maxFramePayloadLength
Annotations
@Nullable
specBuilderSupplierback to summary
private final Supplier<WebsocketServerSpec.Builder> specBuilderSupplier

Constructor Detail

ReactorNettyRequestUpgradeStrategyback to summary
public ReactorNettyRequestUpgradeStrategy()

Create an instances with a default reactor.netty.http.server.WebsocketServerSpec.Builder.

Since
5.2.6
ReactorNettyRequestUpgradeStrategyback to summary
public ReactorNettyRequestUpgradeStrategy(Supplier<WebsocketServerSpec.Builder> builderSupplier)

Create an instance with a pre-configured reactor.netty.http.server.WebsocketServerSpec.Builder to use for WebSocket upgrades.

Since
5.2.6

Method Detail

buildSpecback to summary
pack-priv WebsocketServerSpec buildSpec(String subProtocol)
getHandlePingback to summary
public boolean getHandlePing()

Deprecated

as of 5.2.6 in favor of getWebsocketServerSpec()

Return the configured setHandlePing(boolean).

Annotations
@Deprecated
Since
5.2.4
getMaxFramePayloadLengthback to summary
public int getMaxFramePayloadLength()

Deprecated

as of 5.2.6 in favor of getWebsocketServerSpec()

Return the configured max length for frames.

Annotations
@Deprecated
Since
5.1
getWebsocketServerSpecback to summary
public WebsocketServerSpec getWebsocketServerSpec()

Build an instance of WebsocketServerSpec that reflects the current configuration. This can be used to check the configured parameters except for sub-protocols which depend on the WebSocketHandler that is used for a given upgrade.

Since
5.2.6
setHandlePingback to summary
public void setHandlePing(boolean handlePing)

Deprecated

as of 5.2.6 in favor of providing a supplier of reactor.netty.http.server.WebsocketServerSpec.Builder with a constructor argument

Configure whether to let ping frames through to be handled by the WebSocketHandler given to the upgrade method. By default, Reactor Netty automatically replies with pong frames in response to pings. This is useful in a proxy for allowing ping and pong frames through.

By default this is set to false in which case ping frames are handled automatically by Reactor Netty. If set to true, ping frames will be passed through to the WebSocketHandler.

Parameters
handlePing:boolean

whether to let Ping frames through for handling

Annotations
@Deprecated
Since
5.2.4
setMaxFramePayloadLengthback to summary
public void setMaxFramePayloadLength(Integer maxFramePayloadLength)

Deprecated

as of 5.2.6 in favor of providing a supplier of reactor.netty.http.server.WebsocketServerSpec.Builder with a constructor argument

Configure the maximum allowable frame payload length. Setting this value to your application's requirement may reduce denial of service attacks using long data frames.

Corresponds to the argument with the same name in the constructor of WebSocketServerHandshakerFactory in Netty.

By default set to 65536 (64K).

Parameters
maxFramePayloadLength:Integer

the max length for frames.

Annotations
@Deprecated
Since
5.1
upgradeback to summary
public Mono<Void> upgrade(ServerWebExchange exchange, WebSocketHandler handler, String subProtocol, Supplier<HandshakeInfo> handshakeInfoFactory)

Implements org.springframework.web.reactive.socket.server.RequestUpgradeStrategy.upgrade.

Doc from org.springframework.web.reactive.socket.server.RequestUpgradeStrategy.upgrade.

Upgrade to a WebSocket session and handle it with the given handler.

Parameters
exchange:ServerWebExchange

the current exchange

handler:WebSocketHandler

handler for the WebSocket session

subProtocol:String

the selected sub-protocol got the handler

handshakeInfoFactory:Supplier<HandshakeInfo>

factory to create HandshakeInfo for the WebSocket session

Returns:Mono<Void>

completion Mono<Void> to indicate the outcome of the WebSocket session handling.

Annotations
@Override