com.monoserv.http
Class HttpResponse

java.lang.Object
  extended by com.monoserv.http.HttpResponse

public class HttpResponse
extends java.lang.Object

Creates a HTTP compliant response message based on the parameters given.


Field Summary
static java.lang.String CRLF
          Constant end of line character for the headers in the HTTP response
 
Constructor Summary
protected HttpResponse()
          Blank constructor - not used
 
Method Summary
 HttpParameters getHeaders()
          Returns the HTTP headers as an HttpParameters object.
 java.lang.String getHttpMessage()
          This will take all the information in the object and construct a http message from it.
 int getHttpResponseCode()
          Returns the HTTP reponse code (defaults to 501-'Not Implemented').
static java.lang.String GetHTTPText(int code)
          Returns a text based description of the HTTP code based on the supplied integer.
 double getHttpVersion()
          Returns the HTTP version as a double.
 HttpBody getMessageBody()
          Returns the object for the internal message body object.
 java.lang.String getStatusLine()
          Returns the status line for the HTTP response.
static HttpResponse makeResponse()
          Creates a generic response message.
static HttpResponse makeResponse(int responseCode)
          Creates a generic HTTP response message using the supplied integer as the response code.
static HttpResponse makeResponse(int responseCode, double httpVersion)
          Creates a HTTP response message with the response code and using the supplied HTTP version number As of right now, creates the HttpResponse object, sets the Response code and the HTTP version and returns it.
 void setHeaders(HttpParameters headerValues)
          Saves the supplied parameters as the actual headers for this message.
 void setHttpResponseCode(int httpResponseCode)
          Sets the HTTP response code to a new value.
 void setHttpVersion(double httpVersion)
          Sets the HTTP version to a new value.
 void setMessageBody(HttpBody theBody)
          Stores the body contents per the data passed in.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CRLF

public static java.lang.String CRLF
Constant end of line character for the headers in the HTTP response

Constructor Detail

HttpResponse

protected HttpResponse()
Blank constructor - not used

Method Detail

getHeaders

public HttpParameters getHeaders()
Returns the HTTP headers as an HttpParameters object.

Returns:
HttpParameters An object representing all the headers

setHeaders

public void setHeaders(HttpParameters headerValues)
Saves the supplied parameters as the actual headers for this message.

Parameters:
headerValues - The values stored inside the object to use.

getMessageBody

public HttpBody getMessageBody()
Returns the object for the internal message body object.

Returns:
HttpBody An object representing the data for the body

setMessageBody

public void setMessageBody(HttpBody theBody)
Stores the body contents per the data passed in.

Parameters:
theBody - The object representing the HTTP message body to store.

getHttpResponseCode

public int getHttpResponseCode()
Returns the HTTP reponse code (defaults to 501-'Not Implemented').

Returns:
int The HTTP response code stored in the object

setHttpResponseCode

public void setHttpResponseCode(int httpResponseCode)
Sets the HTTP response code to a new value. Minimal checking is done to ensure a valid HTTP response code. Requirements: Must be greater than or equal to 100, less than or equal to 505. See GetHTTPText(int) for a list of valid HTTP response codes.

Parameters:
httpResponseCode - The new HTTP response code to be used.
See Also:
GetHTTPText(int)

getHttpVersion

public double getHttpVersion()
Returns the HTTP version as a double. Most likely either '1.0' or '1.1' depending on how the object was constructed.

Returns:
double The HTTP version.

setHttpVersion

public void setHttpVersion(double httpVersion)
                    throws GenericHTTPException
Sets the HTTP version to a new value. Must be greater than .5 and less than 2.0 at the moment.

Parameters:
httpVersion - The new HTTP version to use
Throws:
GenericHTTPException - If the value is less than 0.5 or greater than 2.0

getStatusLine

public java.lang.String getStatusLine()
                               throws InvalidHTTPResponseCode
Returns the status line for the HTTP response. Based on RFC 2616, it follows the following syntax.
Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF
Where SP is a space, CRLF is "\r\n" If the HTTP version is null, then a default of 1.0 is used. If an error occuprs while constructing the line, an exception is thrown.

Returns:
String A textual representaion of the status line. Null on error.
Throws:
InvalidHTTPResponseCode - If the response code is not valid (must be not null, greater than or equal to 100, less than or equal to 505).

makeResponse

public static HttpResponse makeResponse()
                                 throws GenericHTTPException
Creates a generic response message. Shortcut for HttpResponse.makeResponse(501);

Returns:
HttpResponse A HTTP response object with a response code of 501 and a version of 1.1
Throws:
GenericHTTPException - If anything fails in creating it

makeResponse

public static HttpResponse makeResponse(int responseCode)
                                 throws GenericHTTPException
Creates a generic HTTP response message using the supplied integer as the response code. Shortcut for HttpResponse.makeResponse(responseCode, 1.1);

Parameters:
responseCode - The HTTP response code to use
Returns:
HttpResponse HTTP response object with the supplied response code and a HTTP version of 1.1
Throws:
GenericHTTPException - If anything fails in creating it

makeResponse

public static HttpResponse makeResponse(int responseCode,
                                        double httpVersion)
                                 throws GenericHTTPException
Creates a HTTP response message with the response code and using the supplied HTTP version number As of right now, creates the HttpResponse object, sets the Response code and the HTTP version and returns it.

Parameters:
responseCode - The HTTP response code to use for the object
httpVersion - The HTTP version to use for this message.
Returns:
HttpResponse HTTP response object with the supplied response code and HTTP version
Throws:
GenericHTTPException - If the response code or http version are invalid
See Also:
setHttpResponseCode(int), setHttpVersion(double)

getHttpMessage

public java.lang.String getHttpMessage()
This will take all the information in the object and construct a http message from it.

Returns:
String A string representing the HTTP message for this object

GetHTTPText

public static java.lang.String GetHTTPText(int code)
                                    throws InvalidHTTPResponseCode
Returns a text based description of the HTTP code based on the supplied integer. If the supplied code is not a valid HTTP message, then "Unknown" is returned. Else, the appropiate string is returned. Valid codes are (Inclusive) 100-101 200-206 300-307 400-417 500-505

Parameters:
code - The HTTP code to reference.
Returns:
String A string representing the HTTP code
Throws:
InvalidHTTPResponseCode - If the supplied code is not a valid HTTP code. See valid codes reference