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

public Class StandardWebSocketClient

extends Object
implements WebSocketClient
Class Inheritance
All Implemented Interfaces
org.springframework.web.reactive.socket.client.WebSocketClient
Known Direct Subclasses
org.springframework.web.reactive.socket.client.TomcatWebSocketClient
Imports
java.net.URI, java.util.List, .Map, jakarta.websocket.ClientEndpointConfig, .ClientEndpointConfig.Configurator, .ContainerProvider, .Endpoint, .HandshakeResponse, .Session, .WebSocketContainer, org.apache.commons.logging.Log, .LogFactory, reactor.core.publisher.Mono, .Sinks, reactor.core.scheduler.Schedulers, org.springframework.core.io.buffer.DataBufferFactory, .DefaultDataBufferFactory, org.springframework.http.HttpHeaders, org.springframework.web.reactive.socket.HandshakeInfo, .WebSocketHandler, org.springframework.web.reactive.socket.adapter.ContextWebSocketHandler, .StandardWebSocketHandlerAdapter, .StandardWebSocketSession

WebSocketClient implementation for use with the Jakarta WebSocket API.
Authors
Violeta Georgieva, Rossen Stoyanchev
Since
5.0
See Also
https://www.jcp.org/en/jsr/detail?id=356

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final Log
private final WebSocketContainer

Constructor Summary

AccessConstructor and Description
public
StandardWebSocketClient()

Default constructor that calls ContainerProvider.getWebSocketContainer() to obtain a (new) WebSocketContainer instance.

public
StandardWebSocketClient(WebSocketContainer
a web socket container
webSocketContainer
)

Constructor accepting an existing WebSocketContainer instance.

Method Summary

Modifier and TypeMethod and Description
protected DataBufferFactory
bufferFactory()

Return the DataBufferFactory to use.

private StandardWebSocketHandlerAdapter
protected ClientEndpointConfig
createEndpointConfig(ClientEndpointConfig.Configurator
the configurator to apply
configurator
,
List<String>
the preferred sub-protocols
subProtocols
)

Create the ClientEndpointConfig for the given configurator.

private HandshakeInfo
protected StandardWebSocketSession
createWebSocketSession(Session session, HandshakeInfo info, Sinks.Empty<Void> completionSink)

Create the StandardWebSocketSession for the given Jakarta WebSocket Session.

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
headers
,
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.

private Mono<Void>
executeInternal(URI url, HttpHeaders requestHeaders, WebSocketHandler handler)

public WebSocketContainer
getWebSocketContainer()

Return the configured WebSocketContainer to use.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

loggerback to summary
private static final Log logger
webSocketContainerback to summary
private final WebSocketContainer webSocketContainer

Constructor Detail

StandardWebSocketClientback to summary
public StandardWebSocketClient()

Default constructor that calls ContainerProvider.getWebSocketContainer() to obtain a (new) WebSocketContainer instance.

StandardWebSocketClientback to summary
public StandardWebSocketClient(WebSocketContainer webSocketContainer)

Constructor accepting an existing WebSocketContainer instance.

Parameters
webSocketContainer:WebSocketContainer

a web socket container

Method Detail

bufferFactoryback to summary
protected DataBufferFactory bufferFactory()

Return the DataBufferFactory to use.

See Also
createWebSocketSession
createEndpointback to summary
private StandardWebSocketHandlerAdapter createEndpoint(URI url, WebSocketHandler handler, Sinks.Empty<Void> completionSink, StandardWebSocketClient.DefaultConfigurator configurator)
createEndpointConfigback to summary
protected ClientEndpointConfig createEndpointConfig(ClientEndpointConfig.Configurator configurator, List<String> subProtocols)

Create the ClientEndpointConfig for the given configurator. Can be overridden to add extensions or an SSL context.

Parameters
configurator:ClientEndpointConfig.Configurator

the configurator to apply

subProtocols:List<String>

the preferred sub-protocols

Since
6.1.3
createHandshakeInfoback to summary
private HandshakeInfo createHandshakeInfo(URI url, StandardWebSocketClient.DefaultConfigurator configurator)
createWebSocketSessionback to summary
protected StandardWebSocketSession createWebSocketSession(Session session, HandshakeInfo info, Sinks.Empty<Void> completionSink)

Create the StandardWebSocketSession for the given Jakarta WebSocket Session.

See Also
bufferFactory()
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 headers, 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

headers: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
executeInternalback to summary
private Mono<Void> executeInternal(URI url, HttpHeaders requestHeaders, WebSocketHandler handler)
getWebSocketContainerback to summary
public WebSocketContainer getWebSocketContainer()

Return the configured WebSocketContainer to use.

org.springframework.web.reactive.socket.client back to summary

private final Class StandardWebSocketClient.DefaultConfigurator

extends Configurator
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final HttpHeaders
private final HttpHeaders

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
afterResponse(HandshakeResponse
The response
response
)

Overrides jakarta.websocket.ClientEndpointConfig.Configurator.afterResponse.

Provides the client with a mechanism to inspect the handshake response that is returned from the server.

public void
beforeRequest(Map<String, List<String>>
The HTTP headers
requestHeaders
)

Overrides jakarta.websocket.ClientEndpointConfig.Configurator.beforeRequest.

Provides the client with a mechanism to inspect and/or modify the headers that are sent to the server to start the WebSocket handshake.

public HttpHeaders

Field Detail

requestHeadersback to summary
private final HttpHeaders requestHeaders
responseHeadersback to summary
private final HttpHeaders responseHeaders

Constructor Detail

DefaultConfiguratorback to summary
public DefaultConfigurator(HttpHeaders requestHeaders)

Method Detail

afterResponseback to summary
public void afterResponse(HandshakeResponse response)

Overrides jakarta.websocket.ClientEndpointConfig.Configurator.afterResponse.

Doc from jakarta.websocket.ClientEndpointConfig.Configurator.afterResponse.

Provides the client with a mechanism to inspect the handshake response that is returned from the server.

Parameters
response:HandshakeResponse

The response

Annotations
@Override
beforeRequestback to summary
public void beforeRequest(Map<String, List<String>> requestHeaders)

Overrides jakarta.websocket.ClientEndpointConfig.Configurator.beforeRequest.

Doc from jakarta.websocket.ClientEndpointConfig.Configurator.beforeRequest.

Provides the client with a mechanism to inspect and/or modify the headers that are sent to the server to start the WebSocket handshake.

Parameters
requestHeaders:Map<String, List<String>>

The HTTP headers

Annotations
@Override
getResponseHeadersback to summary
public HttpHeaders getResponseHeaders()