Top Description Fields Constructors Methods
org.apache.hc.client5.http.impl.classic

public final Class CloseableHttpResponse

extends Object
implements ClassicHttpResponse
Class Inheritance
All Implemented Interfaces
org.apache.hc.core5.http.ClassicHttpResponse, java.io.Closeable, java.lang.AutoCloseable, org.apache.hc.core5.http.HttpEntityContainer, org.apache.hc.core5.http.HttpResponse, org.apache.hc.core5.http.HttpMessage, org.apache.hc.core5.http.MessageHeaders
Imports
java.io.IOException, java.util.Iterator, .Locale, org.apache.hc.client5.http.classic.ExecRuntime, org.apache.hc.core5.http.ClassicHttpResponse, .Header, .HttpEntity, .ProtocolException, .ProtocolVersion, org.apache.hc.core5.util.Args

Provided for backward compatibility with HttpClient 4.x.
Since
4.3

Field Summary

Modifier and TypeField and Description
private final ExecRuntime
private final ClassicHttpResponse

Constructor Summary

AccessConstructor and Description
pack-priv
CloseableHttpResponse(final ClassicHttpResponse response, final ExecRuntime execRuntime)

Method Summary

Modifier and TypeMethod and Description
pack-priv static CloseableHttpResponse
adapt(final ClassicHttpResponse response)

public void
addHeader(final Header
the header to append.
header
)

Implements org.apache.hc.core5.http.HttpMessage.addHeader.

Adds a header to this message.
public void
addHeader(final String
the name of the header.
name
,
final Object
the value of the header, taken as the value's Object#toString().
value
)

Implements org.apache.hc.core5.http.HttpMessage.addHeader.

Adds a header to this message.
public void
close()

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.
public boolean
containsHeader(final String
the header name to check for.
name
)

Implements org.apache.hc.core5.http.MessageHeaders.containsHeader.

Checks if a certain header is present in this message.
public int
countHeaders(final String
the header name to check for.
name
)

Implements org.apache.hc.core5.http.MessageHeaders.countHeaders.

Checks if a certain header is present in this message and how many times.
public int
getCode()

Implements org.apache.hc.core5.http.HttpResponse.getCode.

Obtains the code of this response message.
public HttpEntity
getEntity()

Implements org.apache.hc.core5.http.HttpEntityContainer.getEntity.

Obtains the message entity, if available.
public Header
getFirstHeader(final String
the name of the header to return.
name
)

Implements org.apache.hc.core5.http.MessageHeaders.getFirstHeader.

Returns the first header with a specified name of this message.
public Header
getHeader(final String
the name of the header to get
name
)

Implements org.apache.hc.core5.http.MessageHeaders.getHeader.

Gets single first header with the given name.
public Header[]
getHeaders(final String
the name of the headers to return.
name
)

Implements org.apache.hc.core5.http.MessageHeaders.getHeaders.

Returns all the headers with a specified name of this message.
public Header[]
getHeaders()

Implements org.apache.hc.core5.http.MessageHeaders.getHeaders.

Returns all the headers of this message.
public Header
getLastHeader(final String
the name of the header to return.
name
)

Implements org.apache.hc.core5.http.MessageHeaders.getLastHeader.

Returns the last header with a specified name of this message.
public Locale
getLocale()

Implements org.apache.hc.core5.http.HttpResponse.getLocale.

Obtains the locale of this response.
public String
getReasonPhrase()

Implements org.apache.hc.core5.http.HttpResponse.getReasonPhrase.

Obtains the reason phrase of this response if available.
public ProtocolVersion
getVersion()

Implements org.apache.hc.core5.http.HttpMessage.getVersion.

Returns protocol version or null when not available.
public Iterator<Header>
headerIterator()

Implements org.apache.hc.core5.http.MessageHeaders.headerIterator.

Returns an iterator of all the headers.
public Iterator<Header>
headerIterator(final String
the name of the headers over which to iterate, or null for all headers
name
)

Implements org.apache.hc.core5.http.MessageHeaders.headerIterator.

Returns an iterator of the headers with a given name.
public boolean
removeHeader(final Header
the header to remove.
header
)

Implements org.apache.hc.core5.http.HttpMessage.removeHeader.

Removes a header from this message.
public boolean
removeHeaders(final String
The name of the headers to remove.
name
)

Implements org.apache.hc.core5.http.HttpMessage.removeHeaders.

Removes all headers with a certain name from this message.
public void
setCode(final int
the HTTP status code.
code
)

Implements org.apache.hc.core5.http.HttpResponse.setCode.

Updates status code of this response message.
public void
setEntity(final HttpEntity
the entity to set of this message, or null to unset
entity
)

Implements org.apache.hc.core5.http.HttpEntityContainer.setEntity.

Sets an entity for this message.
public void
setHeader(final Header
the header to set.
header
)

Implements org.apache.hc.core5.http.HttpMessage.setHeader.

Overwrites the first header with the same name.
public void
setHeader(final String
the name of the header.
name
,
final Object
the value of the header, taken as the value's Object#toString().
value
)

Implements org.apache.hc.core5.http.HttpMessage.setHeader.

Overwrites the first header with the same name.
public void
setHeaders(final Header...
the array of headers to set.
headers
)

Implements org.apache.hc.core5.http.HttpMessage.setHeaders.

Overwrites all the headers in the message.
public void
setLocale(final Locale
the new locale
loc
)

Implements org.apache.hc.core5.http.HttpResponse.setLocale.

Changes the locale of this response.
public void
setReasonPhrase(final String
the new reason phrase as a single-line string, or null to unset the reason phrase
reason
)

Implements org.apache.hc.core5.http.HttpResponse.setReasonPhrase.

Updates the status line of this response with a new reason phrase.
public void
setVersion(final ProtocolVersion version)

Implements org.apache.hc.core5.http.HttpMessage.setVersion.

Sets protocol version.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

execRuntimeback to summary
private final ExecRuntime execRuntime
responseback to summary
private final ClassicHttpResponse response

Constructor Detail

CloseableHttpResponseback to summary
pack-priv CloseableHttpResponse(final ClassicHttpResponse response, final ExecRuntime execRuntime)

Method Detail

adaptback to summary
pack-priv static CloseableHttpResponse adapt(final ClassicHttpResponse response)
addHeaderback to summary
public void addHeader(final Header header)

Implements org.apache.hc.core5.http.HttpMessage.addHeader.

Doc from org.apache.hc.core5.http.HttpMessage.addHeader.

Adds a header to this message. The header will be appended to the end of the list.

Parameters
header:Header

the header to append.

Annotations
@Override
addHeaderback to summary
public void addHeader(final String name, final Object value)

Implements org.apache.hc.core5.http.HttpMessage.addHeader.

Doc from org.apache.hc.core5.http.HttpMessage.addHeader.

Adds a header to this message. The header will be appended to the end of the list.

Parameters
name:String

the name of the header.

value:Object

the value of the header, taken as the value's Object#toString().

Annotations
@Override
closeback to summary
public void close() throws IOException

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
Exceptions
IOException:
if an I/O error occurs
containsHeaderback to summary
public boolean containsHeader(final String name)

Implements org.apache.hc.core5.http.MessageHeaders.containsHeader.

Doc from org.apache.hc.core5.http.MessageHeaders.containsHeader.

Checks if a certain header is present in this message. Header values are ignored.

Parameters
name:String

the header name to check for.

Returns:boolean

true if at least one header with this name is present.

Annotations
@Override
countHeadersback to summary
public int countHeaders(final String name)

Implements org.apache.hc.core5.http.MessageHeaders.countHeaders.

Doc from org.apache.hc.core5.http.MessageHeaders.countHeaders.

Checks if a certain header is present in this message and how many times.

Parameters
name:String

the header name to check for.

Returns:int

number of occurrences of the header in the message.

Annotations
@Override
getCodeback to summary
public int getCode()

Implements org.apache.hc.core5.http.HttpResponse.getCode.

Doc from org.apache.hc.core5.http.HttpResponse.getCode.

Obtains the code of this response message.

Returns:int

the status code.

Annotations
@Override
getEntityback to summary
public HttpEntity getEntity()

Implements org.apache.hc.core5.http.HttpEntityContainer.getEntity.

Doc from org.apache.hc.core5.http.HttpEntityContainer.getEntity.

Obtains the message entity, if available.

Returns:HttpEntity

the message entity, or null if not available

Annotations
@Override
getFirstHeaderback to summary
public Header getFirstHeader(final String name)

Implements org.apache.hc.core5.http.MessageHeaders.getFirstHeader.

Doc from org.apache.hc.core5.http.MessageHeaders.getFirstHeader.

Returns the first header with a specified name of this message. Header values are ignored. If there is more than one matching header in the message the first element of getHeaders(String) is returned. If there is no matching header in the message null is returned.

Parameters
name:String

the name of the header to return.

Returns:Header

the first header whose name property equals name or null if no such header could be found.

Annotations
@Override
getHeaderback to summary
public Header getHeader(final String name) throws ProtocolException

Implements org.apache.hc.core5.http.MessageHeaders.getHeader.

Doc from org.apache.hc.core5.http.MessageHeaders.getHeader.

Gets single first header with the given name.

Header name comparison is case insensitive.

Parameters
name:String

the name of the header to get

Returns:Header

the first header or null

Annotations
@Override
Exceptions
ProtocolException:
in case multiple headers with the given name are found.
getHeadersback to summary
public Header[] getHeaders(final String name)

Implements org.apache.hc.core5.http.MessageHeaders.getHeaders.

Doc from org.apache.hc.core5.http.MessageHeaders.getHeaders.

Returns all the headers with a specified name of this message. Header values are ignored. Headers are ordered in the sequence they will be sent over a connection.

Parameters
name:String

the name of the headers to return.

Returns:Header[]

the headers whose name property equals name.

Annotations
@Override
getHeadersback to summary
public Header[] getHeaders()

Implements org.apache.hc.core5.http.MessageHeaders.getHeaders.

Doc from org.apache.hc.core5.http.MessageHeaders.getHeaders.

Returns all the headers of this message. Headers are ordered in the sequence they will be sent over a connection.

Returns:Header[]

all the headers of this message

Annotations
@Override
getLastHeaderback to summary
public Header getLastHeader(final String name)

Implements org.apache.hc.core5.http.MessageHeaders.getLastHeader.

Doc from org.apache.hc.core5.http.MessageHeaders.getLastHeader.

Returns the last header with a specified name of this message. Header values are ignored. If there is more than one matching header in the message the last element of getHeaders(String) is returned. If there is no matching header in the message null is returned.

Parameters
name:String

the name of the header to return.

Returns:Header

the last header whose name property equals name. or null if no such header could be found.

Annotations
@Override
getLocaleback to summary
public Locale getLocale()

Implements org.apache.hc.core5.http.HttpResponse.getLocale.

Doc from org.apache.hc.core5.http.HttpResponse.getLocale.

Obtains the locale of this response. The locale is used to determine the reason phrase for the status code. It can be changed using setLocale.

Returns:Locale

the locale of this response, never null

Annotations
@Override
getReasonPhraseback to summary
public String getReasonPhrase()

Implements org.apache.hc.core5.http.HttpResponse.getReasonPhrase.

Doc from org.apache.hc.core5.http.HttpResponse.getReasonPhrase.

Obtains the reason phrase of this response if available.

Returns:String

the reason phrase.

Annotations
@Override
getVersionback to summary
public ProtocolVersion getVersion()

Implements org.apache.hc.core5.http.HttpMessage.getVersion.

Doc from org.apache.hc.core5.http.HttpMessage.getVersion.

Returns protocol version or null when not available.

For incoming messages it represents protocol version this message was transmitted with. For outgoing messages it represents a hint what protocol version should be used to transmit the message.

Annotations
@Override
headerIteratorback to summary
public Iterator<Header> headerIterator()

Implements org.apache.hc.core5.http.MessageHeaders.headerIterator.

Doc from org.apache.hc.core5.http.MessageHeaders.headerIterator.

Returns an iterator of all the headers.

Returns:Iterator<Header>

Iterator that returns Header objects in the sequence they are sent over a connection.

Annotations
@Override
headerIteratorback to summary
public Iterator<Header> headerIterator(final String name)

Implements org.apache.hc.core5.http.MessageHeaders.headerIterator.

Doc from org.apache.hc.core5.http.MessageHeaders.headerIterator.

Returns an iterator of the headers with a given name.

Parameters
name:String

the name of the headers over which to iterate, or null for all headers

Returns:Iterator<Header>

Iterator that returns Header objects with the argument name in the sequence they are sent over a connection.

Annotations
@Override
removeHeaderback to summary
public boolean removeHeader(final Header header)

Implements org.apache.hc.core5.http.HttpMessage.removeHeader.

Doc from org.apache.hc.core5.http.HttpMessage.removeHeader.

Removes a header from this message.

Parameters
header:Header

the header to remove.

Returns:boolean

true if a header was removed as a result of this call.

Annotations
@Override
removeHeadersback to summary
public boolean removeHeaders(final String name)

Implements org.apache.hc.core5.http.HttpMessage.removeHeaders.

Doc from org.apache.hc.core5.http.HttpMessage.removeHeaders.

Removes all headers with a certain name from this message.

Parameters
name:String

The name of the headers to remove.

Returns:boolean

true if any header was removed as a result of this call.

Annotations
@Override
setCodeback to summary
public void setCode(final int code)

Implements org.apache.hc.core5.http.HttpResponse.setCode.

Doc from org.apache.hc.core5.http.HttpResponse.setCode.

Updates status code of this response message.

Parameters
code:int

the HTTP status code.

Annotations
@Override
setEntityback to summary
public void setEntity(final HttpEntity entity)

Implements org.apache.hc.core5.http.HttpEntityContainer.setEntity.

Doc from org.apache.hc.core5.http.HttpEntityContainer.setEntity.

Sets an entity for this message.

Please note that if an entity has already been set it is responsibility of the caller to ensure release of the resources that may be associated with that entity.

Parameters
entity:HttpEntity

the entity to set of this message, or null to unset

Annotations
@Override
setHeaderback to summary
public void setHeader(final Header header)

Implements org.apache.hc.core5.http.HttpMessage.setHeader.

Doc from org.apache.hc.core5.http.HttpMessage.setHeader.

Overwrites the first header with the same name. The new header will be appended to the end of the list, if no header with the given name can be found.

Parameters
header:Header

the header to set.

Annotations
@Override
setHeaderback to summary
public void setHeader(final String name, final Object value)

Implements org.apache.hc.core5.http.HttpMessage.setHeader.

Doc from org.apache.hc.core5.http.HttpMessage.setHeader.

Overwrites the first header with the same name. The new header will be appended to the end of the list, if no header with the given name can be found.

Parameters
name:String

the name of the header.

value:Object

the value of the header, taken as the value's Object#toString().

Annotations
@Override
setHeadersback to summary
public void setHeaders(final Header... headers)

Implements org.apache.hc.core5.http.HttpMessage.setHeaders.

Doc from org.apache.hc.core5.http.HttpMessage.setHeaders.

Overwrites all the headers in the message.

Parameters
headers:Header[]

the array of headers to set.

Annotations
@Override
setLocaleback to summary
public void setLocale(final Locale loc)

Implements org.apache.hc.core5.http.HttpResponse.setLocale.

Doc from org.apache.hc.core5.http.HttpResponse.setLocale.

Changes the locale of this response.

Parameters
loc:Locale

the new locale

Annotations
@Override
setReasonPhraseback to summary
public void setReasonPhrase(final String reason)

Implements org.apache.hc.core5.http.HttpResponse.setReasonPhrase.

Doc from org.apache.hc.core5.http.HttpResponse.setReasonPhrase.

Updates the status line of this response with a new reason phrase.

Parameters
reason:String

the new reason phrase as a single-line string, or null to unset the reason phrase

Annotations
@Override
setVersionback to summary
public void setVersion(final ProtocolVersion version)

Implements org.apache.hc.core5.http.HttpMessage.setVersion.

Doc from org.apache.hc.core5.http.HttpMessage.setVersion.

Sets protocol version.

For incoming messages it represents protocol version this message was transmitted with. For outgoing messages it represents a hint what protocol version should be used to transmit the message.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override