Class StandardWebSocketClient
java.lang.Object
org.springframework.web.socket.client.AbstractWebSocketClient
org.springframework.web.socket.client.standard.StandardWebSocketClient
- All Implemented Interfaces:
WebSocketClient
A WebSocketClient based on the standard Jakarta WebSocket API.
- Since:
- 4.0
- Author:
- Rossen Stoyanchev, Juergen Hoeller
-
Field Summary
Fields inherited from class AbstractWebSocketClient
logger -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor that callsContainerProvider.getWebSocketContainer()to obtain a (new)WebSocketContainerinstance.StandardWebSocketClient(jakarta.websocket.WebSocketContainer webSocketContainer) Constructor accepting an existingWebSocketContainerinstance. -
Method Summary
Modifier and TypeMethodDescriptionprotected CompletableFuture<WebSocketSession> executeInternal(WebSocketHandler webSocketHandler, HttpHeaders headers, URI uri, List<String> protocols, List<WebSocketExtension> extensions, Map<String, Object> attributes) Perform the actual handshake to establish a connection to the server.Return theSSLContextto use.Return the configuredAsyncTaskExecutor.Return the configured user properties.voidsetSslContext(@Nullable SSLContext sslContext) Set theSSLContextto use forClientEndpointConfig.getSSLContext().voidsetTaskExecutor(@Nullable AsyncTaskExecutor taskExecutor) Set anAsyncTaskExecutorto use when opening connections.voidsetUserProperties(@Nullable Map<String, Object> userProperties) The standard Jakarta WebSocket API allows passing "user properties" to the server viauserProperties.Methods inherited from class AbstractWebSocketClient
assertUri, execute, execute
-
Constructor Details
-
StandardWebSocketClient
public StandardWebSocketClient()Default constructor that callsContainerProvider.getWebSocketContainer()to obtain a (new)WebSocketContainerinstance. Also see constructor accepting existingWebSocketContainerinstance. -
StandardWebSocketClient
public StandardWebSocketClient(jakarta.websocket.WebSocketContainer webSocketContainer) Constructor accepting an existingWebSocketContainerinstance.For XML configuration, see
WebSocketContainerFactoryBean. For Java configuration, useContainerProvider.getWebSocketContainer()to obtain theWebSocketContainerinstance.
-
-
Method Details
-
setUserProperties
-
getUserProperties
-
setSslContext
Set theSSLContextto use forClientEndpointConfig.getSSLContext().- Since:
- 6.1.3
-
getSslContext
-
setTaskExecutor
Set anAsyncTaskExecutorto use when opening connections.If this property is set to
null, calls to any of thedoHandshakemethods will block until the connection is established.By default, an instance of
SimpleAsyncTaskExecutoris used. -
getTaskExecutor
Return the configuredAsyncTaskExecutor. -
executeInternal
protected CompletableFuture<WebSocketSession> executeInternal(WebSocketHandler webSocketHandler, HttpHeaders headers, URI uri, List<String> protocols, List<WebSocketExtension> extensions, Map<String, Object> attributes) Description copied from class:AbstractWebSocketClientPerform the actual handshake to establish a connection to the server.- Specified by:
executeInternalin classAbstractWebSocketClient- Parameters:
webSocketHandler- the client-side handler for WebSocket messagesheaders- the HTTP headers to use for the handshake, with unwanted (forbidden) headers filtered out (nevernull)uri- the target URI for the handshake (nevernull)protocols- requested sub-protocols, or an empty listextensions- requested WebSocket extensions, or an empty listattributes- the attributes to associate with the WebSocketSession, i.e. viaWebSocketSession.getAttributes(); currently always an empty map- Returns:
- the established WebSocket session wrapped in a
CompletableFuture.
-