Top Description Inners Fields Constructors Methods
org.springframework.web.socket.sockjs.client

public Class WebSocketTransport

extends Object
implements Transport, Lifecycle
Class Inheritance
All Implemented Interfaces
org.springframework.context.Lifecycle, org.springframework.web.socket.sockjs.client.Transport
Imports
java.net.URI, java.util.Collections, .List, java.util.concurrent.CompletableFuture, java.util.concurrent.atomic.AtomicBoolean, org.apache.commons.logging.Log, .LogFactory, org.springframework.context.Lifecycle, org.springframework.util.Assert, org.springframework.web.socket.CloseStatus, .TextMessage, .WebSocketHandler, .WebSocketHttpHeaders, .WebSocketSession, org.springframework.web.socket.client.WebSocketClient, org.springframework.web.socket.handler.TextWebSocketHandler, org.springframework.web.socket.sockjs.transport.TransportType

A SockJS Transport that uses a WebSocketClient.
Author
Rossen Stoyanchev
Since
4.1

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final Log
private volatile boolean
private final WebSocketClient

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public CompletableFuture<WebSocketSession>
connectAsync(TransportRequest
the transport request
request
,
WebSocketHandler
the application handler to delegate lifecycle events to
handler
)

Implements org.springframework.web.socket.sockjs.client.Transport.connectAsync.

Connect the transport.

public List<TransportType>
getTransportTypes()

Implements org.springframework.web.socket.sockjs.client.Transport.getTransportTypes.

Get the SockJS transport types that this transport can be used for.

public WebSocketClient
getWebSocketClient()

Return the configured WebSocketClient.

public boolean
isRunning()

Implements org.springframework.context.Lifecycle.isRunning.

Check whether this component is currently running.

public void
start()

Implements org.springframework.context.Lifecycle.start.

Start this component.

public void
stop()

Implements org.springframework.context.Lifecycle.stop.

Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

loggerback to summary
private static final Log logger
runningback to summary
private volatile boolean running
webSocketClientback to summary
private final WebSocketClient webSocketClient

Constructor Detail

WebSocketTransportback to summary
public WebSocketTransport(WebSocketClient webSocketClient)

Method Detail

connectAsyncback to summary
public CompletableFuture<WebSocketSession> connectAsync(TransportRequest request, WebSocketHandler handler)

Implements org.springframework.web.socket.sockjs.client.Transport.connectAsync.

Doc from org.springframework.web.socket.sockjs.client.Transport.connectAsync.

Connect the transport.

Parameters
request:TransportRequest

the transport request

handler:WebSocketHandler

the application handler to delegate lifecycle events to

Returns:CompletableFuture<WebSocketSession>

a future to indicate success or failure to connect

Annotations
@Override
getTransportTypesback to summary
public List<TransportType> getTransportTypes()

Implements org.springframework.web.socket.sockjs.client.Transport.getTransportTypes.

Doc from org.springframework.web.socket.sockjs.client.Transport.getTransportTypes.

Get the SockJS transport types that this transport can be used for.

In particular since from a client perspective there is no difference between XHR and XHR streaming, an XhrTransport could do both.

Annotations
@Override
getWebSocketClientback to summary
public WebSocketClient getWebSocketClient()

Return the configured WebSocketClient.

isRunningback to summary
public boolean isRunning()

Implements org.springframework.context.Lifecycle.isRunning.

Doc from org.springframework.context.Lifecycle.isRunning.

Check whether this component is currently running.

In the case of a container, this will return true only if all components that apply are currently running.

Returns:boolean

whether the component is currently running

Annotations
@Override
startback to summary
public void start()

Implements org.springframework.context.Lifecycle.start.

Doc from org.springframework.context.Lifecycle.start.

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.

Annotations
@Override
stopback to summary
public void stop()

Implements org.springframework.context.Lifecycle.stop.

Doc from org.springframework.context.Lifecycle.stop.

Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method. Consider implementing SmartLifecycle and its stop(Runnable) variant when asynchronous stop behavior is necessary.

Note that this stop notification is not guaranteed to come before destruction: On regular shutdown, Lifecycle beans will first receive a stop notification before the general destruction callbacks are being propagated; however, on hot refresh during a context's lifetime or on aborted refresh attempts, a given bean's destroy method will be called without any consideration of stop signals upfront.

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.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
org.springframework.web.socket.sockjs.client back to summary

private Class WebSocketTransport.ClientSockJsWebSocketHandler

extends TextWebSocketHandler
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final AtomicBoolean
private final WebSocketClientSockJsSession

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
afterConnectionClosed(WebSocketSession webSocketSession, CloseStatus status)

Overrides org.springframework.web.socket.handler.AbstractWebSocketHandler.afterConnectionClosed.

Implements org.springframework.web.socket.WebSocketHandler.afterConnectionClosed.

Invoked after the WebSocket connection has been closed by either side, or after a transport error has occurred.

public void
afterConnectionEstablished(WebSocketSession webSocketSession)

Overrides org.springframework.web.socket.handler.AbstractWebSocketHandler.afterConnectionEstablished.

Implements org.springframework.web.socket.WebSocketHandler.afterConnectionEstablished.

Invoked after WebSocket negotiation has succeeded and the WebSocket connection is opened and ready for use.

public void
public void
Inherited from org.springframework.web.socket.handler.TextWebSocketHandler:
handleBinaryMessage

Field Detail

connectedback to summary
private final AtomicBoolean connected
sockJsSessionback to summary
private final WebSocketClientSockJsSession sockJsSession

Constructor Detail

ClientSockJsWebSocketHandlerback to summary
public ClientSockJsWebSocketHandler(WebSocketClientSockJsSession session)

Method Detail

afterConnectionClosedback to summary
public void afterConnectionClosed(WebSocketSession webSocketSession, CloseStatus status) throws Exception

Overrides org.springframework.web.socket.handler.AbstractWebSocketHandler.afterConnectionClosed.

Implements org.springframework.web.socket.WebSocketHandler.afterConnectionClosed.

Doc from org.springframework.web.socket.WebSocketHandler.afterConnectionClosed.

Invoked after the WebSocket connection has been closed by either side, or after a transport error has occurred. Although the session may technically still be open, depending on the underlying implementation, sending messages at this point is discouraged and most likely will not succeed.

Annotations
@Override
Exceptions
Exception:
this method can handle or propagate exceptions; see class-level Javadoc for details.
afterConnectionEstablishedback to summary
public void afterConnectionEstablished(WebSocketSession webSocketSession) throws Exception

Overrides org.springframework.web.socket.handler.AbstractWebSocketHandler.afterConnectionEstablished.

Implements org.springframework.web.socket.WebSocketHandler.afterConnectionEstablished.

Doc from org.springframework.web.socket.WebSocketHandler.afterConnectionEstablished.

Invoked after WebSocket negotiation has succeeded and the WebSocket connection is opened and ready for use.

Annotations
@Override
Exceptions
Exception:
this method can handle or propagate exceptions; see class-level Javadoc for details.
handleTextMessageback to summary
public void handleTextMessage(WebSocketSession webSocketSession, TextMessage message) throws Exception

Overrides org.springframework.web.socket.handler.AbstractWebSocketHandler.handleTextMessage.

Annotations
@Override
handleTransportErrorback to summary
public void handleTransportError(WebSocketSession webSocketSession, Throwable ex) throws Exception

Overrides org.springframework.web.socket.handler.AbstractWebSocketHandler.handleTransportError.

Implements org.springframework.web.socket.WebSocketHandler.handleTransportError.

Doc from org.springframework.web.socket.WebSocketHandler.handleTransportError.

Handle an error from the underlying WebSocket message transport.

Annotations
@Override
Exceptions
Exception:
this method can handle or propagate exceptions; see class-level Javadoc for details.