com.radekzitek.userver.http
Class HttpMessage

java.lang.Object
  extended bycom.radekzitek.userver.http.HttpMessage
Direct Known Subclasses:
HttpRequestMessage, HttpResponseMessage

public abstract class HttpMessage
extends java.lang.Object

Class representing any of the two types of HTTP messages - request and response.

Author:
rzitek

Field Summary
protected  byte[] body
          Budy of the message in a byte array.
private static byte[] CRLF
          CRLF
protected  java.util.Hashtable headers
          Message headers.
private  boolean headResponse
          Used to flag that the message is response to a HEAD.
private static org.apache.log4j.Logger LOG
          Log4j logger.
protected  HttpStartLine startLine
          Startline of the message.
protected  java.util.Hashtable trailers
          Message trailers.
 
Constructor Summary
HttpMessage()
          Default contructor of the HttpMassage creates an empty message.
 
Method Summary
 void clear()
          Empties the message content.
 byte[] getBody()
          Gets the body of the message.
 long getBodyLength()
          Based on the start line and headers returns the expected length of the message body.
 HttpHeader getHeader(java.lang.String fieldName)
          Retrieves an individual header of the message.
 java.util.Hashtable getHeaders()
          Retrieves all headers of the message.
 HttpHeader getTrailer(java.lang.String fieldName)
          Retrieves individual trailer from the message.
 java.util.Hashtable getTrailers()
          Retrieves all trailers of the message.
 boolean isBodyless()
           
 boolean isChunked()
           
 boolean isHeadResponse()
           
 HttpHeader putHeader(HttpHeader header)
          Puts individual header into the message.
 HttpHeader putTrailer(HttpHeader trailer)
          Puts individual trailer into the message.
 void setBody(byte[] body)
          Sets the body byte array.
 void setHeaders(java.util.Hashtable headers)
          Sets the headers hashtable.
 void setHeadResponse(boolean headResponse)
           
 void setTrailers(java.util.Hashtable trailers)
          Sets the trailes hashtable.
 boolean shouldClose()
           
 java.lang.String toString()
          Returns String representation of the mssage.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CRLF

private static final byte[] CRLF
CRLF


headResponse

private boolean headResponse
Used to flag that the message is response to a HEAD.


LOG

private static final org.apache.log4j.Logger LOG
Log4j logger.


body

protected byte[] body
Budy of the message in a byte array.


headers

protected java.util.Hashtable headers
Message headers.


startLine

protected HttpStartLine startLine
Startline of the message.


trailers

protected java.util.Hashtable trailers
Message trailers.

Constructor Detail

HttpMessage

public HttpMessage()
Default contructor of the HttpMassage creates an empty message.

Method Detail

clear

public void clear()
Empties the message content.


getBody

public byte[] getBody()
Gets the body of the message.

Returns:
Returns the body of the message.

getHeader

public HttpHeader getHeader(java.lang.String fieldName)
Retrieves an individual header of the message.

Parameters:
fieldName - Name of the header to be retrieved.
Returns:
Returns the header retrieved or null if the requested header was not found.

getHeaders

public java.util.Hashtable getHeaders()
Retrieves all headers of the message.

Returns:
Returns the headers in a hashtable.

getTrailer

public HttpHeader getTrailer(java.lang.String fieldName)
Retrieves individual trailer from the message.

Parameters:
fieldName - Name of the trailer to be retrieved.
Returns:
Returns the trailer or null if the requested trailer was not found in the message.

getTrailers

public java.util.Hashtable getTrailers()
Retrieves all trailers of the message.

Returns:
Returns the trailers in a hashtable.

putHeader

public HttpHeader putHeader(HttpHeader header)
Puts individual header into the message.

Parameters:
header - The header to be included in the message.
Returns:
the header inserted

putTrailer

public HttpHeader putTrailer(HttpHeader trailer)
Puts individual trailer into the message.

Parameters:
trailer - The trailer to be included in the message.
Returns:
the trailer inserted

setBody

public void setBody(byte[] body)
Sets the body byte array.

Parameters:
body - The body to set.

setHeaders

public void setHeaders(java.util.Hashtable headers)
Sets the headers hashtable.

Parameters:
headers - The headers to set.

setTrailers

public void setTrailers(java.util.Hashtable trailers)
Sets the trailes hashtable.

Parameters:
trailers - The trailers to set.

toString

public java.lang.String toString()
Returns String representation of the mssage. This is not to be used to output the message via connections.

Returns:
Message in the string form.

getBodyLength

public long getBodyLength()
Based on the start line and headers returns the expected length of the message body.

Returns:
Returns positive integre if it determines the length of the body. Returns 0 if it determines that there is a body but length can not be determined (for example uses chunked encoding). Returns -1 if the message has no body.

isChunked

public boolean isChunked()

isBodyless

public boolean isBodyless()

shouldClose

public boolean shouldClose()

isHeadResponse

public boolean isHeadResponse()
Returns:
Returns the headResponse.

setHeadResponse

public void setHeadResponse(boolean headResponse)
Parameters:
headResponse - The headResponse to set.