Top Description Fields Constructors Methods
org.apache.http.message

public Class BasicHttpResponse

extends AbstractHttpMessage
implements HttpResponse
Class Inheritance
All Implemented Interfaces
org.apache.http.HttpResponse, org.apache.http.HttpMessage
Imports
java.util.Locale, org.apache.http.HttpEntity, .HttpResponse, .HttpVersion, .ProtocolVersion, .ReasonPhraseCatalog, .StatusLine, org.apache.http.util.Args, .TextUtils

Basic implementation of HttpResponse.
Since
4.0
See Also
org.apache.http.impl.DefaultHttpResponseFactory

Field Summary

Modifier and TypeField and Description
private int
private HttpEntity
private Locale
private final ReasonPhraseCatalog
private String
private StatusLine
private ProtocolVersion
Inherited from org.apache.http.message.AbstractHttpMessage:
headergroupparams

Constructor Summary

AccessConstructor and Description
public
BasicHttpResponse(final StatusLine
the status line
statusline
,
final ReasonPhraseCatalog
the reason phrase catalog, or null to disable automatic reason phrase lookup
catalog
,
final Locale
the locale for looking up reason phrases, or null for the system locale
locale
)

Creates a new response.

public
BasicHttpResponse(final StatusLine
the status line
statusline
)

Creates a response from a status line.

public
BasicHttpResponse(final ProtocolVersion
the protocol version of the response
ver
,
final int
the status code of the response
code
,
final String
the reason phrase to the status code, or null
reason
)

Creates a response from elements of a status line.

Method Summary

Modifier and TypeMethod and Description
public HttpEntity
getEntity()

Implements org.apache.http.HttpResponse.getEntity.

Obtains the message entity of this response, if any.
public Locale
getLocale()

Implements org.apache.http.HttpResponse.getLocale.

Obtains the locale of this response.
public ProtocolVersion
getProtocolVersion()

Implements org.apache.http.HttpMessage.getProtocolVersion.

Returns the protocol version this message is compatible with.
protected String

Returns:

the reason phrase, or null if there is none
getReason
(final int
the status code for which to look up the reason
code
)

Looks up a reason phrase.

public StatusLine
getStatusLine()

Implements org.apache.http.HttpResponse.getStatusLine.

Obtains the status line of this response.
public void
setEntity(final HttpEntity
the entity to associate with this response, or null to unset
entity
)

Implements org.apache.http.HttpResponse.setEntity.

Associates a response entity with this response.
public void
setLocale(final Locale
the new locale
locale
)

Implements org.apache.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.http.HttpResponse.setReasonPhrase.

Updates the status line of this response with a new reason phrase.
public void
setStatusCode(final int
the HTTP status code.
code
)

Implements org.apache.http.HttpResponse.setStatusCode.

Updates the status line of this response with a new status code.
public void
setStatusLine(final StatusLine
the status line of this response
statusline
)

Implements org.apache.http.HttpResponse.setStatusLine.

Sets the status line of this response.
public void
setStatusLine(final ProtocolVersion
the HTTP version
ver
,
final int
the status code
code
)

Implements org.apache.http.HttpResponse.setStatusLine.

Sets the status line of this response.
public void
setStatusLine(final ProtocolVersion
the HTTP version
ver
,
final int
the status code
code
,
final String
the reason phrase, or null to omit
reason
)

Implements org.apache.http.HttpResponse.setStatusLine.

Sets the status line of this response with a reason phrase.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from org.apache.http.message.AbstractHttpMessage:
addHeaderaddHeadercontainsHeadergetAllHeadersgetFirstHeadergetHeadersgetLastHeadergetParamsheaderIteratorheaderIteratorremoveHeaderremoveHeaderssetHeadersetHeadersetHeaderssetParams

Field Detail

codeback to summary
private int code
entityback to summary
private HttpEntity entity
localeback to summary
private Locale locale
reasonCatalogback to summary
private final ReasonPhraseCatalog reasonCatalog
reasonPhraseback to summary
private String reasonPhrase
statuslineback to summary
private StatusLine statusline
verback to summary
private ProtocolVersion ver

Constructor Detail

BasicHttpResponseback to summary
public BasicHttpResponse(final StatusLine statusline, final ReasonPhraseCatalog catalog, final Locale locale)

Creates a new response. This is the constructor to which all others map.

Parameters
statusline:StatusLine

the status line

catalog:ReasonPhraseCatalog

the reason phrase catalog, or null to disable automatic reason phrase lookup

locale:Locale

the locale for looking up reason phrases, or null for the system locale

BasicHttpResponseback to summary
public BasicHttpResponse(final StatusLine statusline)

Creates a response from a status line. The response will not have a reason phrase catalog and use the system default locale.

Parameters
statusline:StatusLine

the status line

BasicHttpResponseback to summary
public BasicHttpResponse(final ProtocolVersion ver, final int code, final String reason)

Creates a response from elements of a status line. The response will not have a reason phrase catalog and use the system default locale.

Parameters
ver:ProtocolVersion

the protocol version of the response

code:int

the status code of the response

reason:String

the reason phrase to the status code, or null

Method Detail

getEntityback to summary
public HttpEntity getEntity()

Implements org.apache.http.HttpResponse.getEntity.

Doc from org.apache.http.HttpResponse.getEntity.

Obtains the message entity of this response, if any. The entity is provided by calling setEntity.

Returns:HttpEntity

the response entity, or null if there is none

Annotations
@Override
getLocaleback to summary
public Locale getLocale()

Implements org.apache.http.HttpResponse.getLocale.

Doc from org.apache.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
getProtocolVersionback to summary
public ProtocolVersion getProtocolVersion()

Implements org.apache.http.HttpMessage.getProtocolVersion.

Doc from org.apache.http.HttpMessage.getProtocolVersion.

Returns the protocol version this message is compatible with.

Annotations
@Override
getReasonback to summary
protected String getReason(final int code)

Looks up a reason phrase. This method evaluates the currently set catalog and locale. It also handles a missing catalog.

Parameters
code:int

the status code for which to look up the reason

Returns:String

the reason phrase, or null if there is none

getStatusLineback to summary
public StatusLine getStatusLine()

Implements org.apache.http.HttpResponse.getStatusLine.

Doc from org.apache.http.HttpResponse.getStatusLine.

Obtains the status line of this response. The status line can be set using one of the setStatusLine methods, or it can be initialized in a constructor.

Returns:StatusLine

the status line, or null if not yet set

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

Implements org.apache.http.HttpResponse.setEntity.

Doc from org.apache.http.HttpResponse.setEntity.

Associates a response entity with this response.

Please note that if an entity has already been set for this response and it depends on an input stream (HttpEntity#isStreaming() returns true), it must be fully consumed in order to ensure release of resources.

Parameters
entity:HttpEntity

the entity to associate with this response, or null to unset

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

Implements org.apache.http.HttpResponse.setLocale.

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

Changes the locale of this response.

Parameters
locale:Locale

the new locale

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

Implements org.apache.http.HttpResponse.setReasonPhrase.

Doc from org.apache.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
setStatusCodeback to summary
public void setStatusCode(final int code)

Implements org.apache.http.HttpResponse.setStatusCode.

Doc from org.apache.http.HttpResponse.setStatusCode.

Updates the status line of this response with a new status code.

Parameters
code:int

the HTTP status code.

Annotations
@Override
setStatusLineback to summary
public void setStatusLine(final StatusLine statusline)

Implements org.apache.http.HttpResponse.setStatusLine.

Doc from org.apache.http.HttpResponse.setStatusLine.

Sets the status line of this response.

Parameters
statusline:StatusLine

the status line of this response

Annotations
@Override
setStatusLineback to summary
public void setStatusLine(final ProtocolVersion ver, final int code)

Implements org.apache.http.HttpResponse.setStatusLine.

Doc from org.apache.http.HttpResponse.setStatusLine.

Sets the status line of this response. The reason phrase will be determined based on the current locale.

Parameters
ver:ProtocolVersion

the HTTP version

code:int

the status code

Annotations
@Override
setStatusLineback to summary
public void setStatusLine(final ProtocolVersion ver, final int code, final String reason)

Implements org.apache.http.HttpResponse.setStatusLine.

Doc from org.apache.http.HttpResponse.setStatusLine.

Sets the status line of this response with a reason phrase.

Parameters
ver:ProtocolVersion

the HTTP version

code:int

the status code

reason:String

the reason phrase, or null to omit

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