org.springframework.web.socket.sockjs.client

## Class AbstractXhrTransport

- java.lang.Object
- - org.springframework.web.socket.sockjs.client.AbstractXhrTransport

All Implemented Interfaces:
  InfoReceiver, Transport, XhrTransport

Direct Known Subclasses:
  JettyXhrTransport, RestTemplateXhrTransport, UndertowXhrTransport

    public abstract class AbstractXhrTransport
    extends Object
    implements XhrTransport

Abstract base class for XHR transport implementations to extend.

Since:
  4.1
Author:
  Rossen Stoyanchev

### Field Summary

Fields
`protected Log` `logger`
`protected static String` `PRELUDE`

### Constructor Summary

Constructors
Constructor and Description
`AbstractXhrTransport()`

### Method Summary

All Methods Instance Methods Abstract Methods Concrete Methods
`org.springframework.util.concurrent.ListenableFuture<WebSocketSession>` `connect(TransportRequest request, WebSocketHandler handler)` Connect the transport.
`protected abstract void` `connectInternal(TransportRequest request, WebSocketHandler handler, URI receiveUrl, org.springframework.http.HttpHeaders handshakeHeaders, XhrClientSockJsSession session, org.springframework.util.concurrent.SettableListenableFuture<WebSocketSession> connectFuture)`
`String` `executeInfoRequest(URI infoUrl, org.springframework.http.HttpHeaders headers)` Perform an HTTP request to the SockJS "Info" URL.
`protected abstract org.springframework.http.ResponseEntity<String>` `executeInfoRequestInternal(URI infoUrl, org.springframework.http.HttpHeaders headers)`
`void` `executeSendRequest(URI url, org.springframework.http.HttpHeaders headers, TextMessage message)` Execute a request to send the message to the server.
`protected abstract org.springframework.http.ResponseEntity<String>` `executeSendRequestInternal(URI url, org.springframework.http.HttpHeaders headers, TextMessage message)`
`List<TransportType>` `getTransportTypes()` Return the SockJS transport types that this transport can be used for.
`boolean` `isXhrStreamingDisabled()` Whether XHR streaming is disabled or not.
`void` `setXhrStreamingDisabled(boolean disabled)` An `XhrTransport` can support both the "xhr_streaming" and "xhr" SockJS server transports.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### PRELUDE

    protected static final String PRELUDE

#### logger

    protected final Log logger

### Constructor Detail

#### AbstractXhrTransport

    public AbstractXhrTransport()

### Method Detail

#### getTransportTypes

    public List<TransportType> getTransportTypes()

Description copied from interface: `Transport`
Return 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.

Specified by:
  `getTransportTypes` in interface `Transport`

#### setXhrStreamingDisabled

    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.

#### isXhrStreamingDisabled

    public boolean isXhrStreamingDisabled()

Whether XHR streaming is disabled or not.

Specified by:
  `isXhrStreamingDisabled` in interface `XhrTransport`

#### connect

    public org.springframework.util.concurrent.ListenableFuture<WebSocketSession> connect(TransportRequest request,
                                                                                          WebSocketHandler handler)

Description copied from interface: `Transport`
Connect the transport.

Specified by:
  `connect` in interface `Transport`
Parameters:
  `request` - the transport request.
  `handler` - the application handler to delegate lifecycle events to.
Returns:
  a future to indicate success or failure to connect.

#### connectInternal

    protected abstract void connectInternal(TransportRequest request,
                                            WebSocketHandler handler,
                                            URI receiveUrl,
                                            org.springframework.http.HttpHeaders handshakeHeaders,
                                            XhrClientSockJsSession session,
                                            org.springframework.util.concurrent.SettableListenableFuture<WebSocketSession> connectFuture)

#### executeInfoRequest

    public String executeInfoRequest(URI infoUrl,
                                     @Nullable
                                     org.springframework.http.HttpHeaders headers)

Description copied from interface: `InfoReceiver`
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.

Specified by:
  `executeInfoRequest` in interface `InfoReceiver`
Parameters:
  `infoUrl` - the URL to obtain SockJS server information from
  `headers` - the headers to use for the request
Returns:
  the body of the response

#### executeInfoRequestInternal

    protected abstract org.springframework.http.ResponseEntity<String> executeInfoRequestInternal(URI infoUrl,
                                                                                                  org.springframework.http.HttpHeaders headers)

#### executeSendRequest

    public void executeSendRequest(URI url,
                                   org.springframework.http.HttpHeaders headers,
                                   TextMessage message)

Description copied from interface: `XhrTransport`
Execute a request to send the message to the server.

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

Specified by:
  `executeSendRequest` in interface `XhrTransport`
Parameters:
  `url` - the URL for sending messages.
  `message` - the message to send

#### executeSendRequestInternal

    protected abstract org.springframework.http.ResponseEntity<String> executeSendRequestInternal(URI url,
                                                                                                  org.springframework.http.HttpHeaders headers,
                                                                                                  TextMessage message)