Class StandardWebSocketClient
- java.lang.Object
- org.springframework.web.socket.client.AbstractWebSocketClient
- org.springframework.web.socket.client.standard.StandardWebSocketClient
- All Implemented Interfaces:
WebSocketClient
public class StandardWebSocketClient extends AbstractWebSocketClient
A WebSocketClient based on standard Java WebSocket API.- Since:
- 4.0
- Author:
- Rossen Stoyanchev
Field Summary
Fields inherited from class org.springframework.web.socket.client.AbstractWebSocketClient
logger
Constructor Summary
Constructors Constructor Description StandardWebSocketClient()Default constructor that callsContainerProvider.getWebSocketContainer()to obtain a (new)WebSocketContainerinstance.StandardWebSocketClient(WebSocketContainer webSocketContainer)Constructor accepting an existingWebSocketContainerinstance.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected ListenableFuture<WebSocketSession>doHandshakeInternal(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.AsyncListenableTaskExecutorgetTaskExecutor()Return the configuredTaskExecutor.Map<String,Object>getUserProperties()The configured user properties, ornull.voidsetTaskExecutor(AsyncListenableTaskExecutor taskExecutor)Set anAsyncListenableTaskExecutorto use when opening connections.voidsetUserProperties(Map<String,Object> userProperties)The standard Java WebSocket API allows passing "user properties" to the server viauserProperties.Methods inherited from class org.springframework.web.socket.client.AbstractWebSocketClient
assertUri, doHandshake, doHandshake
Constructor Detail
StandardWebSocketClient
public StandardWebSocketClient()
Default constructor that callsContainerProvider.getWebSocketContainer()to obtain a (new)WebSocketContainerinstance. Also see constructor accepting existingWebSocketContainerinstance.
StandardWebSocketClient
public StandardWebSocketClient(WebSocketContainer webSocketContainer)
Constructor accepting an existingWebSocketContainerinstance.For XML configuration, see
WebSocketContainerFactoryBean. For Java configuration, useContainerProvider.getWebSocketContainer()to obtain theWebSocketContainerinstance.
Method Detail
setUserProperties
public void setUserProperties(Map<String,Object> userProperties)
The standard Java 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
public Map<String,Object> getUserProperties()
The configured user properties, ornull.
setTaskExecutor
public void setTaskExecutor(AsyncListenableTaskExecutor taskExecutor)
Set anAsyncListenableTaskExecutorto use when opening connections. If this property is set tonull, calls to any of thedoHandshakemethods will block until the connection is established.By default, an instance of
SimpleAsyncTaskExecutoris used.
getTaskExecutor
public AsyncListenableTaskExecutor getTaskExecutor()
Return the configuredTaskExecutor.
doHandshakeInternal
protected ListenableFuture<WebSocketSession> doHandshakeInternal(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:
doHandshakeInternalin classAbstractWebSocketClient- Parameters:
webSocketHandler- the client-side handler for WebSocket messagesheaders- HTTP headers to use for the handshake, with unwanted (forbidden) headers filtered out, nevernulluri- the target URI for the handshake, nevernullprotocols- requested sub-protocols, or an empty listextensions- requested WebSocket extensions, or an empty listattributes- attributes to associate with the WebSocketSession, i.e. viaWebSocketSession.getAttributes(); currently always an empty map.- Returns:
- the established WebSocket session wrapped in a ListenableFuture.