More information: http://www.cs.berkeley.edu/~mdw/proj/seda/

seda.sandStorm.lib.http
Class httpResponse

java.lang.Object
  |
  +--seda.sandStorm.lib.http.httpResponse
All Implemented Interfaces:
httpConst, QueueElementIF
Direct Known Subclasses:
httpBadRequestResponse, httpInternalServerErrorResponse, httpNotFoundResponse, httpOKResponse, httpRedirectResponse, httpServiceUnavailableResponse

public abstract class httpResponse
extends java.lang.Object
implements httpConst, QueueElementIF

This is an abstract class corresponding to an HTTP response. Use one of the subclasses (such as httpOKResponse or httpNotFoundResponse) to push responses back to the client.

Author:
Matt Welsh
See Also:
httpOKResponse, httpNotFoundResponse

Field Summary
protected  int code
          The code corresponding to the response.
protected  BufferElement combinedData
          The actual data of the response.
protected  int contentLength
          The content-length header.
protected  java.lang.String contentType
          The MIME type of the response.
static java.lang.String DEFAULT_MIME_TYPE
          The default MIME type for responses, which is "text/html".
protected static java.lang.String defaultHeader
          The default response header.
protected  BufferElement header
          The header for the response.
protected  BufferElement payload
          The payload for the response.
static int RESPONSE_BAD_REQUEST
          Code corresponding to '400 Bad Request'.
static int RESPONSE_INTERNAL_SERVER_ERROR
          Code corresponding to '500 Internal Server Error'.
static int RESPONSE_NOT_FOUND
          Code corresponding to '404 Not Found'.
static int RESPONSE_OK
          Code corresponding to '200 OK'.
static int RESPONSE_REDIRECT
          Code corresponding to '301 Moved Permanently'.
static int RESPONSE_SERVICE_UNAVAILABLE
          Code corresponding to '503 Service Unavailable'.
 
Fields inherited from interface seda.sandStorm.lib.http.httpConst
CRLF, DEFAULT_HTTP_PORT, HTTP_VERSION, WRITE_CLOG_THRESHOLD
 
Constructor Summary
protected httpResponse(int code, java.lang.String contentType)
          Create an httpResponse with the given response code with no payload.
protected httpResponse(int code, java.lang.String contentType, BufferElement payload)
          Create an httpResponse with the given response code with the given payload.
protected httpResponse(int code, java.lang.String contentType, BufferElement payload, int contentLength)
          Create an httpResponse with the given response code with the given payload.
protected httpResponse(int code, java.lang.String contentType, int payloadSize)
          Create an httpResponse with the the given response code, with an empty payload of the given size.
protected httpResponse(int code, java.lang.String contentType, int payloadSize, SinkIF compQ)
          Create an httpResponse with the the given response code, with an empty payload of the given size.
 
Method Summary
 BufferElement[] getBuffers(boolean sendHeader)
          Get an array of BufferElements corresponding to this response.
static java.lang.String getDefaultHeader()
          Return the default header string sent in all responses.
protected abstract  java.lang.String getEntityHeader()
          Return the entity header as a String.
 BufferElement getHeader()
          Returns the header for this response.
 BufferElement getPayload()
          Returns the payload for this response.
static void setDefaultHeader(java.lang.String defhdr)
          Set the default header string sent in all responses.
 void setPayload(BufferElement payload)
          Used to set the payload after creating the response with an empty payload.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESPONSE_OK

public static final int RESPONSE_OK
Code corresponding to '200 OK'.

RESPONSE_REDIRECT

public static final int RESPONSE_REDIRECT
Code corresponding to '301 Moved Permanently'.

RESPONSE_BAD_REQUEST

public static final int RESPONSE_BAD_REQUEST
Code corresponding to '400 Bad Request'.

RESPONSE_NOT_FOUND

public static final int RESPONSE_NOT_FOUND
Code corresponding to '404 Not Found'.

RESPONSE_INTERNAL_SERVER_ERROR

public static final int RESPONSE_INTERNAL_SERVER_ERROR
Code corresponding to '500 Internal Server Error'.

RESPONSE_SERVICE_UNAVAILABLE

public static final int RESPONSE_SERVICE_UNAVAILABLE
Code corresponding to '503 Service Unavailable'.

DEFAULT_MIME_TYPE

public static final java.lang.String DEFAULT_MIME_TYPE
The default MIME type for responses, which is "text/html".

code

protected int code
The code corresponding to the response.

defaultHeader

protected static java.lang.String defaultHeader
The default response header.

combinedData

protected BufferElement combinedData
The actual data of the response.

header

protected BufferElement header
The header for the response.

payload

protected BufferElement payload
The payload for the response.

contentType

protected java.lang.String contentType
The MIME type of the response.

contentLength

protected int contentLength
The content-length header.
Constructor Detail

httpResponse

protected httpResponse(int code,
                       java.lang.String contentType,
                       BufferElement payload)
Create an httpResponse with the given response code with the given payload.
Parameters:
code - The response code; should be one of the constants from httpResponse.RESPONSE_*.
contentType - The MIME type of the response content. Should not be CRLF-terminated.
payload - The payload of the response.

httpResponse

protected httpResponse(int code,
                       java.lang.String contentType,
                       BufferElement payload,
                       int contentLength)
Create an httpResponse with the given response code with the given payload.
Parameters:
code - The response code; should be one of the constants from httpResponse.RESPONSE_*.
contentType - The MIME type of the response content. Should not be CRLF-terminated.
payload - The payload of the response.
contentLength - The contentLength to place in the header.

httpResponse

protected httpResponse(int code,
                       java.lang.String contentType)
Create an httpResponse with the given response code with no payload. A payload can be assigned later using setPayload().
Parameters:
code - The response code; should be one of the constants from httpResponse.RESPONSE_*.
contentType - The MIME type of the response content. Should not be CRLF-terminated.
payload - The payload of the response.

httpResponse

protected httpResponse(int code,
                       java.lang.String contentType,
                       int payloadSize,
                       SinkIF compQ)
Create an httpResponse with the the given response code, with an empty payload of the given size. This can be more efficient than providing a payload separately, as the entire contents of the httpResponse can be sent as a single TCP packet. The payload can be filled in using the getPayload() method.
Parameters:
code - The response code; should be one of the constants from httpResponse.RESPONSE_*.
contentType - The MIME type of the response content. Should not be CRLF-terminated.
payloadSize - The size of the payload to allocate.
compQ - The completion queue for the payload.

httpResponse

protected httpResponse(int code,
                       java.lang.String contentType,
                       int payloadSize)
Create an httpResponse with the the given response code, with an empty payload of the given size. This can be more efficient than providing a payload separately, as the entire contents of the httpResponse can be sent as a single TCP packet. The payload can be filled in using the getPayload() method.
Parameters:
code - The response code; should be one of the constants from httpResponse.RESPONSE_*.
contentType - The MIME type of the response content. Should not be CRLF-terminated.
payloadSize - The size of the payload to allocate.
Method Detail

getEntityHeader

protected abstract java.lang.String getEntityHeader()
Return the entity header as a String. Must be implemented by subclasses of httpResponse.

setPayload

public void setPayload(BufferElement payload)
Used to set the payload after creating the response with an empty payload. XXX Should not be used if the payload was allocated by this response (that is, if the payloadSize was specified in the constructor).

getHeader

public BufferElement getHeader()
Returns the header for this response.

getPayload

public BufferElement getPayload()
Returns the payload for this response.

setDefaultHeader

public static void setDefaultHeader(java.lang.String defhdr)
Set the default header string sent in all responses.

getDefaultHeader

public static java.lang.String getDefaultHeader()
Return the default header string sent in all responses.

getBuffers

public BufferElement[] getBuffers(boolean sendHeader)
Get an array of BufferElements corresponding to this response. Used internally when sending the response to a client.
Parameters:
sendHeader - Indicate whether the header should be included.

More information: http://www.cs.berkeley.edu/~mdw/proj/seda/