Top Description Inners Fields Constructors Methods
org.springframework.http.client

pack-priv final Class HttpComponentsClientHttpRequest

extends AbstractStreamingClientHttpRequest
Class Inheritance
Imports
java.io.IOException, .InputStream, .OutputStream, java.net.URI, .URISyntaxException, java.util.List, .Set, org.apache.hc.client5.http.classic.HttpClient, org.apache.hc.core5.function.Supplier, org.apache.hc.core5.http.ClassicHttpRequest, .ClassicHttpResponse, .Header, .HttpEntity, org.apache.hc.core5.http.protocol.HttpContext, org.springframework.http.HttpHeaders, .HttpMethod, org.springframework.lang.Nullable, org.springframework.util.StringUtils

ClientHttpRequest implementation based on Apache HttpComponents HttpClient.

Created via the HttpComponentsClientHttpRequestFactory.

Authors
Oleg Kalnichevski, Arjen Poutsma, Juergen Hoeller
Since
3.1
See Also
HttpComponentsClientHttpRequestFactory#createRequest(URI, HttpMethod)

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final HttpClient
private final HttpContext
private final ClassicHttpRequest

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv static void
addHeaders(ClassicHttpRequest
the request to add the headers to
httpRequest
,
HttpHeaders
the headers to add
headers
)

Add the given headers to the given HTTP request.

protected ClientHttpResponse
executeInternal(HttpHeaders
the HTTP headers
headers
,
StreamingHttpOutputMessage.Body
the HTTP body, may be null if no body was set
body
)

Implements abstract org.springframework.http.client.AbstractStreamingClientHttpRequest.executeInternal.

Abstract template method that writes the given headers and content to the HTTP request.
pack-priv HttpContext
public HttpMethod
getMethod()

Implements org.springframework.http.HttpRequest.getMethod.

Return the HTTP method of the request.
public URI
getURI()

Implements org.springframework.http.HttpRequest.getURI.

Return the URI of the request (including a query string if any, but only if it is well-formed for a URI representation).
Inherited from org.springframework.http.client.AbstractStreamingClientHttpRequest:
executeInternalgetBodyInternalsetBody

Field Detail

httpClientback to summary
private final HttpClient httpClient
httpContextback to summary
private final HttpContext httpContext
httpRequestback to summary
private final ClassicHttpRequest httpRequest

Constructor Detail

HttpComponentsClientHttpRequestback to summary
pack-priv HttpComponentsClientHttpRequest(HttpClient client, ClassicHttpRequest request, HttpContext context)

Method Detail

addHeadersback to summary
pack-priv static void addHeaders(ClassicHttpRequest httpRequest, HttpHeaders headers)

Add the given headers to the given HTTP request.

Parameters
httpRequest:ClassicHttpRequest

the request to add the headers to

headers:HttpHeaders

the headers to add

executeInternalback to summary
protected ClientHttpResponse executeInternal(HttpHeaders headers, StreamingHttpOutputMessage.Body body) throws IOException

Implements abstract org.springframework.http.client.AbstractStreamingClientHttpRequest.executeInternal.

Doc from org.springframework.http.client.AbstractStreamingClientHttpRequest.executeInternal.

Abstract template method that writes the given headers and content to the HTTP request.

Parameters
headers:HttpHeaders

the HTTP headers

body:StreamingHttpOutputMessage.Body

the HTTP body, may be null if no body was set

Returns:ClientHttpResponse

the response object for the executed request

Annotations
@Override
getHttpContextback to summary
pack-priv HttpContext getHttpContext()
getMethodback to summary
public HttpMethod getMethod()

Implements org.springframework.http.HttpRequest.getMethod.

Doc from org.springframework.http.HttpRequest.getMethod.

Return the HTTP method of the request.

Returns:HttpMethod

the HTTP method as an HttpMethod value

Annotations
@Override
getURIback to summary
public URI getURI()

Implements org.springframework.http.HttpRequest.getURI.

Doc from org.springframework.http.HttpRequest.getURI.

Return the URI of the request (including a query string if any, but only if it is well-formed for a URI representation).

Returns:URI

the URI of the request (never null)

Annotations
@Override
org.springframework.http.client back to summary

private Class HttpComponentsClientHttpRequest.BodyEntity

extends Object
implements HttpEntity
Class Inheritance
  • java.lang.Object
  • org.springframework.http.client.HttpComponentsClientHttpRequest.BodyEntity
All Implemented Interfaces
org.apache.hc.core5.http.HttpEntity, java.io.Closeable, java.lang.AutoCloseable, org.apache.hc.core5.http.EntityDetails

Field Summary

Modifier and TypeField and Description
private final StreamingHttpOutputMessage.Body
private final HttpHeaders

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.
public InputStream
getContent()

Implements org.apache.hc.core5.http.HttpEntity.getContent.

Returns a content stream of the entity.
public String
getContentEncoding()

Implements org.apache.hc.core5.http.EntityDetails.getContentEncoding.

Returns content encoding of the entity, if known.
public long
getContentLength()

Implements org.apache.hc.core5.http.EntityDetails.getContentLength.

Returns length of the entity, if known.
public String
getContentType()

Implements org.apache.hc.core5.http.EntityDetails.getContentType.

Returns content type of the entity, if known.
public Set<String>
getTrailerNames()

Implements org.apache.hc.core5.http.EntityDetails.getTrailerNames.

Preliminary declaration of trailing headers.
public Supplier<List<? extends Header>>
getTrailers()

Implements org.apache.hc.core5.http.HttpEntity.getTrailers.

Returns supplier of message trailers - headers sent after message body.
public boolean
isChunked()

Implements org.apache.hc.core5.http.EntityDetails.isChunked.

Returns chunked transfer hint for this entity.
public boolean
isRepeatable()

Implements org.apache.hc.core5.http.HttpEntity.isRepeatable.

Tells if the entity is capable of producing its data more than once.
public boolean
isStreaming()

Implements org.apache.hc.core5.http.HttpEntity.isStreaming.

Tells whether this entity depends on an underlying stream.
public void
writeTo(OutputStream
the output stream to write entity content to
outStream
)

Implements org.apache.hc.core5.http.HttpEntity.writeTo.

Writes the entity content out to the output stream.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bodyback to summary
private final StreamingHttpOutputMessage.Body body
headersback to summary
private final HttpHeaders headers

Constructor Detail

BodyEntityback to summary
public BodyEntity(HttpHeaders headers, StreamingHttpOutputMessage.Body body)

Method Detail

closeback to summary
public void close()

Implements java.io.Closeable.close.

Doc from java.io.Closeable.close.

Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

As noted in AutoCloseable#close(), cases where the close may fail require careful attention. It is strongly advised to relinquish the underlying resources and to internally mark the Closeable as closed, prior to throwing the IOException.

Annotations
@Override
getContentback to summary
public InputStream getContent()

Implements org.apache.hc.core5.http.HttpEntity.getContent.

Doc from org.apache.hc.core5.http.HttpEntity.getContent.

Returns a content stream of the entity. Repeatable entities are expected to create a new instance of InputStream for each invocation of this method and therefore can be consumed multiple times. Entities that are not repeatable are expected to return the same InputStream instance and therefore may not be consumed more than once.

If this entity belongs to an incoming HTTP message, calling InputStream#close() on the returned InputStream will try to consume the complete entity content to keep the connection alive. In cases where this is undesired, e.g. when only a small part of the content is relevant and consuming the complete entity content would be too inefficient, only the HTTP message from which this entity was obtained should be closed (if supported).

Important Note

Please note all entity implementations must ensure that all allocated resources are properly deallocated after the InputStream#close() method is invoked.

Returns:InputStream

content stream of the entity.

Annotations
@Override
getContentEncodingback to summary
public String getContentEncoding()

Implements org.apache.hc.core5.http.EntityDetails.getContentEncoding.

Doc from org.apache.hc.core5.http.EntityDetails.getContentEncoding.

Returns content encoding of the entity, if known.

Annotations
@Override
@Nullable
getContentLengthback to summary
public long getContentLength()

Implements org.apache.hc.core5.http.EntityDetails.getContentLength.

Doc from org.apache.hc.core5.http.EntityDetails.getContentLength.

Returns length of the entity, if known.

Annotations
@Override
getContentTypeback to summary
public String getContentType()

Implements org.apache.hc.core5.http.EntityDetails.getContentType.

Doc from org.apache.hc.core5.http.EntityDetails.getContentType.

Returns content type of the entity, if known.

Annotations
@Override
@Nullable
getTrailerNamesback to summary
public Set<String> getTrailerNames()

Implements org.apache.hc.core5.http.EntityDetails.getTrailerNames.

Doc from org.apache.hc.core5.http.EntityDetails.getTrailerNames.

Preliminary declaration of trailing headers.

Annotations
@Override
@Nullable
getTrailersback to summary
public Supplier<List<? extends Header>> getTrailers()

Implements org.apache.hc.core5.http.HttpEntity.getTrailers.

Doc from org.apache.hc.core5.http.HttpEntity.getTrailers.

Returns supplier of message trailers - headers sent after message body. May return null if trailers are not available.

Annotations
@Override
@Nullable
isChunkedback to summary
public boolean isChunked()

Implements org.apache.hc.core5.http.EntityDetails.isChunked.

Doc from org.apache.hc.core5.http.EntityDetails.isChunked.

Returns chunked transfer hint for this entity.

The behavior of wrapping entities is implementation dependent, but should respect the primary purpose.

Annotations
@Override
isRepeatableback to summary
public boolean isRepeatable()

Implements org.apache.hc.core5.http.HttpEntity.isRepeatable.

Doc from org.apache.hc.core5.http.HttpEntity.isRepeatable.

Tells if the entity is capable of producing its data more than once. A repeatable entity's getContent() and writeTo(OutputStream) methods can be called more than once whereas a non-repeatable entity's can not.

Returns:boolean

true if the entity is repeatable, false otherwise.

Annotations
@Override
isStreamingback to summary
public boolean isStreaming()

Implements org.apache.hc.core5.http.HttpEntity.isStreaming.

Doc from org.apache.hc.core5.http.HttpEntity.isStreaming.

Tells whether this entity depends on an underlying stream. Streamed entities that read data directly from the socket should return true. Self-contained entities should return false. Wrapping entities should delegate this call to the wrapped entity.

Returns:boolean

true if the entity content is streamed, false otherwise

Annotations
@Override
writeToback to summary
public void writeTo(OutputStream outStream) throws IOException

Implements org.apache.hc.core5.http.HttpEntity.writeTo.

Doc from org.apache.hc.core5.http.HttpEntity.writeTo.

Writes the entity content out to the output stream.

Important Note

Please note all entity implementations must ensure that all allocated resources are properly deallocated when this method returns.

Parameters
outStream:OutputStream

the output stream to write entity content to

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs