## 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.42.2.5 2004/01/30 06:28:08 gregwilkins Exp $
Author:
  Greg Wilkins (gregw)
See Also:
  `HttpRequest`

Nested Class Summary

Nested classes inherited from class org.mortbay.http.HttpMessage
`HttpMessage.HeaderWriter`

Field Summary
`static int` `__100_Continue`
`static int` `__101_Switching_Protocols`
`static int` `__102_Processing`
`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` `__207_Multi_Status`
`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` `__422_Unprocessable_Entity`
`static int` `__423_Locked`
`static int` `__424_Failed_Dependency`
`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 int` `__507_Insufficient_Storage`
`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, __SCHEME, __SSL_SCHEME, __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()`
`void` `destroy()` Destroy the response.
`HttpContext` `getHttpContext()` Get the HttpContext handling this reponse.
`HttpRequest` `getHttpRequest()` Get the HTTP Request.
`java.lang.String` `getReason()`
`HttpRequest` `getRequest()` Deprecated. use getHttpRequest()
`int` `getStatus()`
`boolean` `isDirty()`
`void` `readHeader(HttpInputStream in)` Not Implemented.
`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)` 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, addDateField, addField, addIntField, containsField, getAttribute, getAttributeNames, getCharacterEncoding, getContentLength, getContentType, getDateField, getDotVersion, getField, getFieldNames, getFieldValues, getFieldValues, getHeader, getHttpConnection, getInputStream, getIntField, getMimeType, getOutputStream, getState, getTrailer, getVersion, getWrapper, isCommitted, removeAttribute, removeField, setAcceptTrailer, setAttribute, setCharacterEncoding, setContentLength, setContentType, setDateField, setDateField, setField, setField, setIntField, setState, setVersion, setWrapper, 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

See Also:
  Constant Field Values

### __101_Switching_Protocols

    public static final int __101_Switching_Protocols

See Also:
  Constant Field Values

### __102_Processing

    public static final int __102_Processing

See Also:
  Constant Field Values

### __200_OK

    public static final int __200_OK

See Also:
  Constant Field Values

### __201_Created

    public static final int __201_Created

See Also:
  Constant Field Values

### __202_Accepted

    public static final int __202_Accepted

See Also:
  Constant Field Values

### __203_Non_Authoritative_Information

    public static final int __203_Non_Authoritative_Information

See Also:
  Constant Field Values

### __204_No_Content

    public static final int __204_No_Content

See Also:
  Constant Field Values

### __205_Reset_Content

    public static final int __205_Reset_Content

See Also:
  Constant Field Values

### __206_Partial_Content

    public static final int __206_Partial_Content

See Also:
  Constant Field Values

### __207_Multi_Status

    public static final int __207_Multi_Status

See Also:
  Constant Field Values

### __300_Multiple_Choices

    public static final int __300_Multiple_Choices

See Also:
  Constant Field Values

### __301_Moved_Permanently

    public static final int __301_Moved_Permanently

See Also:
  Constant Field Values

### __302_Moved_Temporarily

    public static final int __302_Moved_Temporarily

See Also:
  Constant Field Values

### __303_See_Other

    public static final int __303_See_Other

See Also:
  Constant Field Values

### __304_Not_Modified

    public static final int __304_Not_Modified

See Also:
  Constant Field Values

### __305_Use_Proxy

    public static final int __305_Use_Proxy

See Also:
  Constant Field Values

### __400_Bad_Request

    public static final int __400_Bad_Request

See Also:
  Constant Field Values

### __401_Unauthorized

    public static final int __401_Unauthorized

See Also:
  Constant Field Values

### __402_Payment_Required

    public static final int __402_Payment_Required

See Also:
  Constant Field Values

### __403_Forbidden

    public static final int __403_Forbidden

See Also:
  Constant Field Values

### __404_Not_Found

    public static final int __404_Not_Found

See Also:
  Constant Field Values

### __405_Method_Not_Allowed

    public static final int __405_Method_Not_Allowed

See Also:
  Constant Field Values

### __406_Not_Acceptable

    public static final int __406_Not_Acceptable

See Also:
  Constant Field Values

### __407_Proxy_Authentication_Required

    public static final int __407_Proxy_Authentication_Required

See Also:
  Constant Field Values

### __408_Request_Timeout

    public static final int __408_Request_Timeout

See Also:
  Constant Field Values

### __409_Conflict

    public static final int __409_Conflict

See Also:
  Constant Field Values

### __410_Gone

    public static final int __410_Gone

See Also:
  Constant Field Values

### __411_Length_Required

    public static final int __411_Length_Required

See Also:
  Constant Field Values

### __412_Precondition_Failed

    public static final int __412_Precondition_Failed

See Also:
  Constant Field Values

### __413_Request_Entity_Too_Large

    public static final int __413_Request_Entity_Too_Large

See Also:
  Constant Field Values

### __414_Request_URI_Too_Large

    public static final int __414_Request_URI_Too_Large

See Also:
  Constant Field Values

### __415_Unsupported_Media_Type

    public static final int __415_Unsupported_Media_Type

See Also:
  Constant Field Values

### __416_Requested_Range_Not_Satisfiable

    public static final int __416_Requested_Range_Not_Satisfiable

See Also:
  Constant Field Values

### __417_Expectation_Failed

    public static final int __417_Expectation_Failed

See Also:
  Constant Field Values

### __422_Unprocessable_Entity

    public static final int __422_Unprocessable_Entity

See Also:
  Constant Field Values

### __423_Locked

    public static final int __423_Locked

See Also:
  Constant Field Values

### __424_Failed_Dependency

    public static final int __424_Failed_Dependency

See Also:
  Constant Field Values

### __500_Internal_Server_Error

    public static final int __500_Internal_Server_Error

See Also:
  Constant Field Values

### __501_Not_Implemented

    public static final int __501_Not_Implemented

See Also:
  Constant Field Values

### __502_Bad_Gateway

    public static final int __502_Bad_Gateway

See Also:
  Constant Field Values

### __503_Service_Unavailable

    public static final int __503_Service_Unavailable

See Also:
  Constant Field Values

### __504_Gateway_Timeout

    public static final int __504_Gateway_Timeout

See Also:
  Constant Field Values

### __505_HTTP_Version_Not_Supported

    public static final int __505_HTTP_Version_Not_Supported

See Also:
  Constant Field Values

### __507_Insufficient_Storage

    public static final int __507_Insufficient_Storage

See Also:
  Constant Field Values

### __statusMsg

    public static final java.util.HashMap __statusMsg

Constructor Detail

### HttpResponse

    public HttpResponse()

  Constructor.

### HttpResponse

    public HttpResponse(HttpConnection connection)

  Constructor.

Parameters:
  `connection` -

Method Detail

### getHttpContext

    public HttpContext getHttpContext()

  Get the HttpContext handling this reponse.

  Returns:
    The HttpContext that is handling this request.

### 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`.

  Overrides:
    `reset` in class `HttpMessage`
  Throws:
    `java.lang.IllegalStateException` - if the response has already been committed

### getRequest

    public HttpRequest getRequest()

  Deprecated. use getHttpRequest()

### getHttpRequest

    public HttpRequest getHttpRequest()

  Get the HTTP Request. Get the HTTP Request associated with this response.

  Returns:
    associated request

### readHeader

    public void readHeader(HttpInputStream 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

  Overrides:
    `writeHeader` in class `HttpMessage`
    `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

  Send Error Response.

    `java.io.IOException`

### 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.

### 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

### commit

    public void commit()
                throws java.io.IOException

  Throws:
    `java.io.IOException`

### destroy

    public void destroy()

  Destroy the response. Help the garbage collector by null everything that we can.

  Overrides:
    `destroy` in class `HttpMessage`

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