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

public Class JettyXhrTransport

extends AbstractXhrTransport
implements Lifecycle
Class Inheritance
All Implemented Interfaces
org.springframework.context.Lifecycle
Imports
java.io.ByteArrayOutputStream, java.net.URI, java.nio.ByteBuffer, java.util.Enumeration, java.util.concurrent.CompletableFuture, org.eclipse.jetty.client.ContentResponse, .HttpClient, .Request, .Response, .StringRequestContent, org.eclipse.jetty.http.HttpFields, .HttpMethod, org.springframework.context.Lifecycle, org.springframework.http.HttpHeaders, .HttpStatusCode, .ResponseEntity, org.springframework.lang.Nullable, org.springframework.util.Assert, .StreamUtils, org.springframework.web.client.HttpServerErrorException, org.springframework.web.socket.CloseStatus, .TextMessage, .WebSocketHandler, .WebSocketSession, org.springframework.web.socket.sockjs.SockJsException, .SockJsTransportFailureException, org.springframework.web.socket.sockjs.frame.SockJsFrame

An XHR transport based on Jetty's org.eclipse.jetty.client.HttpClient.

When used for testing purposes (e.g. load testing) the HttpClient properties must be set to allow a larger than usual number of connections and threads. For example:

HttpClient httpClient = new HttpClient();
httpClient.setMaxConnectionsPerDestination(1000);
httpClient.setExecutor(new QueuedThreadPool(500));
Author
Rossen Stoyanchev
Since
4.1

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
JettyXhrTransport.SockJsResponseListener

Jetty client Response Listener that splits the body of the response into SockJS frames and delegates them to the XhrClientSockJsSession.

Field Summary

Modifier and TypeField and Description
private final HttpClient
Inherited from org.springframework.web.socket.sockjs.client.AbstractXhrTransport:
loggerPRELUDE

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static void
protected void
protected ResponseEntity<String>
private void
protected ResponseEntity<String>
executeRequest(URI url, HttpMethod method, HttpHeaders headers, String body)

public ResponseEntity<String>
public HttpClient
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.

private static HttpHeaders
Inherited from org.springframework.web.socket.sockjs.client.AbstractXhrTransport:
connectAsyncconnectInternalexecuteInfoRequestexecuteSendRequestgetTransportTypesisXhrStreamingDisabledsetXhrStreamingDisabled

Field Detail

httpClientback to summary
private final HttpClient httpClient

Constructor Detail

JettyXhrTransportback to summary
public JettyXhrTransport(HttpClient httpClient)

Method Detail

addHttpHeadersback to summary
private static void addHttpHeaders(Request request, HttpHeaders headers)
connectInternalback to summary
protected void connectInternal(TransportRequest transportRequest, WebSocketHandler handler, URI url, HttpHeaders handshakeHeaders, XhrClientSockJsSession session, CompletableFuture<WebSocketSession> connectFuture)

Implements abstract org.springframework.web.socket.sockjs.client.AbstractXhrTransport.connectInternal.

Annotations
@Override
executeInfoRequestInternalback to summary
protected ResponseEntity<String> executeInfoRequestInternal(URI infoUrl, HttpHeaders headers)

Implements abstract org.springframework.web.socket.sockjs.client.AbstractXhrTransport.executeInfoRequestInternal.

Annotations
@Override
executeReceiveRequestback to summary
private void executeReceiveRequest(URI url, HttpHeaders headers, JettyXhrTransport.SockJsResponseListener listener)
executeRequestback to summary
protected ResponseEntity<String> executeRequest(URI url, HttpMethod method, HttpHeaders headers, String body)
executeSendRequestInternalback to summary
public ResponseEntity<String> executeSendRequestInternal(URI url, HttpHeaders headers, TextMessage message)

Implements abstract org.springframework.web.socket.sockjs.client.AbstractXhrTransport.executeSendRequestInternal.

Annotations
@Override
getHttpClientback to summary
public HttpClient getHttpClient()
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
toHttpHeadersback to summary
private static HttpHeaders toHttpHeaders(HttpFields httpFields)
org.springframework.web.socket.sockjs.client back to summary

private Class JettyXhrTransport.SockJsResponseListener

extends Object
implements Listener
Class Inheritance
  • java.lang.Object
  • org.springframework.web.socket.sockjs.client.JettyXhrTransport.SockJsResponseListener
All Implemented Interfaces
org.eclipse.jetty.client.Response.Listener, org.eclipse.jetty.client.Response.CompleteListener, org.eclipse.jetty.client.Response.ResponseListener, java.util.EventListener, org.eclipse.jetty.client.Response.FailureListener, org.eclipse.jetty.client.Response.SuccessListener, org.eclipse.jetty.client.Response.ContentListener, org.eclipse.jetty.client.Response.AsyncContentListener, org.eclipse.jetty.client.Response.ContentSourceListener, org.eclipse.jetty.client.Response.HeadersListener, org.eclipse.jetty.client.Response.HeaderListener, org.eclipse.jetty.client.Response.BeginListener

Jetty client Response Listener that splits the body of the response into SockJS frames and delegates them to the XhrClientSockJsSession.

Field Summary

Modifier and TypeField and Description
private final CompletableFuture<WebSocketSession>
private final ByteArrayOutputStream
private final HttpHeaders
private final XhrClientSockJsSession
private final URI

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
public void
onBegin(Response
the response containing the response line data
response
)

Overrides default org.eclipse.jetty.client.Response.Listener.onBegin.

Callback method invoked when the response line containing HTTP version, HTTP status code and reason has been received and parsed.

public void
onContent(Response
the response containing the response line data and the headers
response
,
ByteBuffer
the content bytes received
buffer
)

Overrides default org.eclipse.jetty.client.Response.Listener.onContent.

Callback method invoked when the response content has been received, parsed and there is demand.

public void
onFailure(Response
the response containing data up to the point the failure happened
response
,
Throwable
the failure happened
failure
)

Overrides default org.eclipse.jetty.client.Response.Listener.onFailure.

Callback method invoked when the response has failed in the process of being received

public void
onHeaders(Response
the response containing the response line data and the headers
response
)

Overrides default org.eclipse.jetty.client.Response.Listener.onHeaders.

Callback method invoked when all the response headers have been received and parsed.

public void
onSuccess(Response
the response containing the response line data and the headers
response
)

Overrides default org.eclipse.jetty.client.Response.Listener.onSuccess.

Callback method invoked when the whole response has been successfully received.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

connectFutureback to summary
private final CompletableFuture<WebSocketSession> connectFuture
outputStreamback to summary
private final ByteArrayOutputStream outputStream
receiveHeadersback to summary
private final HttpHeaders receiveHeaders
sockJsSessionback to summary
private final XhrClientSockJsSession sockJsSession
transportUrlback to summary
private final URI transportUrl

Constructor Detail

SockJsResponseListenerback to summary
public SockJsResponseListener(URI url, HttpHeaders headers, XhrClientSockJsSession sockJsSession, CompletableFuture<WebSocketSession> connectFuture)

Method Detail

handleFrameback to summary
private void handleFrame()
onBeginback to summary
public void onBegin(Response response)

Overrides default org.eclipse.jetty.client.Response.Listener.onBegin.

Doc from org.eclipse.jetty.client.Response.BeginListener.onBegin.

Callback method invoked when the response line containing HTTP version, HTTP status code and reason has been received and parsed.

This method is the best approximation to detect when the first bytes of the response arrived to the client.

Parameters
response:Response

the response containing the response line data

Annotations
@Override
onContentback to summary
public void onContent(Response response, ByteBuffer buffer)

Overrides default org.eclipse.jetty.client.Response.Listener.onContent.

Doc from org.eclipse.jetty.client.Response.ContentListener.onContent.

Callback method invoked when the response content has been received, parsed and there is demand. This method may be invoked multiple times, and the content buffer must be consumed (or copied) before returning from this method.

Parameters
response:Response

the response containing the response line data and the headers

buffer:ByteBuffer

the content bytes received

Annotations
@Override
onFailureback to summary
public void onFailure(Response response, Throwable failure)

Overrides default org.eclipse.jetty.client.Response.Listener.onFailure.

Doc from org.eclipse.jetty.client.Response.FailureListener.onFailure.

Callback method invoked when the response has failed in the process of being received

Parameters
response:Response

the response containing data up to the point the failure happened

failure:Throwable

the failure happened

Annotations
@Override
onHeadersback to summary
public void onHeaders(Response response)

Overrides default org.eclipse.jetty.client.Response.Listener.onHeaders.

Doc from org.eclipse.jetty.client.Response.HeadersListener.onHeaders.

Callback method invoked when all the response headers have been received and parsed.

Parameters
response:Response

the response containing the response line data and the headers

Annotations
@Override
onSuccessback to summary
public void onSuccess(Response response)

Overrides default org.eclipse.jetty.client.Response.Listener.onSuccess.

Doc from org.eclipse.jetty.client.Response.SuccessListener.onSuccess.

Callback method invoked when the whole response has been successfully received.

Parameters
response:Response

the response containing the response line data and the headers

Annotations
@Override