FileDocCategorySizeDatePackage
BasicHttpResponse.javaAPI DocAndroid 1.5 API7371Wed May 06 22:41:10 BST 2009org.apache.http.message

BasicHttpResponse

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.
author
Oleg Kalnichevski
version
$Revision: 573864 $
since
4.0

Fields Summary
private StatusLine
statusline
private HttpEntity
entity
private ReasonPhraseCatalog
reasonCatalog
private Locale
locale
Constructors Summary
public BasicHttpResponse(StatusLine statusline, ReasonPhraseCatalog catalog, Locale locale)
Creates a new response. This is the constructor to which all others map.

param
statusline the status line
param
catalog the reason phrase catalog, or null to disable automatic reason phrase lookup
param
locale the locale for looking up reason phrases, or null for the system locale

        super();
        if (statusline == null) {
            throw new IllegalArgumentException("Status line may not be null.");
        }
        this.statusline    = statusline;
        this.reasonCatalog = catalog;
        this.locale        = (locale != null) ? locale : Locale.getDefault();
    
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.

param
statusline the status line

        this(statusline, null, null);
    
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.

param
ver the protocol version of the response
param
code the status code of the response
param
reason the reason phrase to the status code, or null

        this(new BasicStatusLine(ver, code, reason), null, null);
    
Methods Summary
public org.apache.http.HttpEntitygetEntity()

        return this.entity;
    
public java.util.LocalegetLocale()

        return this.locale;
    
public org.apache.http.ProtocolVersiongetProtocolVersion()

        return this.statusline.getProtocolVersion();
    
protected java.lang.StringgetReason(int code)
Looks up a reason phrase. This method evaluates the currently set catalog and locale. It also handles a missing catalog.

param
code the status code for which to look up the reason
return
the reason phrase, or null if there is none

        return (this.reasonCatalog == null) ?
            null : this.reasonCatalog.getReason(code, this.locale);
    
public org.apache.http.StatusLinegetStatusLine()

        return this.statusline; 
    
public voidsetEntity(org.apache.http.HttpEntity entity)

        this.entity = entity;
    
public voidsetLocale(java.util.Locale loc)

        if (loc == null) {
            throw new IllegalArgumentException("Locale may not be null.");
        }
        this.locale = loc;
        final int code = this.statusline.getStatusCode();
        this.statusline = new BasicStatusLine
            (this.statusline.getProtocolVersion(), code, getReason(code));
    
public voidsetReasonPhrase(java.lang.String reason)


        if ((reason != null) && ((reason.indexOf('\n") >= 0) ||
                                 (reason.indexOf('\r") >= 0))
            ) {
            throw new IllegalArgumentException("Line break in reason phrase.");
        }
        this.statusline = new BasicStatusLine(this.statusline.getProtocolVersion(),
                                              this.statusline.getStatusCode(),
                                              reason);
    
public voidsetStatusCode(int code)

        // argument checked in BasicStatusLine constructor
        ProtocolVersion ver = this.statusline.getProtocolVersion();
        this.statusline = new BasicStatusLine(ver, code, getReason(code));
    
public voidsetStatusLine(org.apache.http.ProtocolVersion ver, int code, java.lang.String reason)

        // arguments checked in BasicStatusLine constructor
        this.statusline = new BasicStatusLine(ver, code, reason);
    
public voidsetStatusLine(org.apache.http.StatusLine statusline)

        if (statusline == null) {
            throw new IllegalArgumentException("Status line may not be null");
        }
        this.statusline = statusline;
    
public voidsetStatusLine(org.apache.http.ProtocolVersion ver, int code)

        // arguments checked in BasicStatusLine constructor
        this.statusline = new BasicStatusLine(ver, code, getReason(code));