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
-
Field Summary
Fields inherited from class org.springframework.web.socket.client.AbstractWebSocketClient
logger
-
Constructor Summary
ConstructorDescriptionDefault constructor that callsContainerProvider.getWebSocketContainer()
to obtain a (new)WebSocketContainer
instance.StandardWebSocketClient
(WebSocketContainer webSocketContainer) Constructor accepting an existingWebSocketContainer
instance. -
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 the configuredAsyncTaskExecutor
.The configured user properties.void
setTaskExecutor
(AsyncTaskExecutor taskExecutor) Set anAsyncTaskExecutor
to use when opening connections.void
setUserProperties
(Map<String, Object> userProperties) The standard Jakarta WebSocket API allows passing "user properties" to the server viauserProperties
.Methods inherited from class org.springframework.web.socket.client.AbstractWebSocketClient
assertUri, doHandshakeInternal, execute, execute
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.web.socket.client.WebSocketClient
doHandshake, doHandshake
-
Constructor Details
-
StandardWebSocketClient
public StandardWebSocketClient()Default constructor that callsContainerProvider.getWebSocketContainer()
to obtain a (new)WebSocketContainer
instance. Also see constructor accepting existingWebSocketContainer
instance. -
StandardWebSocketClient
Constructor accepting an existingWebSocketContainer
instance.For XML configuration, see
WebSocketContainerFactoryBean
. For Java configuration, useContainerProvider.getWebSocketContainer()
to obtain theWebSocketContainer
instance.
-
-
Method Details
-
setUserProperties
The standard Jakarta WebSocket API allows passing "user properties" to the server viauserProperties
. Use this property to configure one or more properties to be passed on every handshake. -
getUserProperties
The configured user properties. -
setTaskExecutor
Set anAsyncTaskExecutor
to use when opening connections.If this property is set to
null
, calls to any of thedoHandshake
methods will block until the connection is established.By default, an instance of
SimpleAsyncTaskExecutor
is 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:AbstractWebSocketClient
Perform the actual handshake to establish a connection to the server.- Specified by:
executeInternal
in 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
.
-