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

public Class RestTemplateXhrTransport

extends AbstractXhrTransport
Class Inheritance
Imports
java.io.ByteArrayOutputStream, .IOException, .InputStream, java.net.URI, java.util.concurrent.CompletableFuture, org.springframework.core.task.SimpleAsyncTaskExecutor, .TaskExecutor, org.springframework.http.HttpHeaders, .HttpMethod, .HttpStatus, .HttpStatusCode, .ResponseEntity, .StreamingHttpOutputMessage, org.springframework.http.client.ClientHttpRequest, .ClientHttpResponse, org.springframework.lang.Nullable, org.springframework.util.Assert, .StreamUtils, org.springframework.web.client.HttpServerErrorException, .RequestCallback, .ResponseExtractor, .RestOperations, .RestTemplate, org.springframework.web.socket.CloseStatus, .TextMessage, .WebSocketHandler, .WebSocketSession, org.springframework.web.socket.sockjs.frame.SockJsFrame

An XhrTransport implementation that uses a RestTemplate.
Author
Rossen Stoyanchev
Since
4.1

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
RestTemplateXhrTransport.XhrReceiveExtractor

Splits the body of an HTTP response into SockJS frames and delegates those to an XhrClientSockJsSession.

private static class
RestTemplateXhrTransport.XhrRequestCallback

A RequestCallback to add the headers and (optionally) String content.

Field Summary

Modifier and TypeField and Description
private final RestOperations
private TaskExecutor
private static final ResponseExtractor<ResponseEntity<String>>
textResponseExtractor

A simple ResponseExtractor that reads the body into a String.

Inherited from org.springframework.web.socket.sockjs.client.AbstractXhrTransport:
loggerPRELUDE

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
protected void
connectInternal(final TransportRequest transportRequest, final WebSocketHandler handler, final URI receiveUrl, final HttpHeaders handshakeHeaders, final XhrClientSockJsSession session, final CompletableFuture<WebSocketSession> connectFuture)

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

protected ResponseEntity<String>
public ResponseEntity<String>
public RestOperations
getRestTemplate()

Return the configured RestTemplate.

public TaskExecutor
getTaskExecutor()

Return the configured TaskExecutor.

private static <T> T
nonNull(T result)

public void
setTaskExecutor(TaskExecutor taskExecutor)

Configure the TaskExecutor to use to execute XHR receive requests.

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

Field Detail

restTemplateback to summary
private final RestOperations restTemplate
taskExecutorback to summary
private TaskExecutor taskExecutor
textResponseExtractorback to summary
private static final ResponseExtractor<ResponseEntity<String>> textResponseExtractor

A simple ResponseExtractor that reads the body into a String.

Constructor Detail

RestTemplateXhrTransportback to summary
public RestTemplateXhrTransport()
RestTemplateXhrTransportback to summary
public RestTemplateXhrTransport(RestOperations restTemplate)

Method Detail

connectInternalback to summary
protected void connectInternal(final TransportRequest transportRequest, final WebSocketHandler handler, final URI receiveUrl, final HttpHeaders handshakeHeaders, final XhrClientSockJsSession session, final 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
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
getRestTemplateback to summary
public RestOperations getRestTemplate()

Return the configured RestTemplate.

getTaskExecutorback to summary
public TaskExecutor getTaskExecutor()

Return the configured TaskExecutor.

nonNullback to summary
private static <T> T nonNull(T result)
setTaskExecutorback to summary
public void setTaskExecutor(TaskExecutor taskExecutor)

Configure the TaskExecutor to use to execute XHR receive requests.

By default SimpleAsyncTaskExecutor is configured which creates a new thread every time the transports connects.

org.springframework.web.socket.sockjs.client back to summary

private Class RestTemplateXhrTransport.XhrReceiveExtractor

extends Object
implements ResponseExtractor<Object>
Class Inheritance
  • java.lang.Object
  • org.springframework.web.socket.sockjs.client.RestTemplateXhrTransport.XhrReceiveExtractor
All Implemented Interfaces
org.springframework.web.client.ResponseExtractor

Splits the body of an HTTP response into SockJS frames and delegates those to an XhrClientSockJsSession.

Field Summary

Modifier and TypeField and Description
private final XhrClientSockJsSession

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Object
extractData(ClientHttpResponse
the HTTP response
response
)

Implements org.springframework.web.client.ResponseExtractor.extractData.

Extract data from the given ClientHttpResponse and return it.

private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

sockJsSessionback to summary
private final XhrClientSockJsSession sockJsSession

Constructor Detail

XhrReceiveExtractorback to summary
public XhrReceiveExtractor(XhrClientSockJsSession sockJsSession)

Method Detail

extractDataback to summary
public Object extractData(ClientHttpResponse response) throws IOException

Implements org.springframework.web.client.ResponseExtractor.extractData.

Doc from org.springframework.web.client.ResponseExtractor.extractData.

Extract data from the given ClientHttpResponse and return it.

Parameters
response:ClientHttpResponse

the HTTP response

Returns:Object

the extracted data

Annotations
@Override
Exceptions
IOException:
in case of I/O errors
handleFrameback to summary
private void handleFrame(ByteArrayOutputStream os)
org.springframework.web.socket.sockjs.client back to summary

private Class RestTemplateXhrTransport.XhrRequestCallback

extends Object
implements RequestCallback
Class Inheritance
  • java.lang.Object
  • org.springframework.web.socket.sockjs.client.RestTemplateXhrTransport.XhrRequestCallback
All Implemented Interfaces
org.springframework.web.client.RequestCallback

A RequestCallback to add the headers and (optionally) String content.

Field Summary

Modifier and TypeField and Description
private final String
private final HttpHeaders

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
public void
doWithRequest(ClientHttpRequest
the active HTTP request
request
)

Implements org.springframework.web.client.RequestCallback.doWithRequest.

Gets called by RestTemplate#execute with an opened ClientHttpRequest.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bodyback to summary
private final String body
Annotations
@Nullable
headersback to summary
private final HttpHeaders headers

Constructor Detail

XhrRequestCallbackback to summary
public XhrRequestCallback(HttpHeaders headers)
XhrRequestCallbackback to summary
public XhrRequestCallback(HttpHeaders headers, String body)

Method Detail

doWithRequestback to summary
public void doWithRequest(ClientHttpRequest request) throws IOException

Implements org.springframework.web.client.RequestCallback.doWithRequest.

Doc from org.springframework.web.client.RequestCallback.doWithRequest.

Gets called by RestTemplate#execute with an opened ClientHttpRequest. Does not need to care about closing the request or about handling errors: this will all be handled by the RestTemplate.

Parameters
request:ClientHttpRequest

the active HTTP request

Annotations
@Override
Exceptions
IOException:
in case of I/O errors