Class WebSocketConnectionManager
- java.lang.Object
- org.springframework.web.socket.client.ConnectionManagerSupport
- org.springframework.web.socket.client.WebSocketConnectionManager
- All Implemented Interfaces:
Lifecycle,Phased,SmartLifecycle
public class WebSocketConnectionManager extends ConnectionManagerSupport
A WebSocket connection manager that is given a URI, aWebSocketClient, and aWebSocketHandler, connects to a WebSocket server throughConnectionManagerSupport.start()andConnectionManagerSupport.stop()methods. IfConnectionManagerSupport.setAutoStartup(boolean)is set totruethis will be done automatically when the Spring ApplicationContext is refreshed.- Since:
- 4.0
- Author:
- Rossen Stoyanchev
Field Summary
Fields inherited from class org.springframework.web.socket.client.ConnectionManagerSupport
logger
Constructor Summary
Constructors Constructor Description WebSocketConnectionManager(WebSocketClient client, WebSocketHandler webSocketHandler, String uriTemplate, Object... uriVariables)
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcloseConnection()protected WebSocketHandlerdecorateWebSocketHandler(WebSocketHandler handler)Decorate the WebSocketHandler provided to the class constructor.HttpHeadersgetHeaders()Return the default headers for the WebSocket handshake request.StringgetOrigin()Return the configured origin.List<String>getSubProtocols()Return the configured sub-protocols to use.protected booleanisConnected()protected voidopenConnection()voidsetHeaders(HttpHeaders headers)Provide default headers to add to the WebSocket handshake request.voidsetOrigin(String origin)Set the origin to use.voidsetSubProtocols(List<String> protocols)Set the sub-protocols to use.voidstartInternal()voidstopInternal()Methods inherited from class org.springframework.web.socket.client.ConnectionManagerSupport
getPhase, getUri, isAutoStartup, isRunning, setAutoStartup, setPhase, start, stop, stop
Constructor Detail
WebSocketConnectionManager
public WebSocketConnectionManager(WebSocketClient client, WebSocketHandler webSocketHandler, String uriTemplate, Object... uriVariables)
Method Detail
decorateWebSocketHandler
protected WebSocketHandler decorateWebSocketHandler(WebSocketHandler handler)
Decorate the WebSocketHandler provided to the class constructor.By default
LoggingWebSocketHandlerDecoratoris added.
setSubProtocols
public void setSubProtocols(List<String> protocols)
Set the sub-protocols to use. If configured, specified sub-protocols will be requested in the handshake through theSec-WebSocket-Protocolheader. The resulting WebSocket session will contain the protocol accepted by the server, if any.
getSubProtocols
public List<String> getSubProtocols()
Return the configured sub-protocols to use.
setHeaders
public void setHeaders(HttpHeaders headers)
Provide default headers to add to the WebSocket handshake request.
getHeaders
public HttpHeaders getHeaders()
Return the default headers for the WebSocket handshake request.
startInternal
public void startInternal()
- Overrides:
startInternalin classConnectionManagerSupport
stopInternal
public void stopInternal() throws Exception
- Overrides:
stopInternalin classConnectionManagerSupport- Throws:
Exception
openConnection
protected void openConnection()
- Specified by:
openConnectionin classConnectionManagerSupport
closeConnection
protected void closeConnection() throws Exception
- Specified by:
closeConnectionin classConnectionManagerSupport- Throws:
Exception
isConnected
protected boolean isConnected()
- Specified by:
isConnectedin classConnectionManagerSupport