Top Description Fields Constructors Methods
org.springframework.web.reactive.socket.client

public Class ReactorNettyWebSocketClient

extends Object
implements WebSocketClient
Class Inheritance
All Implemented Interfaces
org.springframework.web.reactive.socket.client.WebSocketClient
Imports
java.net.URI, java.util.function.Supplier, org.apache.commons.logging.Log, .LogFactory, reactor.core.publisher.Mono, reactor.netty.http.client.HttpClient, .WebsocketClientSpec, reactor.netty.http.websocket.WebsocketInbound, org.springframework.core.io.buffer.NettyDataBufferFactory, org.springframework.http.HttpHeaders, org.springframework.lang.Nullable, org.springframework.util.Assert, .StringUtils, org.springframework.web.reactive.socket.HandshakeInfo, .WebSocketHandler, .WebSocketSession, org.springframework.web.reactive.socket.adapter.ReactorNettyWebSocketSession

WebSocketClient implementation for use with Reactor Netty.
Author
Rossen Stoyanchev
Since
5.0

Field Summary

Modifier and TypeField and Description
private Boolean
private final HttpClient
private static final Log
private Integer
private final Supplier<WebsocketClientSpec.Builder>

Constructor Summary

AccessConstructor and Description
public
ReactorNettyWebSocketClient()

Default constructor.

public
ReactorNettyWebSocketClient(HttpClient httpClient)

Constructor that accepts an existing HttpClient builder with a default reactor.netty.http.client.WebsocketClientSpec.Builder.

public
ReactorNettyWebSocketClient(HttpClient httpClient, Supplier<WebsocketClientSpec.Builder> builderSupplier)

Constructor that accepts an existing HttpClient builder and a pre-configured reactor.netty.http.client.WebsocketClientSpec.Builder.

Method Summary

Modifier and TypeMethod and Description
private WebsocketClientSpec
buildSpec(String protocols)

public Mono<Void>
execute(URI
the handshake url
url
,
WebSocketHandler
the handler of the WebSocket session
handler
)

Implements org.springframework.web.reactive.socket.client.WebSocketClient.execute.

Execute a handshake request to the given url and handle the resulting WebSocket session with the given handler.

public Mono<Void>
execute(URI
the handshake url
url
,
HttpHeaders
custom headers for the handshake request
requestHeaders
,
WebSocketHandler
the handler of the WebSocket session
handler
)

Implements org.springframework.web.reactive.socket.client.WebSocketClient.execute.

A variant of execute(URI, WebSocketHandler) with custom headers.

public boolean
getHandlePing()
Deprecated as of 5.3 in favor of getWebsocketClientSpec()

Return the configured setHandlePing(boolean).

public HttpClient
getHttpClient()

Return the configured HttpClient.

public int
getMaxFramePayloadLength()
Deprecated as of 5.3 in favor of getWebsocketClientSpec()

Return the configured maxFramePayloadLength.

public WebsocketClientSpec
getWebsocketClientSpec()

Build an instance of WebsocketClientSpec that reflects the current configuration.

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

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

public void
setMaxFramePayloadLength(int
the max length for frames.
maxFramePayloadLength
)
Deprecated as of 5.3 in favor of providing a supplier of reactor.netty.http.client.WebsocketClientSpec.Builder with a constructor argument

Configure the maximum allowable frame payload length.

private void
setNettyHeaders(HttpHeaders httpHeaders, HttpHeaders nettyHeaders)

private HttpHeaders
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

handlePingback to summary
private Boolean handlePing
Annotations
@Nullable
httpClientback to summary
private final HttpClient httpClient
loggerback to summary
private static final Log logger
maxFramePayloadLengthback to summary
private Integer maxFramePayloadLength
Annotations
@Nullable
specBuilderSupplierback to summary
private final Supplier<WebsocketClientSpec.Builder> specBuilderSupplier

Constructor Detail

ReactorNettyWebSocketClientback to summary
public ReactorNettyWebSocketClient()

Default constructor.

ReactorNettyWebSocketClientback to summary
public ReactorNettyWebSocketClient(HttpClient httpClient)

Constructor that accepts an existing HttpClient builder with a default reactor.netty.http.client.WebsocketClientSpec.Builder.

Since
5.1
ReactorNettyWebSocketClientback to summary
public ReactorNettyWebSocketClient(HttpClient httpClient, Supplier<WebsocketClientSpec.Builder> builderSupplier)

Constructor that accepts an existing HttpClient builder and a pre-configured reactor.netty.http.client.WebsocketClientSpec.Builder.

Since
5.3

Method Detail

buildSpecback to summary
private WebsocketClientSpec buildSpec(String protocols)
executeback to summary
public Mono<Void> execute(URI url, WebSocketHandler handler)

Implements org.springframework.web.reactive.socket.client.WebSocketClient.execute.

Doc from org.springframework.web.reactive.socket.client.WebSocketClient.execute.

Execute a handshake request to the given url and handle the resulting WebSocket session with the given handler.

Parameters
url:URI

the handshake url

handler:WebSocketHandler

the handler of the WebSocket session

Returns:Mono<Void>

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

Annotations
@Override
executeback to summary
public Mono<Void> execute(URI url, HttpHeaders requestHeaders, WebSocketHandler handler)

Implements org.springframework.web.reactive.socket.client.WebSocketClient.execute.

Doc from org.springframework.web.reactive.socket.client.WebSocketClient.execute.

A variant of execute(URI, WebSocketHandler) with custom headers.

Parameters
url:URI

the handshake url

requestHeaders:HttpHeaders

custom headers for the handshake request

handler:WebSocketHandler

the handler of the WebSocket session

Returns:Mono<Void>

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

Annotations
@Override
getHandlePingback to summary
public boolean getHandlePing()

Deprecated

as of 5.3 in favor of getWebsocketClientSpec()

Return the configured setHandlePing(boolean).

Annotations
@Deprecated
Since
5.2.4
getHttpClientback to summary
public HttpClient getHttpClient()

Return the configured HttpClient.

getMaxFramePayloadLengthback to summary
public int getMaxFramePayloadLength()

Deprecated

as of 5.3 in favor of getWebsocketClientSpec()

Return the configured maxFramePayloadLength.

Annotations
@Deprecated
Since
5.2
getWebsocketClientSpecback to summary
public WebsocketClientSpec getWebsocketClientSpec()

Build an instance of WebsocketClientSpec 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.3
setHandlePingback to summary
public void setHandlePing(boolean handlePing)

Deprecated

as of 5.3 in favor of providing a supplier of reactor.netty.http.client.WebsocketClientSpec.Builder with a constructor argument

Configure whether to let ping frames through to be handled by the WebSocketHandler given to the execute 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(int maxFramePayloadLength)

Deprecated

as of 5.3 in favor of providing a supplier of reactor.netty.http.client.WebsocketClientSpec.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:int

the max length for frames.

Annotations
@Deprecated
Since
5.2
setNettyHeadersback to summary
private void setNettyHeaders(HttpHeaders httpHeaders, HttpHeaders nettyHeaders)
toHttpHeadersback to summary
private HttpHeaders toHttpHeaders(WebsocketInbound inbound)