Class WebSocketConnectionManager
java.lang.Object
org.springframework.web.socket.client.ConnectionManagerSupport
org.springframework.web.socket.client.WebSocketConnectionManager
- All Implemented Interfaces:
Lifecycle
,Phased
,SmartLifecycle
WebSocket
connection manager
that connects
to the server via WebSocketClient
and handles the session with a
WebSocketHandler
.- Since:
- 4.0
- Author:
- Rossen Stoyanchev, Sam Brannen
-
Field Summary
Fields inherited from class org.springframework.web.socket.client.ConnectionManagerSupport
logger
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE
-
Constructor Summary
ConstructorDescriptionWebSocketConnectionManager
(WebSocketClient client, WebSocketHandler webSocketHandler, String uriTemplate, Object... uriVariables) Constructor with the client to use and a handler to handle messages with.WebSocketConnectionManager
(WebSocketClient client, WebSocketHandler webSocketHandler, URI uri) Variant ofWebSocketConnectionManager(WebSocketClient, WebSocketHandler, String, Object...)
with a preparedURI
. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Subclasses implement this to close the connection.protected WebSocketHandler
decorateWebSocketHandler
(WebSocketHandler handler) Decorate the WebSocketHandler provided to the class constructor.Return the default headers for the WebSocket handshake request.Return the configured origin.Return the configured sub-protocols to use.boolean
Whether the connection is open/true
or closed/false
.protected void
Subclasses implement this to actually establish the connection.void
setHeaders
(HttpHeaders headers) Provide default headers to add to the WebSocket handshake request.void
Set the origin to use.void
setSubProtocols
(List<String> protocols) Set the sub-protocols to use.void
void
Methods inherited from class org.springframework.web.socket.client.ConnectionManagerSupport
getPhase, getUri, isAutoStartup, isRunning, setAutoStartup, setPhase, start, stop, stop
-
Constructor Details
-
WebSocketConnectionManager
public WebSocketConnectionManager(WebSocketClient client, WebSocketHandler webSocketHandler, String uriTemplate, Object... uriVariables) Constructor with the client to use and a handler to handle messages with. -
WebSocketConnectionManager
public WebSocketConnectionManager(WebSocketClient client, WebSocketHandler webSocketHandler, URI uri) Variant ofWebSocketConnectionManager(WebSocketClient, WebSocketHandler, String, Object...)
with a preparedURI
.- Since:
- 6.0.5
-
-
Method Details
-
setSubProtocols
Set the sub-protocols to use. If configured, specified sub-protocols will be requested in the handshake through theSec-WebSocket-Protocol
header. The resulting WebSocket session will contain the protocol accepted by the server, if any. -
getSubProtocols
Return the configured sub-protocols to use. -
setOrigin
Set the origin to use. -
getOrigin
Return the configured origin. -
setHeaders
Provide default headers to add to the WebSocket handshake request. -
getHeaders
Return the default headers for the WebSocket handshake request. -
startInternal
public void startInternal()- Overrides:
startInternal
in classConnectionManagerSupport
-
stopInternal
- Overrides:
stopInternal
in classConnectionManagerSupport
- Throws:
Exception
-
isConnected
public boolean isConnected()Description copied from class:ConnectionManagerSupport
Whether the connection is open/true
or closed/false
.- Specified by:
isConnected
in classConnectionManagerSupport
-
openConnection
protected void openConnection()Description copied from class:ConnectionManagerSupport
Subclasses implement this to actually establish the connection.- Specified by:
openConnection
in classConnectionManagerSupport
-
closeConnection
Description copied from class:ConnectionManagerSupport
Subclasses implement this to close the connection.- Specified by:
closeConnection
in classConnectionManagerSupport
- Throws:
Exception
-
decorateWebSocketHandler
Decorate the WebSocketHandler provided to the class constructor.By default
LoggingWebSocketHandlerDecorator
is added.
-