Class JettyWebSocketClient
java.lang.Object
org.springframework.web.socket.client.AbstractWebSocketClient
org.springframework.web.socket.client.jetty.JettyWebSocketClient
- All Implemented Interfaces:
org.springframework.context.Lifecycle,WebSocketClient
public class JettyWebSocketClient
extends AbstractWebSocketClient
implements org.springframework.context.Lifecycle
Initiates WebSocket requests to a WebSocket server programmatically
through the Jetty WebSocket API.
As of 4.1 this class implements Lifecycle rather than
SmartLifecycle. Use
WebSocketConnectionManager instead to auto-start a WebSocket connection.
- Since:
- 4.0
- Author:
- Rossen Stoyanchev, Juergen Hoeller
-
Field Summary
Fields inherited from class org.springframework.web.socket.client.AbstractWebSocketClient
logger -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor that creates an instance ofWebSocketClient.JettyWebSocketClient(org.eclipse.jetty.websocket.client.WebSocketClient client) Constructor that accepts an existingWebSocketClientinstance. -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.util.concurrent.ListenableFuture<WebSocketSession>doHandshake(WebSocketHandler webSocketHandler, String uriTemplate, Object... uriVars) org.springframework.util.concurrent.ListenableFuture<WebSocketSession>doHandshakeInternal(WebSocketHandler wsHandler, org.springframework.http.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.org.springframework.core.task.AsyncListenableTaskExecutorReturn the configuredTaskExecutor.protected PrincipalgetUser()Return the user to make available throughWebSocketSession.getPrincipal().booleanvoidsetTaskExecutor(org.springframework.core.task.AsyncListenableTaskExecutor taskExecutor) Set anAsyncListenableTaskExecutorto use when opening connections.voidstart()voidstop()Methods inherited from class org.springframework.web.socket.client.AbstractWebSocketClient
assertUri, doHandshake
-
Constructor Details
-
JettyWebSocketClient
public JettyWebSocketClient()Default constructor that creates an instance ofWebSocketClient. -
JettyWebSocketClient
public JettyWebSocketClient(org.eclipse.jetty.websocket.client.WebSocketClient client) Constructor that accepts an existingWebSocketClientinstance.
-
-
Method Details
-
setTaskExecutor
public void setTaskExecutor(@Nullable org.springframework.core.task.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
@Nullable public org.springframework.core.task.AsyncListenableTaskExecutor getTaskExecutor()Return the configuredTaskExecutor. -
start
public void start()- Specified by:
startin interfaceorg.springframework.context.Lifecycle
-
stop
public void stop()- Specified by:
stopin interfaceorg.springframework.context.Lifecycle
-
isRunning
public boolean isRunning()- Specified by:
isRunningin interfaceorg.springframework.context.Lifecycle
-
doHandshake
public org.springframework.util.concurrent.ListenableFuture<WebSocketSession> doHandshake(WebSocketHandler webSocketHandler, String uriTemplate, Object... uriVars) - Specified by:
doHandshakein interfaceWebSocketClient- Overrides:
doHandshakein classAbstractWebSocketClient
-
doHandshakeInternal
public org.springframework.util.concurrent.ListenableFuture<WebSocketSession> doHandshakeInternal(WebSocketHandler wsHandler, org.springframework.http.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:
wsHandler- 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 ListenableFuture.
-
getUser
Return the user to make available throughWebSocketSession.getPrincipal(). By default this method returnsnull
-