mmhttp.protocol
Class Response

java.lang.Object
  extended by mmhttp.protocol.Response
Direct Known Subclasses:
ChunkedResponse, InputStreamResponse, SimpleResponse

public abstract class Response
extends java.lang.Object

The base class for building HTTP 1.1 compliant responses.


Field Summary
protected static java.lang.String CRLF
           
static java.lang.String DEFAULT_CONTENT_TYPE
           
 
Constructor Summary
Response()
          Empty constructor.
Response(int status)
          A constructor that sets the status of the response.
 
Method Summary
 void addHeader(java.lang.String key, java.lang.String value)
          Add an header to the response.
protected abstract  void addSpecificHeaders()
           
protected  void addStandardHeaders()
           
abstract  int getContentSize()
          A method to get the size of the response content.
 java.lang.String getContentType()
           
 byte[] getEncodedBytes(java.lang.String value)
           
 java.lang.String getHeader(java.lang.String key)
          Get the value of a header already set on this response.
protected  java.lang.String getReasonPhrase()
           
static java.lang.String getReasonPhrase(int status)
          Provideds the HTTP description for each response status code.
 int getStatus()
           
 java.lang.String makeHttpHeaders()
          Build the headers portion of the response.
static java.text.SimpleDateFormat makeStandardHttpDateFormat()
          HTTP Protocol fluff.
abstract  void readyToSend(ResponseSender sender)
          To be called when response has been prepared and is ready to go out the door.
 void redirect(java.lang.String location)
          Configures this response to be a redirect to the specified URL.
 void setContentType(java.lang.String type)
          Sets the Content-Type header.
 void setExpiresHeader(java.lang.String date)
          Gives the response an expiration data.
 void setLastModifiedHeader(java.lang.String date)
          Tells the client when the requested resource was last modified.
 void setMaxAge(int age)
          Configures the response for chaching by setting the Cache-Control header to 'max-age=<age>'.
 void setStatus(int status)
          Sets the status of the response
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CONTENT_TYPE

public static final java.lang.String DEFAULT_CONTENT_TYPE
See Also:
Constant Field Values

CRLF

protected static final java.lang.String CRLF
See Also:
Constant Field Values
Constructor Detail

Response

public Response()
Empty constructor.


Response

public Response(int status)
A constructor that sets the status of the response.

Parameters:
status -
Method Detail

makeStandardHttpDateFormat

public static java.text.SimpleDateFormat makeStandardHttpDateFormat()
HTTP Protocol fluff.

Returns:
an HTTP date format

readyToSend

public abstract void readyToSend(ResponseSender sender)
                          throws java.lang.Exception
To be called when response has been prepared and is ready to go out the door.

Parameters:
sender -
Throws:
java.lang.Exception

addSpecificHeaders

protected abstract void addSpecificHeaders()

getContentSize

public abstract int getContentSize()
A method to get the size of the response content. Abstract because, who know how the response is built?

Returns:
number of bytes in content

getStatus

public int getStatus()
Returns:
the status

setStatus

public void setStatus(int status)
Sets the status of the response

Parameters:
status -

makeHttpHeaders

public java.lang.String makeHttpHeaders()
Build the headers portion of the response.

Returns:
headers string

getContentType

public java.lang.String getContentType()
Returns:
the Content-Type header of the response

setContentType

public void setContentType(java.lang.String type)
Sets the Content-Type header.

Parameters:
type -

redirect

public void redirect(java.lang.String location)
Configures this response to be a redirect to the specified URL.

Parameters:
location -

setMaxAge

public void setMaxAge(int age)
Configures the response for chaching by setting the Cache-Control header to 'max-age=<age>'. This response should be considered fresh, by the client, for <age> seconds.

Parameters:
age -

setLastModifiedHeader

public void setLastModifiedHeader(java.lang.String date)
Tells the client when the requested resource was last modified. Sets the Last-Modified header.

Parameters:
date -

setExpiresHeader

public void setExpiresHeader(java.lang.String date)
Gives the response an expiration data. Sets the Expires header.

Parameters:
date -

addHeader

public void addHeader(java.lang.String key,
                      java.lang.String value)
Add an header to the response.

Parameters:
key -
value -

getHeader

public java.lang.String getHeader(java.lang.String key)
Get the value of a header already set on this response. Will return null if the specified header is not contained.

Parameters:
key -
Returns:
header value

getEncodedBytes

public byte[] getEncodedBytes(java.lang.String value)
                       throws java.lang.Exception
Parameters:
value -
Returns:
a byte array representation of value encoded in UTF-8.
Throws:
java.lang.Exception

addStandardHeaders

protected void addStandardHeaders()

getReasonPhrase

protected java.lang.String getReasonPhrase()

getReasonPhrase

public static java.lang.String getReasonPhrase(int status)
Provideds the HTTP description for each response status code.

Parameters:
status -
Returns:
response phrase


Copyright © 2009 Micah Martin. All Rights Reserved.