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 of an HTTP response that can be modified.
This implementation makes sure that there always is a status line.
- Since:
- 4.0
- Version:
- $Revision: 573864 $
- Author:
- Oleg Kalnichevski
-
Field Summary
Fields inherited from class org.apache.http.message.AbstractHttpMessage
headergroup, params -
Constructor Summary
Constructors Constructor Description BasicHttpResponse(ProtocolVersion ver, int code, 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, Locale locale)Creates a new response. -
Method Summary
Modifier and Type Method Description HttpEntitygetEntity()Obtains the message entity of this response, if any.LocalegetLocale()Obtains the locale of this response.ProtocolVersiongetProtocolVersion()Returns the protocol version this message is compatible with.protected StringgetReason(int code)Looks up a reason phrase.StatusLinegetStatusLine()Obtains the status line of this response.voidsetEntity(HttpEntity entity)Associates a response entity with this response.voidsetLocale(Locale loc)Changes the locale of this response.voidsetReasonPhrase(String reason)Updates the status line of this response with a new reason phrase.voidsetStatusCode(int code)Updates the status line of this response with a new status code.voidsetStatusLine(ProtocolVersion ver, int code)Sets the status line of this response.voidsetStatusLine(ProtocolVersion ver, int code, String reason)Sets the status line of this response with a reason phrase.voidsetStatusLine(StatusLine statusline)Sets the status line of this response.Methods inherited from class org.apache.http.message.AbstractHttpMessage
addHeader, addHeader, containsHeader, getAllHeaders, getFirstHeader, getHeaders, getLastHeader, getParams, headerIterator, headerIterator, removeHeader, removeHeaders, setHeader, setHeader, setHeaders, setParamsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.http.HttpMessage
addHeader, addHeader, containsHeader, getAllHeaders, getFirstHeader, getHeaders, getLastHeader, getParams, headerIterator, headerIterator, removeHeader, removeHeaders, setHeader, setHeader, setHeaders, setParams
-
Constructor Details
-
BasicHttpResponse
Creates a new response. This is the constructor to which all others map.- Parameters:
statusline- the status linecatalog- the reason phrase catalog, ornullto disable automatic reason phrase lookuplocale- the locale for looking up reason phrases, ornullfor the system locale
-
BasicHttpResponse
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
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 Details
-
getProtocolVersion
Description copied from interface:HttpMessageReturns the protocol version this message is compatible with.- Specified by:
getProtocolVersionin interfaceHttpMessage
-
getStatusLine
Description copied from interface:HttpResponseObtains the status line of this response. The status line can be set using one of thesetStatusLinemethods, or it can be initialized in a constructor.- Specified by:
getStatusLinein interfaceHttpResponse- Returns:
- the status line, or
nullif not yet set
-
getEntity
Description copied from interface:HttpResponseObtains the message entity of this response, if any. The entity is provided by callingsetEntity.- Specified by:
getEntityin interfaceHttpResponse- Returns:
- the response entity, or
nullif there is none
-
getLocale
Description copied from interface:HttpResponseObtains the locale of this response. The locale is used to determine the reason phrase for thestatus code. It can be changed usingsetLocale.- Specified by:
getLocalein interfaceHttpResponse- Returns:
- the locale of this response, never
null
-
setStatusLine
Description copied from interface:HttpResponseSets the status line of this response.- Specified by:
setStatusLinein interfaceHttpResponse- Parameters:
statusline- the status line of this response
-
setStatusLine
Description copied from interface:HttpResponseSets the status line of this response. The reason phrase will be determined based on the currentlocale.- Specified by:
setStatusLinein interfaceHttpResponse- Parameters:
ver- the HTTP versioncode- the status code
-
setStatusLine
Description copied from interface:HttpResponseSets the status line of this response with a reason phrase.- Specified by:
setStatusLinein interfaceHttpResponse- Parameters:
ver- the HTTP versioncode- the status codereason- the reason phrase, ornullto omit
-
setStatusCode
public void setStatusCode(int code)Description copied from interface:HttpResponseUpdates the status line of this response with a new status code. The status line can only be updated if it is available. It must have been set either explicitly or in a constructor.
The reason phrase will be updated according to the new status code, based on the currentlocale. It can be set explicitly usingsetReasonPhrase.- Specified by:
setStatusCodein interfaceHttpResponse- Parameters:
code- the HTTP status code.- See Also:
HttpStatus,HttpResponse.setStatusLine(StatusLine),HttpResponse.setStatusLine(ProtocolVersion,int)
-
setReasonPhrase
Description copied from interface:HttpResponseUpdates the status line of this response with a new reason phrase. The status line can only be updated if it is available. It must have been set either explicitly or in a constructor.- Specified by:
setReasonPhrasein interfaceHttpResponse- Parameters:
reason- the new reason phrase as a single-line string, ornullto unset the reason phrase- See Also:
HttpResponse.setStatusLine(StatusLine),HttpResponse.setStatusLine(ProtocolVersion,int)
-
setEntity
Description copied from interface:HttpResponseAssociates a response entity with this response.- Specified by:
setEntityin interfaceHttpResponse- Parameters:
entity- the entity to associate with this response, ornullto unset
-
setLocale
Description copied from interface:HttpResponseChanges the locale of this response. If there is a status line, it's reason phrase will be updated according to the status code and new locale.- Specified by:
setLocalein interfaceHttpResponse- Parameters:
loc- the new locale- See Also:
getLocale,setStatusCode
-
getReason
Looks up a reason phrase. This method evaluates the currently set catalog and locale. It also handles a missing catalog.- Parameters:
code- the status code for which to look up the reason- Returns:
- the reason phrase, or
nullif there is none
-