Class AbstractStreamingClientHttpRequest
java.lang.Object
org.springframework.http.client.AbstractClientHttpRequest
org.springframework.http.client.AbstractStreamingClientHttpRequest
- All Implemented Interfaces:
ClientHttpRequest, HttpMessage, HttpOutputMessage, HttpRequest, StreamingHttpOutputMessage
public abstract class AbstractStreamingClientHttpRequest
extends AbstractClientHttpRequest
implements StreamingHttpOutputMessage
Extension of
AbstractClientHttpRequest that adds the ability to stream
request body content directly to the underlying HTTP client library through
the StreamingHttpOutputMessage contract.
It is necessary to call setBody(StreamingHttpOutputMessage.Body) and stream the request body through
a callback for access to the OutputStream. The alternative to call
AbstractClientHttpRequest.getBody() is also supported as a fallback, but that does not stream,
and returns an aggregating OutputStream instead.
- Since:
- 6.1
- Author:
- Arjen Poutsma, Rossen Stoyanchev
-
Nested Class Summary
Nested classes/interfaces inherited from interface StreamingHttpOutputMessage
StreamingHttpOutputMessage.Body -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final ClientHttpResponseexecuteInternal(HttpHeaders headers) Abstract template method that writes the given headers and content to the HTTP request.protected abstract ClientHttpResponseexecuteInternal(HttpHeaders headers, @Nullable StreamingHttpOutputMessage.Body body) Abstract method for concrete implementations to write the headers andStreamingHttpOutputMessage.Bodyto the HTTP request.protected final OutputStreamgetBodyInternal(HttpHeaders headers) Implements theHttpOutputMessagecontract for request body content.final voidImplements theStreamingHttpOutputMessagecontract for writing request body by streaming directly to the underlying HTTP client.Methods inherited from class AbstractClientHttpRequest
assertNotExecuted, execute, getAttributes, getBody, getHeadersMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface HttpMessage
getHeadersMethods inherited from interface HttpOutputMessage
getBodyMethods inherited from interface HttpRequest
getMethod, getURIMethods inherited from interface StreamingHttpOutputMessage
setBody
-
Constructor Details
-
AbstractStreamingClientHttpRequest
public AbstractStreamingClientHttpRequest()
-
-
Method Details
-
getBodyInternal
Implements theHttpOutputMessagecontract for request body content.Note that this method does not result in streaming, and the returned
OutputStreamaggregates the full content in a byte[] before sending. To use streaming, callsetBody(StreamingHttpOutputMessage.Body)instead.- Specified by:
getBodyInternalin classAbstractClientHttpRequest- Parameters:
headers- the HTTP headers- Returns:
- the body output stream
-
setBody
Implements theStreamingHttpOutputMessagecontract for writing request body by streaming directly to the underlying HTTP client.- Specified by:
setBodyin interfaceStreamingHttpOutputMessage- Parameters:
body- the streaming body callback
-
executeInternal
Description copied from class:AbstractClientHttpRequestAbstract template method that writes the given headers and content to the HTTP request.- Specified by:
executeInternalin classAbstractClientHttpRequest- Parameters:
headers- the HTTP headers- Returns:
- the response object for the executed request
- Throws:
IOException
-
executeInternal
protected abstract ClientHttpResponse executeInternal(HttpHeaders headers, @Nullable StreamingHttpOutputMessage.Body body) throws IOException Abstract method for concrete implementations to write the headers andStreamingHttpOutputMessage.Bodyto the HTTP request.- Parameters:
headers- the HTTP headers for the requestbody- the HTTP body, may benullif no body was set- Returns:
- the response object for the executed request
- Throws:
IOException- Since:
- 6.1
-