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

public abstract Class AbstractXhrTransport

extends Object
implements XhrTransport
Class Inheritance
All Implemented Interfaces
org.springframework.web.socket.sockjs.client.XhrTransport, org.springframework.web.socket.sockjs.client.InfoReceiver, org.springframework.web.socket.sockjs.client.Transport
Known Direct Subclasses
org.springframework.web.socket.sockjs.client.JettyXhrTransport, org.springframework.web.socket.sockjs.client.RestTemplateXhrTransport, org.springframework.web.socket.sockjs.client.UndertowXhrTransport
Imports
java.net.URI, java.util.Arrays, .Collections, .List, java.util.concurrent.CompletableFuture, org.apache.commons.logging.Log, .LogFactory, org.springframework.http.HttpHeaders, .HttpStatus, .ResponseEntity, org.springframework.lang.Nullable, org.springframework.web.client.HttpServerErrorException, org.springframework.web.socket.TextMessage, .WebSocketHandler, .WebSocketSession, org.springframework.web.socket.sockjs.frame.SockJsFrame, org.springframework.web.socket.sockjs.transport.TransportType

Abstract base class for XHR transport implementations to extend.
Author
Rossen Stoyanchev
Since
4.1

Field Summary

Modifier and TypeField and Description
protected final Log
protected static final String
private boolean

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.

protected void
connectInternal(TransportRequest request, WebSocketHandler handler, URI receiveUrl, HttpHeaders handshakeHeaders, XhrClientSockJsSession session, SettableListenableFuture<WebSocketSession> connectFuture)
Deprecated

protected abstract void
connectInternal(TransportRequest request, WebSocketHandler handler, URI receiveUrl, HttpHeaders handshakeHeaders, XhrClientSockJsSession session, CompletableFuture<WebSocketSession> connectFuture)

public String
executeInfoRequest(URI
the URL to obtain SockJS server information from
infoUrl
,
HttpHeaders
the headers to use for the request
headers
)

Implements org.springframework.web.socket.sockjs.client.InfoReceiver.executeInfoRequest.

Perform an HTTP request to the SockJS "Info" URL.

protected abstract ResponseEntity<String>
public void
executeSendRequest(URI
the URL for sending messages.
url
,
HttpHeaders headers, TextMessage
the message to send
message
)

Implements org.springframework.web.socket.sockjs.client.XhrTransport.executeSendRequest.

Execute a request to send the message to the server.

protected abstract ResponseEntity<String>
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 boolean
public void
setXhrStreamingDisabled(boolean disabled)

An XhrTransport can support both the "xhr_streaming" and "xhr" SockJS server transports.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

loggerback to summary
protected final Log logger
PRELUDEback to summary
protected static final String PRELUDE
xhrStreamingDisabledback to summary
private boolean xhrStreamingDisabled

Constructor Detail

AbstractXhrTransportback to summary
public AbstractXhrTransport()

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
connectInternalback to summary
protected void connectInternal(TransportRequest request, WebSocketHandler handler, URI receiveUrl, HttpHeaders handshakeHeaders, XhrClientSockJsSession session, SettableListenableFuture<WebSocketSession> connectFuture)

Deprecated

Annotations
@Deprecated
connectInternalback to summary
protected abstract void connectInternal(TransportRequest request, WebSocketHandler handler, URI receiveUrl, HttpHeaders handshakeHeaders, XhrClientSockJsSession session, CompletableFuture<WebSocketSession> connectFuture)
executeInfoRequestback to summary
public String executeInfoRequest(URI infoUrl, HttpHeaders headers)

Implements org.springframework.web.socket.sockjs.client.InfoReceiver.executeInfoRequest.

Doc from org.springframework.web.socket.sockjs.client.InfoReceiver.executeInfoRequest.

Perform an HTTP request to the SockJS "Info" URL. and return the resulting JSON response content, or raise an exception.

Note that as of 4.2 this method accepts a headers parameter.

Parameters
infoUrl:URI

the URL to obtain SockJS server information from

headers:HttpHeaders

the headers to use for the request

Returns:String

the body of the response

Annotations
@Override
executeInfoRequestInternalback to summary
protected abstract ResponseEntity<String> executeInfoRequestInternal(URI infoUrl, HttpHeaders headers)
executeSendRequestback to summary
public void executeSendRequest(URI url, HttpHeaders headers, TextMessage message)

Implements org.springframework.web.socket.sockjs.client.XhrTransport.executeSendRequest.

Doc from org.springframework.web.socket.sockjs.client.XhrTransport.executeSendRequest.

Execute a request to send the message to the server.

Note that as of 4.2 this method accepts a headers parameter.

Parameters
url:URI

the URL for sending messages.

message:TextMessage

the message to send

Annotations
@Override
executeSendRequestInternalback to summary
protected abstract ResponseEntity<String> executeSendRequestInternal(URI url, HttpHeaders headers, TextMessage message)
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
isXhrStreamingDisabledback to summary
public boolean isXhrStreamingDisabled()

Implements org.springframework.web.socket.sockjs.client.XhrTransport.isXhrStreamingDisabled.

Whether XHR streaming is disabled or not.

Annotations
@Override
setXhrStreamingDisabledback to summary
public void setXhrStreamingDisabled(boolean disabled)

An XhrTransport can support both the "xhr_streaming" and "xhr" SockJS server transports. From a client perspective there is no implementation difference.

Typically an XhrTransport is used as "XHR streaming" first and then, if that fails, as "XHR". In some cases however it may be helpful to suppress XHR streaming so that only XHR is attempted.

By default this property is set to false which means both "XHR streaming" and "XHR" apply.