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

public Class StandardWebSocketClient

extends AbstractWebSocketClient
Class Inheritance
Imports
java.net.InetAddress, .InetSocketAddress, .URI, .UnknownHostException, java.util.ArrayList, .HashMap, .List, .Locale, .Map, java.util.concurrent.Callable, .CompletableFuture, javax.net.ssl.SSLContext, jakarta.websocket.ClientEndpointConfig, .ClientEndpointConfig.Configurator, .ContainerProvider, .Endpoint, .Extension, .HandshakeResponse, .WebSocketContainer, org.springframework.core.task.AsyncTaskExecutor, .SimpleAsyncTaskExecutor, org.springframework.http.HttpHeaders, org.springframework.lang.Nullable, org.springframework.util.Assert, org.springframework.util.concurrent.FutureUtils, org.springframework.web.socket.WebSocketExtension, .WebSocketHandler, .WebSocketSession, org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter, .StandardWebSocketSession, .WebSocketToStandardExtensionAdapter, org.springframework.web.socket.client.AbstractWebSocketClient

A WebSocketClient based on the standard Jakarta WebSocket API.
Authors
Rossen Stoyanchev, Juergen Hoeller
Since
4.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private SSLContext
private AsyncTaskExecutor
private final Map<String, Object>
private final WebSocketContainer
Inherited from org.springframework.web.socket.client.AbstractWebSocketClient:
logger

Constructor Summary

AccessConstructor and Description
public
StandardWebSocketClient()

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

public
StandardWebSocketClient(WebSocketContainer webSocketContainer)

Constructor accepting an existing WebSocketContainer instance.

Method Summary

Modifier and TypeMethod and Description
private static List<Extension>
protected CompletableFuture<WebSocketSession>
executeInternal(WebSocketHandler
the client-side handler for WebSocket messages
webSocketHandler
,
HttpHeaders
the HTTP headers to use for the handshake, with unwanted (forbidden) headers filtered out (never null)
headers
,
final URI
the target URI for the handshake (never null)
uri
,
List<String>
requested sub-protocols, or an empty list
protocols
,
List<WebSocketExtension>
requested WebSocket extensions, or an empty list
extensions
,
Map<String, Object>
the attributes to associate with the WebSocketSession, i.e. via WebSocketSession#getAttributes(); currently always an empty map
attributes
)

Implements abstract org.springframework.web.socket.client.AbstractWebSocketClient.executeInternal.

Perform the actual handshake to establish a connection to the server.

private static InetAddress
private static int
getPort(URI uri)

public SSLContext
getSslContext()

Return the SSLContext to use.

public AsyncTaskExecutor
getTaskExecutor()

Return the configured AsyncTaskExecutor.

public Map<String, Object>
getUserProperties()

Return the configured user properties.

public void
public void
setTaskExecutor(AsyncTaskExecutor taskExecutor)

Set an AsyncTaskExecutor to use when opening connections.

public void
setUserProperties(Map<String, Object> userProperties)

The standard Jakarta WebSocket API allows passing "user properties" to the server via userProperties.

Inherited from org.springframework.web.socket.client.AbstractWebSocketClient:
assertUridoHandshakeInternalexecuteexecute

Field Detail

sslContextback to summary
private SSLContext sslContext
Annotations
@Nullable
taskExecutorback to summary
private AsyncTaskExecutor taskExecutor
Annotations
@Nullable
userPropertiesback to summary
private final Map<String, Object> userProperties
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. Also see constructor accepting existing WebSocketContainer instance.

StandardWebSocketClientback to summary
public StandardWebSocketClient(WebSocketContainer webSocketContainer)

Constructor accepting an existing WebSocketContainer instance.

For XML configuration, see WebSocketContainerFactoryBean. For Java configuration, use ContainerProvider.getWebSocketContainer() to obtain the WebSocketContainer instance.

Method Detail

adaptExtensionsback to summary
private static List<Extension> adaptExtensions(List<WebSocketExtension> extensions)
executeInternalback to summary
protected CompletableFuture<WebSocketSession> executeInternal(WebSocketHandler webSocketHandler, HttpHeaders headers, final URI uri, List<String> protocols, List<WebSocketExtension> extensions, Map<String, Object> attributes)

Implements abstract org.springframework.web.socket.client.AbstractWebSocketClient.executeInternal.

Doc from org.springframework.web.socket.client.AbstractWebSocketClient.executeInternal.

Perform the actual handshake to establish a connection to the server.

Parameters
webSocketHandler:WebSocketHandler

the client-side handler for WebSocket messages

headers:HttpHeaders

the HTTP headers to use for the handshake, with unwanted (forbidden) headers filtered out (never null)

uri:URI

the target URI for the handshake (never null)

protocols:List<String>

requested sub-protocols, or an empty list

extensions:List<WebSocketExtension>

requested WebSocket extensions, or an empty list

attributes:Map<String, Object>

the attributes to associate with the WebSocketSession, i.e. via WebSocketSession#getAttributes(); currently always an empty map

Returns:CompletableFuture<WebSocketSession>

the established WebSocket session wrapped in a CompletableFuture.

Annotations
@Override
getLocalHostback to summary
private static InetAddress getLocalHost()
getPortback to summary
private static int getPort(URI uri)
getSslContextback to summary
public SSLContext getSslContext()

Return the SSLContext to use.

Annotations
@Nullable
Since
6.1.3
getTaskExecutorback to summary
public AsyncTaskExecutor getTaskExecutor()

Return the configured AsyncTaskExecutor.

Annotations
@Nullable
getUserPropertiesback to summary
public Map<String, Object> getUserProperties()

Return the configured user properties.

setSslContextback to summary
public void setSslContext(SSLContext sslContext)

Set the SSLContext to use for ClientEndpointConfig#getSSLContext().

Since
6.1.3
setTaskExecutorback to summary
public void setTaskExecutor(AsyncTaskExecutor taskExecutor)

Set an AsyncTaskExecutor to use when opening connections.

If this property is set to null, calls to any of the doHandshake methods will block until the connection is established.

By default, an instance of SimpleAsyncTaskExecutor is used.

setUserPropertiesback to summary
public void setUserProperties(Map<String, Object> userProperties)

The standard Jakarta WebSocket API allows passing "user properties" to the server via userProperties. Use this property to configure one or more properties to be passed on every handshake.

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

private Class StandardWebSocketClient.StandardWebSocketClientConfigurator

extends Configurator
Class Inheritance

Field Summary

Modifier and TypeField and Description
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.

Field Detail

headersback to summary
private final HttpHeaders headers

Constructor Detail

StandardWebSocketClientConfiguratorback to summary
public StandardWebSocketClientConfigurator(HttpHeaders headers)

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