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
  • Constructor Details

    • BasicHttpResponse

      public BasicHttpResponse​(StatusLine statusline, ReasonPhraseCatalog catalog, Locale locale)
      Creates a new response. This is the constructor to which all others map.
      Parameters:
      statusline - the status line
      catalog - the reason phrase catalog, or null to disable automatic reason phrase lookup
      locale - the locale for looking up reason phrases, or null 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, 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 response
      code - the status code of the response
      reason - the reason phrase to the status code, or null
  • Method Details

    • getProtocolVersion

      public ProtocolVersion getProtocolVersion()
      Description copied from interface: HttpMessage
      Returns the protocol version this message is compatible with.
      Specified by:
      getProtocolVersion in interface HttpMessage
    • 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 the setStatusLine methods, or it can be initialized in a constructor.
      Specified by:
      getStatusLine in interface HttpResponse
      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 calling setEntity.
      Specified by:
      getEntity in interface HttpResponse
      Returns:
      the response entity, or null if there is none
    • getLocale

      public Locale getLocale()
      Description copied from interface: HttpResponse
      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.
      Specified by:
      getLocale in interface HttpResponse
      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 interface HttpResponse
      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 current locale.
      Specified by:
      setStatusLine in interface HttpResponse
      Parameters:
      ver - the HTTP version
      code - the status code
    • setStatusLine

      public void setStatusLine​(ProtocolVersion ver, int code, String reason)
      Description copied from interface: HttpResponse
      Sets the status line of this response with a reason phrase.
      Specified by:
      setStatusLine in interface HttpResponse
      Parameters:
      ver - the HTTP version
      code - the status code
      reason - the reason phrase, or null 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. 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 current locale. It can be set explicitly using setReasonPhrase.
      Specified by:
      setStatusCode in interface HttpResponse
      Parameters:
      code - the HTTP status code.
      See Also:
      HttpStatus, HttpResponse.setStatusLine(StatusLine), HttpResponse.setStatusLine(ProtocolVersion,int)
    • setReasonPhrase

      public void setReasonPhrase​(String reason)
      Description copied from interface: HttpResponse
      Updates 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:
      setReasonPhrase in interface HttpResponse
      Parameters:
      reason - the new reason phrase as a single-line string, or null 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.
      Specified by:
      setEntity in interface HttpResponse
      Parameters:
      entity - the entity to associate with this response, or null to unset
    • setLocale

      public void setLocale​(Locale loc)
      Description copied from interface: HttpResponse
      Changes 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:
      setLocale in interface HttpResponse
      Parameters:
      loc - the new locale
      See Also:
      getLocale, setStatusCode
    • getReason

      protected String getReason​(int code)
      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 null if there is none