mmhttp.protocol
Class SimpleResponse

java.lang.Object
  extended by mmhttp.protocol.Response
      extended by mmhttp.protocol.SimpleResponse

public class SimpleResponse
extends Response

The most basic implementation of Response. Just set the status, headers, and content of the response and it's ready to go. The content of SimpleResponse is stored in memory so it should not be used for large data sets.


Field Summary
 
Fields inherited from class mmhttp.protocol.Response
CRLF, DEFAULT_CONTENT_TYPE
 
Constructor Summary
SimpleResponse()
          Default constructor with no configuration.
SimpleResponse(int status)
          A convenience contructor that will set the port.
SimpleResponse(int status, java.lang.String content)
          A convenience contructor that will set the port and content.
 
Method Summary
protected  void addSpecificHeaders()
           
 byte[] getBytes()
          The HTTP response bytes are generated and returned.
 java.lang.String getContent()
           
 byte[] getContentBytes()
           
 int getContentSize()
          A method to get the size of the response content.
 java.lang.String getText()
          The HTTP response bytes are generated and converted into a String.
 void readyToSend(ResponseSender sender)
          Converts the response into HTTP compliant bytes and sends them through the ResponseSender.
 void setContent(byte[] value)
          Sets the content (body) of the response.
 void setContent(java.lang.String value)
          Sets the content (body) of the response.
 
Methods inherited from class mmhttp.protocol.Response
addHeader, addStandardHeaders, getContentType, getEncodedBytes, getHeader, getReasonPhrase, getReasonPhrase, getStatus, makeHttpHeaders, makeStandardHttpDateFormat, redirect, setContentType, setExpiresHeader, setLastModifiedHeader, setMaxAge, setStatus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleResponse

public SimpleResponse()
Default constructor with no configuration.


SimpleResponse

public SimpleResponse(int status)
A convenience contructor that will set the port.

Parameters:
status -

SimpleResponse

public SimpleResponse(int status,
                      java.lang.String content)
               throws java.lang.Exception
A convenience contructor that will set the port and content.

Parameters:
status -
content -
Throws:
java.lang.Exception
Method Detail

readyToSend

public void readyToSend(ResponseSender sender)
                 throws java.lang.Exception
Converts the response into HTTP compliant bytes and sends them through the ResponseSender.

Specified by:
readyToSend in class Response
Parameters:
sender -
Throws:
java.lang.Exception

setContent

public void setContent(java.lang.String value)
                throws java.lang.Exception
Sets the content (body) of the response. The provided string will be converted into bytes using the UTF-8 encoding.

Parameters:
value -
Throws:
java.lang.Exception

setContent

public void setContent(byte[] value)
Sets the content (body) of the response.

Parameters:
value -

getContent

public java.lang.String getContent()
Returns:
the content of the response as a String.

getContentBytes

public byte[] getContentBytes()
Returns:
the raw bytes of the response body.

getText

public java.lang.String getText()
The HTTP response bytes are generated and converted into a String.

Returns:
HTTP response string.

getBytes

public byte[] getBytes()
The HTTP response bytes are generated and returned.

Returns:
HTTP response bytes

getContentSize

public int getContentSize()
Description copied from class: Response
A method to get the size of the response content. Abstract because, who know how the response is built?

Specified by:
getContentSize in class Response
Returns:
the size of the content (body). Used in the Content-Length header.

addSpecificHeaders

protected void addSpecificHeaders()
Specified by:
addSpecificHeaders in class Response


Copyright © 2009 Micah Martin. All Rights Reserved.