WebSocketClient
with fallback alternatives that simulate a WebSocket interaction through plain
HTTP streaming and long polling techniques.
Implements Lifecycle in order to propagate lifecycle events to
the transports it is configured with.
org.springframework.web.socket.sockjs.client.Transport
| Modifier and Type | Class and Description |
|---|---|
| private static class | SockJsClient.
A simple value object holding the result from a SockJS "Info" request. |
| Modifier and Type | Field and Description |
|---|---|
| private TaskScheduler | |
| private String[] | |
| private InfoReceiver | |
| private static final boolean | |
| private static final Log | |
| private SockJsMessageCodec | |
| private volatile boolean | |
| private final Map | |
| private static final Set | |
| private final List |
| Access | Constructor and Description |
|---|---|
| public | SockJsClient(List<Transport>
the (non-empty) list of transports to use transports)Create a |
| Modifier and Type | Method and Description |
|---|---|
| protected SockJsUrlInfo | buildSockJsUrlInfo(URI
the target URL url)Create a new |
| public void | clearServerInfoCache()
By default, the result of a SockJS "Info" request, including whether the server has WebSocket disabled and how long the request took (used for calculating transport timeout time) is cached. |
| private DefaultTransportRequest | |
| public CompletableFuture | execute(WebSocketHandler
the session handler handler, String the url template uriTemplate, Object... the variables to expand the template uriVars)Implements org. Execute a handshake request to the given url and handle the resulting WebSocket session with the given handler. |
| public final CompletableFuture | execute(WebSocketHandler
the session handler handler, WebSocketHttpHeaders headers, URI the url url)Implements org. Execute a handshake request to the given url and handle the resulting WebSocket session with the given handler. |
| public String[] | getHttpHeaderNames()
The configured HTTP header names to be copied from the handshake headers and also included in other HTTP requests. |
| private HttpHeaders | |
| public InfoReceiver | |
| public SockJsMessageCodec | |
| private SockJsClient. | |
| protected Principal | Returns: the user to associate with the session (possiblynull)Return the user to associate with the SockJS session and make available via
|
| private static InfoReceiver | |
| public boolean | isRunning()
Implements org. Check whether this component is currently running. |
| public void | setConnectTimeoutScheduler(TaskScheduler
the task scheduler to use connectTimeoutScheduler)Configure a |
| public void | setHttpHeaderNames(String...
the HTTP header names httpHeaderNames)The names of HTTP headers that should be copied from the handshake headers
of each call to |
| public void | setInfoReceiver(InfoReceiver
the transport to use for the SockJS "Info" request infoReceiver)Configure the |
| public void | |
| public void | |
| public void | stop()
Implements org. Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method. |
| connectTimeoutScheduler | back to summary |
|---|---|
| private TaskScheduler connectTimeoutScheduler
| |
| httpHeaderNames | back to summary |
|---|---|
| private String[] httpHeaderNames
| |
| infoReceiver | back to summary |
|---|---|
| private InfoReceiver infoReceiver | |
| jackson2Present | back to summary |
|---|---|
| private static final boolean jackson2Present | |
| logger | back to summary |
|---|---|
| private static final Log logger | |
| messageCodec | back to summary |
|---|---|
| private SockJsMessageCodec messageCodec
| |
| running | back to summary |
|---|---|
| private volatile boolean running | |
| serverInfoCache | back to summary |
|---|---|
| private final Map<URI, SockJsClient. | |
| supportedProtocols | back to summary |
|---|---|
| private static final Set<String> supportedProtocols | |
| transports | back to summary |
|---|---|
| private final List<Transport> transports | |
| SockJsClient | back to summary |
|---|---|
| public SockJsClient(List<Transport> transports) Create a If the list includes an | |
| buildSockJsUrlInfo | back to summary |
|---|---|
| protected SockJsUrlInfo buildSockJsUrlInfo(URI url) Create a new The default implementation builds a
| |
| clearServerInfoCache | back to summary |
|---|---|
| public void clearServerInfoCache() By default, the result of a SockJS "Info" request, including whether the server has WebSocket disabled and how long the request took (used for calculating transport timeout time) is cached. This method can be used to clear that cache hence causing it to re-populate. | |
| createRequest | back to summary |
|---|---|
| private DefaultTransportRequest createRequest(SockJsUrlInfo urlInfo, HttpHeaders headers, SockJsClient. | |
| execute | back to summary |
|---|---|
| public CompletableFuture Implements org. Doc from org. Execute a handshake request to the given url and handle the resulting WebSocket session with the given handler.
| |
| execute | back to summary |
|---|---|
| public final CompletableFuture Implements org. Doc from org. Execute a handshake request to the given url and handle the resulting WebSocket session with the given handler.
| |
| getHttpHeaderNames | back to summary |
|---|---|
| public String[] getHttpHeaderNames() The configured HTTP header names to be copied from the handshake headers and also included in other HTTP requests.
| |
| getHttpRequestHeaders | back to summary |
|---|---|
private HttpHeaders getHttpRequestHeaders(HttpHeaders webSocketHttpHeaders)
| |
| getInfoReceiver | back to summary |
|---|---|
| public InfoReceiver getInfoReceiver() Return the configured | |
| getMessageCodec | back to summary |
|---|---|
| public SockJsMessageCodec getMessageCodec() Return the SockJsMessageCodec to use. | |
| getServerInfo | back to summary |
|---|---|
| private SockJsClient. | |
| getUser | back to summary |
|---|---|
| protected Principal getUser() Return the user to associate with the SockJS session and make available via
By default this method returns | |
| initInfoReceiver | back to summary |
|---|---|
| private static InfoReceiver initInfoReceiver(List<Transport> transports) | |
| isRunning | back to summary |
|---|---|
| public boolean isRunning() Implements org. Doc from org. Check whether this component is currently running. In the case of a container, this will return
| |
| setConnectTimeoutScheduler | back to summary |
|---|---|
| public void setConnectTimeoutScheduler(TaskScheduler connectTimeoutScheduler) Configure a By default this is not configured in which case a fallback may take longer.
| |
| setHttpHeaderNames | back to summary |
|---|---|
| public void setHttpHeaderNames(String... httpHeaderNames) The names of HTTP headers that should be copied from the handshake headers
of each call to By default if this property is not set, all handshake headers are also used for other HTTP requests. Set it if you want only a subset of handshake headers (e.g. auth headers) to be used for other HTTP requests.
| |
| setInfoReceiver | back to summary |
|---|---|
| public void setInfoReceiver(InfoReceiver infoReceiver) Configure the If the list of transports provided to the constructor contained an
| |
| setMessageCodec | back to summary |
|---|---|
| public void setMessageCodec(SockJsMessageCodec messageCodec) Set the SockJsMessageCodec to use. By default | |
| start | back to summary |
|---|---|
| public void start() Implements org. Doc from org. Start this component. Should not throw an exception if the component is already running. In the case of a container, this will propagate the start signal to all components that apply.
| |
| stop | back to summary |
|---|---|
| public void stop() Implements org. Doc from org. Stop this component, typically in a synchronous fashion, such that the component is
fully stopped upon return of this method. Consider implementing Note that this stop notification is not guaranteed to come before destruction:
On regular shutdown, Should not throw an exception if the component is not running (not started yet). In the case of a container, this will propagate the stop signal to all components that apply.
| |
| Modifier and Type | Field and Description |
|---|---|
| private final long | |
| private final boolean |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public long | |
| public boolean |
| responseTime | back to summary |
|---|---|
| private final long responseTime | |
| webSocketEnabled | back to summary |
|---|---|
| private final boolean webSocketEnabled | |
| ServerInfo | back to summary |
|---|---|
| public ServerInfo(String response, long responseTime) | |
| getRetransmissionTimeout | back to summary |
|---|---|
| public long getRetransmissionTimeout() | |
| isWebSocketEnabled | back to summary |
|---|---|
| public boolean isWebSocketEnabled() | |