org.xlightweb
Class HttpResponse

Package class diagram package HttpResponse
java.lang.Object
  extended by org.xlightweb.Part
      extended by org.xlightweb.HttpResponse
All Implemented Interfaces:
IHeader, IHttpMessage, IHttpResponse, IPart

public class HttpResponse
extends Part
implements IHttpResponse

http response


Field Summary
 
Fields inherited from interface org.xlightweb.IHttpMessage
CONNECT_METHOD, DEFAULT_ENCODING, DEFAULT_ENCODING_KEY, DELETE_METHOD, GET_METHOD, HEAD_METHOD, OPTIONS_METHOD, POST_METHOD, PUT_METHOD, TRACE_METHOD
 
Constructor Summary
HttpResponse(File file)
          constructor.
HttpResponse(IHttpResponseHeader responseHeader)
          constructor
HttpResponse(IHttpResponseHeader responseHeader, byte[] body)
          constructor
HttpResponse(IHttpResponseHeader responseHeader, byte[] body, boolean compress)
          constructor
HttpResponse(IHttpResponseHeader responseHeader, ByteBuffer[] body)
          constructor
HttpResponse(IHttpResponseHeader responseHeader, ByteBuffer[] body, boolean compress)
          constructor
HttpResponse(IHttpResponseHeader header, File file)
          constructor
HttpResponse(IHttpResponseHeader header, File file, String range)
          constructor
HttpResponse(IHttpResponseHeader responseHeader, List<ByteBuffer> body)
          constructor
HttpResponse(IHttpResponseHeader responseHeader, List<ByteBuffer> body, boolean compress)
          constructor
HttpResponse(IHttpResponseHeader responseHeader, NonBlockingBodyDataSource bodyDataSource)
          constructor
HttpResponse(IHttpResponseHeader responseHeader, String body)
          constructor
HttpResponse(IHttpResponseHeader responseHeader, String body, boolean compress)
          constructor
HttpResponse(int status)
          constructor
HttpResponse(int status, File file)
          constructor
HttpResponse(int status, NameValuePair... nvp)
          constructor
HttpResponse(int status, String body)
          constructor
HttpResponse(int status, String contentType, BodyDataSource body)
          constructor
HttpResponse(int status, String contentType, byte[] body)
          constructor
HttpResponse(int status, String contentType, byte[] body, boolean compress)
          constructor
HttpResponse(int status, String contentType, ByteBuffer[] body)
          constructor
HttpResponse(int status, String contentType, File file)
          constructor
HttpResponse(int status, String contentType, File file, String range)
          constructor
HttpResponse(int status, String contentType, int contentLength, BodyDataSource body)
          constructor
HttpResponse(int status, String contentType, int contentLength, NonBlockingBodyDataSource body)
          constructor
HttpResponse(int status, String contentType, NonBlockingBodyDataSource body)
          constructor
HttpResponse(int status, String contentType, String body)
          constructor
HttpResponse(int status, String contentType, String body, boolean compress)
          constructor
HttpResponse(String body)
          constructor.
HttpResponse(String contentType, BodyDataSource bodyDataSource)
          constructor.
HttpResponse(String contentType, byte[] body)
          constructor.
HttpResponse(String contentType, ByteBuffer[] body)
          constructor.
HttpResponse(String contentType, NonBlockingBodyDataSource bodyDataSource)
          constructor
HttpResponse(String contentType, String body)
          constructor.
 
Method Summary
 Object getAttribute(String name)
          Returns the value of the named attribute as an Object, or null if no attribute of the given name exists.
 Enumeration getAttributeNames()
          Returns an Enumeration containing the names of the attributes available to this message.
 Set<String> getAttributeNameSet()
          Returns an Set containing the names of the attributes available to this messaget.
 int getContentLength()
          Returns the length, in bytes, of the message body and made available by the input stream, or -1 if the length is not known.
 String getDate()
          returns the Date header parameter or null if the header is not set
 IHttpMessageHeader getMessageHeader()
          returns the message header
 String getProtocol()
          returns the protocol
 String getProtocolVersion()
          Returns the version of the protocol the message uses in the form majorVersion.minorVersion, for example, 1.1.
 String getReason()
          returns the reason
 IHttpResponseHeader getResponseHeader()
          returns the response header
 String getServer()
          gets the Server header parameter
 int getStatus()
          returns the status
 void removeHopByHopHeaders()
          removes all hop-by-hop headers without Transfer-Encoding if set to chunked
 void setAttribute(String name, Object o)
          Stores an attribute in this header.
 void setContentLength(int length)
          sets the content length in bytes
 void setDate(long timeMillis)
          set the date header of the response
 void setDate(String date)
          sets the Date header parameter
 void setExpireHeaders(int expireSec)
          set the caching expires headers of a response
 void setLastModifiedHeader(long timeMillis)
          set a last modified header of the response
 void setProtocol(String protocol)
          sets the protocol
 void setReason(String reason)
          sets the reason
 void setServer(String server)
          sets the Server header parameter
 void setStatus(int status)
          sets the status
 String toString()
          
 
Methods inherited from class org.xlightweb.Part
addHeader, addHeaderLine, addHeaderlines, containsHeader, getBlockingBody, getBody, getCharacterEncoding, getContentType, getDisposition, getDispositionParam, getDispositionType, getHeader, getHeaderList, getHeaderNames, getHeaderNameSet, getHeaders, getNonBlockingBody, getPartHeader, getTransferEncoding, hasBody, removeHeader, setContentType, setHeader, setTransferEncoding
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.xlightweb.IHttpMessage
getAttribute, getAttributeNames, getAttributeNameSet, getCharacterEncoding, getContentLength, getContentType, getMessageHeader, getTransferEncoding, removeHopByHopHeaders, setAttribute, setContentLength, setContentType, setTransferEncoding
 
Methods inherited from interface org.xlightweb.IPart
getBlockingBody, getBody, getNonBlockingBody, getPartHeader, hasBody
 
Methods inherited from interface org.xlightweb.IHeader
addHeader, addHeaderLine, addHeaderlines, containsHeader, getDisposition, getDispositionParam, getDispositionType, getHeader, getHeaderList, getHeaderNames, getHeaderNameSet, getHeaders, removeHeader, setHeader
 

Constructor Detail

HttpResponse

public HttpResponse(IHttpResponseHeader responseHeader)
constructor

Parameters:
responseHeader - the response header

HttpResponse

public HttpResponse(int status)
constructor

Parameters:
status - the status

HttpResponse

public HttpResponse(IHttpResponseHeader responseHeader,
                    ByteBuffer[] body,
                    boolean compress)
             throws IOException
constructor

Parameters:
responseHeader - the response header
bodyDataSource - the response body
compress - true, if the data should be compressed
Throws:
IOException - if an io exception occurs

HttpResponse

public HttpResponse(IHttpResponseHeader responseHeader,
                    NonBlockingBodyDataSource bodyDataSource)
             throws IOException
constructor

Parameters:
responseHeader - the response header
bodyDataSource - the response body
Throws:
IOException - if an io exception occurs

HttpResponse

public HttpResponse(int status,
                    String contentType,
                    int contentLength,
                    BodyDataSource body)
             throws IOException
constructor

Parameters:
status - the status
contentType - the content type
contentLength - the content length
body - the body
Throws:
IOException - if an io exception occurs

HttpResponse

public HttpResponse(int status,
                    String contentType,
                    int contentLength,
                    NonBlockingBodyDataSource body)
             throws IOException
constructor

Parameters:
status - the status
contentType - the content type
contentLength - the content length
body - the body
Throws:
IOException - if an io exception occurs

HttpResponse

public HttpResponse(String contentType,
                    NonBlockingBodyDataSource bodyDataSource)
             throws IOException
constructor

Parameters:
responseHeader - the response header
bodyDataSource - the response body
Throws:
IOException - if an io exception occurs

HttpResponse

public HttpResponse(String contentType,
                    BodyDataSource bodyDataSource)
             throws IOException
constructor. The status will be set to 200

Parameters:
responseHeader - the response header
bodyDataSource - the response body
Throws:
IOException - if an io exception occurs

HttpResponse

public HttpResponse(String contentType,
                    String body)
             throws IOException
constructor. The status will be set to 200

Parameters:
contentType - the content type
body - the body
Throws:
IOException - if an io exception occurs

HttpResponse

public HttpResponse(String body)
             throws IOException
constructor. The status will be set to 200

Parameters:
body - the body
Throws:
IOException - if an io exception occurs

HttpResponse

public HttpResponse(File file)
             throws IOException
constructor. The status will be set to 200

Parameters:
file - the file
Throws:
IOException - if an io exception occurs

HttpResponse

public HttpResponse(int status,
                    File file)
             throws IOException
constructor

Parameters:
status - the status
file - the file
Throws:
IOException - if an io exception occurs

HttpResponse

public HttpResponse(int status,
                    String contentType,
                    File file)
             throws IOException
constructor

Parameters:
status - the status
contentType - the contentType
file - the file
Throws:
IOException - if an io exception occurs

HttpResponse

public HttpResponse(int status,
                    String contentType,
                    File file,
                    String range)
             throws IOException
constructor

Parameters:
status - the status
contentType - the contentType
file - the file
Throws:
IOException - if an io exception occurs

HttpResponse

public HttpResponse(int status,
                    NameValuePair... nvp)
             throws IOException
constructor

Parameters:
status - the status
nvp - he name value pairs
Throws:
IOException - if an io exception occurs

HttpResponse

public HttpResponse(IHttpResponseHeader header,
                    File file)
             throws IOException
constructor

Parameters:
header - the response header
file - the file
Throws:
IOException - if an io exception occurs

HttpResponse

public HttpResponse(IHttpResponseHeader header,
                    File file,
                    String range)
             throws IOException
constructor

Parameters:
header - the header
file - the file
range - the range
Throws:
IOException - if an exception occurs

HttpResponse

public HttpResponse(int status,
                    String contentType,
                    String body)
             throws IOException
constructor

Parameters:
status - the status
contentType - the content type
body - the body
Throws:
IOException - if an io exception occurs

HttpResponse

public HttpResponse(int status,
                    String contentType,
                    String body,
                    boolean compress)
             throws IOException
constructor

Parameters:
status - the status
contentType - the content type
body - the body
compress - true, if the data should be compressed
Throws:
IOException - if an io exception occurs

HttpResponse

public HttpResponse(int status,
                    String body)
             throws IOException
constructor

Parameters:
status - the status
body - the body
Throws:
IOException - if an io exception occurs

HttpResponse

public HttpResponse(String contentType,
                    byte[] body)
             throws IOException
constructor. The status will be set to 200

Parameters:
contentType - the content type
body - the body
Throws:
IOException - if an io exception occurs

HttpResponse

public HttpResponse(int status,
                    String contentType,
                    NonBlockingBodyDataSource body)
             throws IOException
constructor

Parameters:
status - the status
contentType - the content type
body - the body
Throws:
IOException - if an io exception occurs

HttpResponse

public HttpResponse(int status,
                    String contentType,
                    BodyDataSource body)
             throws IOException
constructor

Parameters:
status - the status
contentType - the content type
body - the body
Throws:
IOException - if an io exception occurs

HttpResponse

public HttpResponse(int status,
                    String contentType,
                    byte[] body)
             throws IOException
constructor

Parameters:
status - the status
contentType - the content type
body - the body
Throws:
IOException - if an io exception occurs

HttpResponse

public HttpResponse(int status,
                    String contentType,
                    byte[] body,
                    boolean compress)
             throws IOException
constructor

Parameters:
status - the status
contentType - the content type
body - the body
compress - true, if the data should be compressed
Throws:
IOException - if an io exception occurs

HttpResponse

public HttpResponse(String contentType,
                    ByteBuffer[] body)
             throws IOException
constructor. The status will be set to 200

Parameters:
contentType - the content type
body - the body
Throws:
IOException - if an io exception occurs

HttpResponse

public HttpResponse(int status,
                    String contentType,
                    ByteBuffer[] body)
             throws IOException
constructor

Parameters:
status - the status
contentType - the content type
body - the body
Throws:
IOException - if an io exception occurs

HttpResponse

public HttpResponse(IHttpResponseHeader responseHeader,
                    String body)
             throws IOException
constructor

Parameters:
responseHeader - the response header
body - the body
Throws:
IOException - if an io exception occurs

HttpResponse

public HttpResponse(IHttpResponseHeader responseHeader,
                    String body,
                    boolean compress)
             throws IOException
constructor

Parameters:
responseHeader - the response header
body - the body
compress - true, if the data whould be compressed
Throws:
IOException - if an io exception occurs

HttpResponse

public HttpResponse(IHttpResponseHeader responseHeader,
                    byte[] body)
             throws IOException
constructor

Parameters:
responseHeader - the response header
body - the body
Throws:
IOException - if an io exception occurs

HttpResponse

public HttpResponse(IHttpResponseHeader responseHeader,
                    byte[] body,
                    boolean compress)
             throws IOException
constructor

Parameters:
responseHeader - the response header
body - the body
compress - true, if the data should be compressed
Throws:
IOException - if an io exception occurs

HttpResponse

public HttpResponse(IHttpResponseHeader responseHeader,
                    List<ByteBuffer> body)
             throws IOException
constructor

Parameters:
responseHeader - the response header
body - the body
Throws:
IOException - if an io exception occurs

HttpResponse

public HttpResponse(IHttpResponseHeader responseHeader,
                    List<ByteBuffer> body,
                    boolean compress)
             throws IOException
constructor

Parameters:
responseHeader - the response header
body - the body
compress - true, if the data should be compressed
Throws:
IOException - if an io exception occurs

HttpResponse

public HttpResponse(IHttpResponseHeader responseHeader,
                    ByteBuffer[] body)
             throws IOException
constructor

Parameters:
responseHeader - the response header
body - the body
Throws:
IOException - if an io exception occurs
Method Detail

getStatus

public final int getStatus()
returns the status

Specified by:
getStatus in interface IHttpResponse
Returns:
the status

setStatus

public final void setStatus(int status)
sets the status

Specified by:
setStatus in interface IHttpResponse
Parameters:
status - the status

getServer

public String getServer()
gets the Server header parameter

Specified by:
getServer in interface IHttpResponse
Returns:
the Server header parameter

setServer

public void setServer(String server)
sets the Server header parameter

Specified by:
setServer in interface IHttpResponse
Parameters:
server - the Server header parameter

setDate

public void setDate(String date)
sets the Date header parameter

Specified by:
setDate in interface IHttpResponse
Parameters:
date - the Date header parameter

getDate

public String getDate()
returns the Date header parameter or null if the header is not set

Specified by:
getDate in interface IHttpResponse
Returns:
the Date header parameter or null if the header is not set

getReason

public final String getReason()
returns the reason

Specified by:
getReason in interface IHttpResponse
Returns:
the reason

setReason

public void setReason(String reason)
sets the reason

Specified by:
setReason in interface IHttpResponse
Parameters:
reason - the reason

getProtocol

public String getProtocol()
returns the protocol

Specified by:
getProtocol in interface IHttpMessage
Specified by:
getProtocol in interface IHttpResponse
Returns:
the protocol

getProtocolVersion

public String getProtocolVersion()
Returns the version of the protocol the message uses in the form majorVersion.minorVersion, for example, 1.1.

Specified by:
getProtocolVersion in interface IHttpMessage
Returns:
a String containing the protocol version number

setDate

public void setDate(long timeMillis)
set the date header of the response

Parameters:
timeMillis - the last modified time in millis

setExpireHeaders

public void setExpireHeaders(int expireSec)
set the caching expires headers of a response

Parameters:
expireSec - the expire time or 0 to set no-cache headers

setLastModifiedHeader

public void setLastModifiedHeader(long timeMillis)
set a last modified header of the response

Parameters:
timeMillis - the last modified time in millis

setProtocol

public final void setProtocol(String protocol)
sets the protocol

Specified by:
setProtocol in interface IHttpResponse
Parameters:
protocol - the protocol

getResponseHeader

public final IHttpResponseHeader getResponseHeader()
returns the response header

Specified by:
getResponseHeader in interface IHttpResponse
Returns:
the response header

toString

public String toString()
Description copied from class: Part

Overrides:
toString in class Part

getMessageHeader

public final IHttpMessageHeader getMessageHeader()
returns the message header

Specified by:
getMessageHeader in interface IHttpMessage
Returns:
the message header

setAttribute

public final void setAttribute(String name,
                               Object o)
Stores an attribute in this header. Attributes are reset between messages.

Attribute names should follow the same conventions as package names.

Specified by:
setAttribute in interface IHttpMessage
Parameters:
name - a String specifying the name of the attribute
o - the Object to be stored

getAttribute

public final Object getAttribute(String name)
Returns the value of the named attribute as an Object, or null if no attribute of the given name exists.

Attribute names should follow the same conventions as package names.

Specified by:
getAttribute in interface IHttpMessage
Parameters:
name - a String specifying the name of the attribute
Returns:
an Object containing the value of the attribute, or null if the attribute does not exist

getAttributeNames

public final Enumeration getAttributeNames()
Returns an Enumeration containing the names of the attributes available to this message. This method returns an empty Enumeration if the message has no attributes available to it.

Specified by:
getAttributeNames in interface IHttpMessage
Returns:
an Enumeration of strings containing the names of the message's attributes

getAttributeNameSet

public final Set<String> getAttributeNameSet()
Returns an Set containing the names of the attributes available to this messaget. This method returns an empty Set if the request has no attributes available to it.

Specified by:
getAttributeNameSet in interface IHttpMessage
Returns:
an Set of strings containing the names of the message's attributes

getContentLength

public final int getContentLength()
Returns the length, in bytes, of the message body and made available by the input stream, or -1 if the length is not known.

Specified by:
getContentLength in interface IHttpMessage
Returns:
an integer containing the length of the message body or -1 if the length is not known

setContentLength

public final void setContentLength(int length)
sets the content length in bytes

Specified by:
setContentLength in interface IHttpMessage
Parameters:
length - the content length in bytes

removeHopByHopHeaders

public final void removeHopByHopHeaders()
removes all hop-by-hop headers without Transfer-Encoding if set to chunked

Specified by:
removeHopByHopHeaders in interface IHttpMessage