org.xlightweb
Class HttpResponseHeader

Package class diagram package HttpResponseHeader
java.lang.Object
  extended by org.xlightweb.Header
      extended by org.xlightweb.HttpResponseHeader
All Implemented Interfaces:
Cloneable, IHeader, IHttpMessageHeader, IHttpResponseHeader

public class HttpResponseHeader
extends Header
implements IHttpResponseHeader

http response header


Field Summary
 
Fields inherited from interface org.xlightweb.IHttpMessageHeader
DEFAULT_ENCODING
 
Constructor Summary
HttpResponseHeader(int statusCode)
          constructor
HttpResponseHeader(int statusCode, String contentType)
          constructor
HttpResponseHeader(int statusCode, String contentType, String reason)
          constructor
HttpResponseHeader(String contentType)
          constructor.
 
Method Summary
protected  Object clone()
          
 boolean containsHeader(String headername)
          Returns a boolean indicating whether the named header has already been set.
 IHttpResponseHeader copy()
          creates a copy of this header
 void copyHeaderFrom(HttpResponseHeader otherHeader, String... upperExcludenames)
          
 void copyHeaderFrom(IHttpMessageHeader otherHeader, String... upperExcludenames)
          copy the headers
 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
 String getHeader(String headername)
          Returns the value of the specified header as a String.
 List<String> getHeaderList(String headername)
          Returns all the values of the specified header as an List of String objects.
 Set<String> getHeaderNameSet()
          Returns an set of all the header names.
 String getProtocol()
          Returns the name and version of the protocol the message uses in the form protocol/majorVersion.minorVersion, for example, HTTP/1.1.
 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
 String getServer()
          gets the Server header parameter
 int getStatus()
          returns the status
protected  boolean onHeaderAdded(String headername, String headervalue)
          
protected  boolean onHeaderRemoved(String headername)
          
 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 contentLength)
          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.Header
addHeader, addHeaderLine, addHeaderlines, getAccept, getCharacterEncoding, getContentType, getDisposition, getDispositionParam, getDispositionType, getHeaderNames, getHeaders, getTransferEncoding, removeHeader, setContentType, setHeader, setTransferEncoding
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.xlightweb.IHttpResponseHeader
getProtocol
 
Methods inherited from interface org.xlightweb.IHttpMessageHeader
copyHeaderFrom, getAttribute, getAttributeNames, getAttributeNameSet, getContentLength, getProtocolVersion, removeHopByHopHeaders, setAttribute, setContentLength
 
Methods inherited from interface org.xlightweb.IHeader
addHeader, addHeaderLine, addHeaderlines, getCharacterEncoding, getContentType, getDisposition, getDispositionParam, getDispositionType, getHeaderNames, getHeaders, getTransferEncoding, removeHeader, setContentType, setHeader, setTransferEncoding
 

Constructor Detail

HttpResponseHeader

public HttpResponseHeader(int statusCode)
constructor

Parameters:
statusCode - the status code

HttpResponseHeader

public HttpResponseHeader(String contentType)
constructor. The status will be set to 200

Parameters:
contentType - the content type

HttpResponseHeader

public HttpResponseHeader(int statusCode,
                          String contentType)
constructor

Parameters:
statusCode - the status code
contentType - the content type

HttpResponseHeader

public HttpResponseHeader(int statusCode,
                          String contentType,
                          String reason)
constructor

Parameters:
statusCode - the status code
contentType - the content type
reason - the reason
Method Detail

copyHeaderFrom

public final void copyHeaderFrom(HttpResponseHeader otherHeader,
                                 String... upperExcludenames)


getStatus

public final int getStatus()
returns the status

Specified by:
getStatus in interface IHttpResponseHeader
Returns:
the status

setStatus

public final void setStatus(int status)
sets the status

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

getReason

public final String getReason()
returns the reason

Specified by:
getReason in interface IHttpResponseHeader
Returns:
the reason

setReason

public final void setReason(String reason)
sets the reason

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

setExpireHeaders

public final 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 final void setLastModifiedHeader(long timeMillis)
set a last modified header of the response

Parameters:
timeMillis - the last modified time in millis

setDate

public final void setDate(long timeMillis)
set the date 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 IHttpResponseHeader
Parameters:
protocol - the protocol

getDate

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

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

setDate

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

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

setServer

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

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

getServer

public final String getServer()
gets the Server header parameter

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

onHeaderAdded

protected final boolean onHeaderAdded(String headername,
                                      String headervalue)


onHeaderRemoved

protected final boolean onHeaderRemoved(String headername)


getHeaderNameSet

public final Set<String> getHeaderNameSet()
Returns an set of all the header names. If the part has no headers, this method returns an empty Set.

Specified by:
getHeaderNameSet in interface IHeader
Returns:
an Set of all the header names

getHeaderList

public final List<String> getHeaderList(String headername)
Returns all the values of the specified header as an List of String objects.

Some headers, such as Accept-Language can be set by part producer as several headers each with a different value rather than sending the header as a comma separated list.

Specified by:
getHeaderList in interface IHeader
Parameters:
headername - a String specifying the header name
Returns:
an List containing the values of the requested header. If the part does not have any headers of that name return an empty enumeration.

getHeader

public final String getHeader(String headername)
Returns the value of the specified header as a String. If the part did not include a header of the specified name, this method returns null. If there are multiple headers with the same name, this method returns the first head in the part.

Specified by:
getHeader in interface IHeader
Parameters:
headername - a String specifying the header name
Returns:
a String containing the value of the requested header, or null if the part does not have a header of that name

containsHeader

public final boolean containsHeader(String headername)
Returns a boolean indicating whether the named header has already been set.

Specified by:
containsHeader in interface IHeader
Returns:
true if the named header has already been set; false otherwise

clone

protected final Object clone()
                      throws CloneNotSupportedException

Throws:
CloneNotSupportedException

copy

public final IHttpResponseHeader copy()
creates a copy of this header

Specified by:
copy in interface IHttpMessageHeader
Specified by:
copy in interface IHttpResponseHeader
Returns:
return the copy

toString

public String toString()

Overrides:
toString in class Header

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 IHttpMessageHeader
Returns:
a String containing the protocol version number

getProtocol

public String getProtocol()
Returns the name and version of the protocol the message uses in the form protocol/majorVersion.minorVersion, for example, HTTP/1.1.

Specified by:
getProtocol in interface IHttpMessageHeader
Returns:
a String containing the protocol name and version number

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 IHttpMessageHeader
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 IHttpMessageHeader
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

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 IHttpMessageHeader
Returns:
an Set of strings containing the names of the message's attributes

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 IHttpMessageHeader
Returns:
an Enumeration 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 IHttpMessageHeader
Returns:
an integer containing the length of the message body or -1 if the length is not known

setContentLength

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

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

copyHeaderFrom

public final void copyHeaderFrom(IHttpMessageHeader otherHeader,
                                 String... upperExcludenames)
copy the headers

Specified by:
copyHeaderFrom in interface IHttpMessageHeader
Parameters:
otherHeader - the other header
upperExcludenames - the header names to exclude

removeHopByHopHeaders

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

Specified by:
removeHopByHopHeaders in interface IHttpMessageHeader