Package org.apache.http.message
Class BasicHttpResponse
- java.lang.Object
-
- org.apache.http.message.AbstractHttpMessage
-
- org.apache.http.message.BasicHttpResponse
-
- All Implemented Interfaces:
HttpMessage
,HttpResponse
public class BasicHttpResponse extends AbstractHttpMessage implements HttpResponse
Basic implementation ofHttpResponse
.- Since:
- 4.0
- See Also:
DefaultHttpResponseFactory
-
-
Constructor Summary
Constructors Constructor Description BasicHttpResponse(ProtocolVersion ver, int code, java.lang.String reason)
Creates a response from elements of a status line.BasicHttpResponse(StatusLine statusline)
Creates a response from a status line.BasicHttpResponse(StatusLine statusline, ReasonPhraseCatalog catalog, java.util.Locale locale)
Creates a new response.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HttpEntity
getEntity()
Obtains the message entity of this response, if any.java.util.Locale
getLocale()
Obtains the locale of this response.ProtocolVersion
getProtocolVersion()
Returns the protocol version this message is compatible with.StatusLine
getStatusLine()
Obtains the status line of this response.void
setEntity(HttpEntity entity)
Associates a response entity with this response.void
setLocale(java.util.Locale locale)
Changes the locale of this response.void
setReasonPhrase(java.lang.String reason)
Updates the status line of this response with a new reason phrase.void
setStatusCode(int code)
Updates the status line of this response with a new status code.void
setStatusLine(ProtocolVersion ver, int code)
Sets the status line of this response.void
setStatusLine(ProtocolVersion ver, int code, java.lang.String reason)
Sets the status line of this response with a reason phrase.void
setStatusLine(StatusLine statusline)
Sets the status line of this response.java.lang.String
toString()
-
Methods inherited from class org.apache.http.message.AbstractHttpMessage
addHeader, addHeader, containsHeader, getAllHeaders, getFirstHeader, getHeaders, getLastHeader, getParams, headerIterator, headerIterator, removeHeader, removeHeaders, setHeader, setHeader, setHeaders, setParams
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.http.HttpMessage
addHeader, addHeader, containsHeader, getAllHeaders, getFirstHeader, getHeaders, getLastHeader, getParams, headerIterator, headerIterator, removeHeader, removeHeaders, setHeader, setHeader, setHeaders, setParams
-
-
-
-
Constructor Detail
-
BasicHttpResponse
public BasicHttpResponse(StatusLine statusline, ReasonPhraseCatalog catalog, java.util.Locale locale)
Creates a new response. This is the constructor to which all others map.- Parameters:
statusline
- the status linecatalog
- the reason phrase catalog, ornull
to disable automatic reason phrase lookuplocale
- the locale for looking up reason phrases, ornull
for the system locale
-
BasicHttpResponse
public BasicHttpResponse(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
- the status line
-
BasicHttpResponse
public BasicHttpResponse(ProtocolVersion ver, int code, java.lang.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
- the protocol version of the responsecode
- the status code of the responsereason
- the reason phrase to the status code, ornull
-
-
Method Detail
-
getProtocolVersion
public ProtocolVersion getProtocolVersion()
Description copied from interface:HttpMessage
Returns the protocol version this message is compatible with.- Specified by:
getProtocolVersion
in interfaceHttpMessage
-
getStatusLine
public StatusLine getStatusLine()
Description copied from interface:HttpResponse
Obtains the status line of this response. The status line can be set using one of thesetStatusLine
methods, or it can be initialized in a constructor.- Specified by:
getStatusLine
in interfaceHttpResponse
- Returns:
- the status line, or
null
if not yet set
-
getEntity
public HttpEntity getEntity()
Description copied from interface:HttpResponse
Obtains the message entity of this response, if any. The entity is provided by callingsetEntity
.- Specified by:
getEntity
in interfaceHttpResponse
- Returns:
- the response entity, or
null
if there is none
-
getLocale
public java.util.Locale getLocale()
Description copied from interface:HttpResponse
Obtains the locale of this response. The locale is used to determine the reason phrase for thestatus code
. It can be changed usingsetLocale
.- Specified by:
getLocale
in interfaceHttpResponse
- Returns:
- the locale of this response, never
null
-
setStatusLine
public void setStatusLine(StatusLine statusline)
Description copied from interface:HttpResponse
Sets the status line of this response.- Specified by:
setStatusLine
in interfaceHttpResponse
- Parameters:
statusline
- the status line of this response
-
setStatusLine
public void setStatusLine(ProtocolVersion ver, int code)
Description copied from interface:HttpResponse
Sets the status line of this response. The reason phrase will be determined based on the currentlocale
.- Specified by:
setStatusLine
in interfaceHttpResponse
- Parameters:
ver
- the HTTP versioncode
- the status code
-
setStatusLine
public void setStatusLine(ProtocolVersion ver, int code, java.lang.String reason)
Description copied from interface:HttpResponse
Sets the status line of this response with a reason phrase.- Specified by:
setStatusLine
in interfaceHttpResponse
- Parameters:
ver
- the HTTP versioncode
- the status codereason
- the reason phrase, ornull
to omit
-
setStatusCode
public void setStatusCode(int code)
Description copied from interface:HttpResponse
Updates the status line of this response with a new status code.- Specified by:
setStatusCode
in interfaceHttpResponse
- Parameters:
code
- the HTTP status code.- See Also:
HttpStatus
,HttpResponse.setStatusLine(StatusLine)
,HttpResponse.setStatusLine(ProtocolVersion,int)
-
setReasonPhrase
public void setReasonPhrase(java.lang.String reason)
Description copied from interface:HttpResponse
Updates the status line of this response with a new reason phrase.- Specified by:
setReasonPhrase
in interfaceHttpResponse
- Parameters:
reason
- the new reason phrase as a single-line string, ornull
to unset the reason phrase- See Also:
HttpResponse.setStatusLine(StatusLine)
,HttpResponse.setStatusLine(ProtocolVersion,int)
-
setEntity
public void setEntity(HttpEntity entity)
Description copied from interface:HttpResponse
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()
returnstrue
), it must be fully consumed in order to ensure release of resources.- Specified by:
setEntity
in interfaceHttpResponse
- Parameters:
entity
- the entity to associate with this response, ornull
to unset- See Also:
HttpEntity.isStreaming()
,EntityUtils.updateEntity(HttpResponse, HttpEntity)
-
setLocale
public void setLocale(java.util.Locale locale)
Description copied from interface:HttpResponse
Changes the locale of this response.- Specified by:
setLocale
in interfaceHttpResponse
- Parameters:
locale
- the new locale
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-