org.mortbay.http
Class HttpResponse

java.lang.Object
  |
  +--org.mortbay.http.HttpMessage
        |
        +--org.mortbay.http.HttpResponse

public class HttpResponse
extends HttpMessage

HTTP Response. This class manages the headers, trailers and content streams of a HTTP response. It can be used for receiving or generating requests. This class is not synchronized. It should be explicitly synchronized if it is used by multiple threads.

Version:
$Id: HttpResponse.java,v 1.6 2001/10/25 05:36:01 gregwilkins Exp $
Author:
Greg Wilkins (gregw)
See Also:
HttpRequest

Field Summary
static int __100_Continue
           
static int __101_Switching_Protocols
           
static int __200_OK
           
static int __201_Created
           
static int __202_Accepted
           
static int __203_Non_Authoritative_Information
           
static int __204_No_Content
           
static int __205_Reset_Content
           
static int __206_Partial_Content
           
static int __300_Multiple_Choices
           
static int __301_Moved_Permanently
           
static int __302_Moved_Temporarily
           
static int __303_See_Other
           
static int __304_Not_Modified
           
static int __305_Use_Proxy
           
static int __400_Bad_Request
           
static int __401_Unauthorized
           
static int __402_Payment_Required
           
static int __403_Forbidden
           
static int __404_Not_Found
           
static int __405_Method_Not_Allowed
           
static int __406_Not_Acceptable
           
static int __407_Proxy_Authentication_Required
           
static int __408_Request_Timeout
           
static int __409_Conflict
           
static int __410_Gone
           
static int __411_Length_Required
           
static int __412_Precondition_Failed
           
static int __413_Request_Entity_Too_Large
           
static int __414_Request_URI_Too_Large
           
static int __415_Unsupported_Media_Type
           
static int __416_Requested_Range_Not_Satisfiable
           
static int __417_Expectation_Failed
           
static int __500_Internal_Server_Error
           
static int __501_Not_Implemented
           
static int __502_Bad_Gateway
           
static int __503_Service_Unavailable
           
static int __504_Gateway_Timeout
           
static int __505_HTTP_Version_Not_Supported
           
static byte[] __Continue
           
static java.util.HashMap __statusMsg
           
 
Fields inherited from class org.mortbay.http.HttpMessage
__HTTP_0_9, __HTTP_1_0, __HTTP_1_1, __HTTP_1_X, __MSG_BAD, __MSG_EDITABLE, __MSG_RECEIVED, __MSG_SENDING, __MSG_SENT, __state
 
Constructor Summary
HttpResponse()
          Constructor.
HttpResponse(HttpConnection connection)
          Constructor.
 
Method Summary
 void addSetCookie(Cookie cookie)
          Add a Set-Cookie field.
 void addSetCookie(Cookie cookie, boolean cookie2)
          Add a Set-Cookie field.
 void addSetCookie(java.lang.String name, java.lang.String value)
          Add a Set-Cookie field.
 void commit()
          Commit the message.
 void commitHeader()
           
 void destroy()
          Destroy the response.
 HandlerContext getHandlerContext()
          Get the HandlerContext handling this reponse.
 java.lang.String getReason()
           
 HttpRequest getRequest()
          Get the HTTP Request.
 int getStatus()
           
 boolean isDirty()
           
 void readHeader(ChunkableInputStream in)
          Not Implemented.
 void recycle(HttpConnection connection)
          Recycle the response.
 void reset()
          Reset the response.
 void sendError(int code)
          Sends an error response to the client using the specified status code and no default message.
 void sendError(int code, java.lang.String message)
          Sends an error response to the client using the specified status code and no default message.
 void sendError(int code, java.lang.Throwable exception)
          Send Error Response.
 void sendRedirect(java.lang.String location)
          Sends a redirect response to the client using the specified redirect location URL.
 void setReason(java.lang.String reason)
           
 void setStatus(int status)
           
 void writeHeader(java.io.Writer writer)
           
 
Methods inherited from class org.mortbay.http.HttpMessage
acceptTrailer, addDateField, addField, addIntField, complete, containsField, getCharacterEncoding, getDateField, getDotVersion, getField, getFieldNames, getFieldValues, getFieldValues, getHeader, getHttpConnection, getInputStream, getIntField, getMimeType, getOutputStream, getState, getTrailer, getVersion, isCommitted, removeField, setAcceptTrailer, setCurrentTime, setDateField, setDateField, setField, setField, setIntField, setState, setVersion, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

__100_Continue

public static final int __100_Continue

__101_Switching_Protocols

public static final int __101_Switching_Protocols

__200_OK

public static final int __200_OK

__201_Created

public static final int __201_Created

__202_Accepted

public static final int __202_Accepted

__203_Non_Authoritative_Information

public static final int __203_Non_Authoritative_Information

__204_No_Content

public static final int __204_No_Content

__205_Reset_Content

public static final int __205_Reset_Content

__206_Partial_Content

public static final int __206_Partial_Content

__300_Multiple_Choices

public static final int __300_Multiple_Choices

__301_Moved_Permanently

public static final int __301_Moved_Permanently

__302_Moved_Temporarily

public static final int __302_Moved_Temporarily

__303_See_Other

public static final int __303_See_Other

__304_Not_Modified

public static final int __304_Not_Modified

__305_Use_Proxy

public static final int __305_Use_Proxy

__400_Bad_Request

public static final int __400_Bad_Request

__401_Unauthorized

public static final int __401_Unauthorized

__402_Payment_Required

public static final int __402_Payment_Required

__403_Forbidden

public static final int __403_Forbidden

__404_Not_Found

public static final int __404_Not_Found

__405_Method_Not_Allowed

public static final int __405_Method_Not_Allowed

__406_Not_Acceptable

public static final int __406_Not_Acceptable

__407_Proxy_Authentication_Required

public static final int __407_Proxy_Authentication_Required

__408_Request_Timeout

public static final int __408_Request_Timeout

__409_Conflict

public static final int __409_Conflict

__410_Gone

public static final int __410_Gone

__411_Length_Required

public static final int __411_Length_Required

__412_Precondition_Failed

public static final int __412_Precondition_Failed

__413_Request_Entity_Too_Large

public static final int __413_Request_Entity_Too_Large

__414_Request_URI_Too_Large

public static final int __414_Request_URI_Too_Large

__415_Unsupported_Media_Type

public static final int __415_Unsupported_Media_Type

__416_Requested_Range_Not_Satisfiable

public static final int __416_Requested_Range_Not_Satisfiable

__417_Expectation_Failed

public static final int __417_Expectation_Failed

__500_Internal_Server_Error

public static final int __500_Internal_Server_Error

__501_Not_Implemented

public static final int __501_Not_Implemented

__502_Bad_Gateway

public static final int __502_Bad_Gateway

__503_Service_Unavailable

public static final int __503_Service_Unavailable

__504_Gateway_Timeout

public static final int __504_Gateway_Timeout

__505_HTTP_Version_Not_Supported

public static final int __505_HTTP_Version_Not_Supported

__statusMsg

public static final java.util.HashMap __statusMsg

__Continue

public static final byte[] __Continue
Constructor Detail

HttpResponse

public HttpResponse()
Constructor.

HttpResponse

public HttpResponse(HttpConnection connection)
Constructor.
Parameters:
connection -  
Method Detail

getHandlerContext

public HandlerContext getHandlerContext()
Get the HandlerContext handling this reponse.
Returns:
 

isDirty

public boolean isDirty()
Overrides:
isDirty in class HttpMessage
Returns:
true if the message has been modified.

reset

public void reset()
Reset the response. Clears any data that exists in the buffer as well as the status code. If the response has been committed, this method throws an IllegalStateException.
Throws:
java.lang.IllegalStateException - if the response has already been committed

getRequest

public HttpRequest getRequest()
Get the HTTP Request. Get the HTTP Request associated with this response.
Returns:
associated request

readHeader

public void readHeader(ChunkableInputStream in)
                throws java.io.IOException
Not Implemented.
Parameters:
in -  
Throws:
java.io.IOException -  

writeHeader

public void writeHeader(java.io.Writer writer)
                 throws java.io.IOException

getStatus

public int getStatus()

setStatus

public void setStatus(int status)

getReason

public java.lang.String getReason()

setReason

public void setReason(java.lang.String reason)

sendError

public void sendError(int code,
                      java.lang.String message)
               throws java.io.IOException
Sends an error response to the client using the specified status code and no default message.
Parameters:
code - the status code
message - the detail message
Throws:
java.io.IOException - If an I/O error has occurred.

sendError

public void sendError(int code)
               throws java.io.IOException
Sends an error response to the client using the specified status code and no default message.
Parameters:
code - the status code
Throws:
java.io.IOException - If an I/O error has occurred.

sendError

public void sendError(int code,
                      java.lang.Throwable exception)
               throws java.io.IOException
Send Error Response. Sends an error response to the client using the specified status code and detail message.
Parameters:
exception -  
Throws:
java.io.IOException - If an I/O error has occurred.

sendRedirect

public void sendRedirect(java.lang.String location)
                  throws java.io.IOException
Sends a redirect response to the client using the specified redirect location URL.
Parameters:
location - the redirect location URL
Throws:
java.io.IOException - If an I/O error has occurred.

addSetCookie

public void addSetCookie(java.lang.String name,
                         java.lang.String value)
Add a Set-Cookie field.

addSetCookie

public void addSetCookie(Cookie cookie)
Add a Set-Cookie field.

addSetCookie

public void addSetCookie(Cookie cookie,
                         boolean cookie2)
Add a Set-Cookie field.
Parameters:
cookie - The cookie.
cookie2 - If true, use the alternate cookie 2 header

recycle

public void recycle(HttpConnection connection)
Recycle the response.
Overrides:
recycle in class HttpMessage

destroy

public void destroy()
Destroy the response. Help the garbage collector by null everything that we can.
Overrides:
destroy in class HttpMessage

commitHeader

public void commitHeader()
                  throws java.io.IOException
Overrides:
commitHeader in class HttpMessage

commit

public void commit()
            throws java.io.IOException
Description copied from class: HttpMessage
Commit the message. Take whatever actions possible to move the message to the SENDING state.
Overrides:
commit in class HttpMessage
Throws:
java.io.IOException -  


Copyright © 2000 Mortbay Consulting Pty. Ltd. All Rights Reserved.