org.mortbay.http

Class 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.61 2005/10/26 08:10:14 gregwilkins Exp $
Author:
Greg Wilkins (gregw)
See Also:
HttpRequest

Nested Class Summary

Nested classes/interfaces 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_Found
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 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, _attributes, _characterEncoding, _connection, _dotVersion, _header, _mimeType, _state, _version, _wrapper

Constructor Summary

HttpResponse()
Constructor.
HttpResponse(HttpConnection connection)
Constructor.

Method Summary

void
addSetCookie(String name, String value)
Add a Set-Cookie field.
void
addSetCookie(Cookie cookie)
Add a Set-Cookie field.
void
commit()
void
completing()
void
destroy()
Destroy the response.
HttpContext
getHttpContext()
Get the HttpContext handling this reponse.
HttpRequest
getHttpRequest()
Get the HTTP Request.
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, String message)
Send Error Response.
void
sendRedirect(String location)
Sends a redirect response to the client using the specified redirect location URL.
void
setHttpContext(HttpContext context)
Set the HttpContext handling this reponse.
void
setReason(String reason)
void
setStatus(int status)
void
setStatus(int code, String message)
void
writeHeader(Writer writer)
Write the message header.

Methods inherited from class org.mortbay.http.HttpMessage

addDateField, addDateField, addField, addIntField, containsField, destroy, getAttribute, getAttributeNames, getCharacterEncoding, getContentLength, getContentType, getDateField, getDotVersion, getField, getFieldNames, getFieldValues, getFieldValues, getHeader, getHttpConnection, getInputStream, getIntField, getMimeType, getOutputStream, getState, getVersion, getWrapper, isCommitted, isDirty, removeAttribute, removeField, reset, setAttribute, setCharacterEncoding, setContentLength, setContentType, setDateField, setDateField, setField, setField, setIntField, setState, setVersion, setWrapper, toString, updateMimeType

Field Details

__100_Continue

public static final int __100_Continue
Field Value:
100

__101_Switching_Protocols

public static final int __101_Switching_Protocols
Field Value:
101

__102_Processing

public static final int __102_Processing
Field Value:
102

__200_OK

public static final int __200_OK
Field Value:
200

__201_Created

public static final int __201_Created
Field Value:
201

__202_Accepted

public static final int __202_Accepted
Field Value:
202

__203_Non_Authoritative_Information

public static final int __203_Non_Authoritative_Information
Field Value:
203

__204_No_Content

public static final int __204_No_Content
Field Value:
204

__205_Reset_Content

public static final int __205_Reset_Content
Field Value:
205

__206_Partial_Content

public static final int __206_Partial_Content
Field Value:
206

__207_Multi_Status

public static final int __207_Multi_Status
Field Value:
207

__300_Multiple_Choices

public static final int __300_Multiple_Choices
Field Value:
300

__301_Moved_Permanently

public static final int __301_Moved_Permanently
Field Value:
301

__302_Found

public static final int __302_Found
Field Value:
302

__302_Moved_Temporarily

public static final int __302_Moved_Temporarily
Field Value:
302

__303_See_Other

public static final int __303_See_Other
Field Value:
303

__304_Not_Modified

public static final int __304_Not_Modified
Field Value:
304

__305_Use_Proxy

public static final int __305_Use_Proxy
Field Value:
305

__400_Bad_Request

public static final int __400_Bad_Request
Field Value:
400

__401_Unauthorized

public static final int __401_Unauthorized
Field Value:
401

__402_Payment_Required

public static final int __402_Payment_Required
Field Value:
402

__403_Forbidden

public static final int __403_Forbidden
Field Value:
403

__404_Not_Found

public static final int __404_Not_Found
Field Value:
404

__405_Method_Not_Allowed

public static final int __405_Method_Not_Allowed
Field Value:
405

__406_Not_Acceptable

public static final int __406_Not_Acceptable
Field Value:
406

__407_Proxy_Authentication_Required

public static final int __407_Proxy_Authentication_Required
Field Value:
407

__408_Request_Timeout

public static final int __408_Request_Timeout
Field Value:
408

__409_Conflict

public static final int __409_Conflict
Field Value:
409

__410_Gone

public static final int __410_Gone
Field Value:
410

__411_Length_Required

public static final int __411_Length_Required
Field Value:
411

__412_Precondition_Failed

public static final int __412_Precondition_Failed
Field Value:
412

__413_Request_Entity_Too_Large

public static final int __413_Request_Entity_Too_Large
Field Value:
413

__414_Request_URI_Too_Large

public static final int __414_Request_URI_Too_Large
Field Value:
414

__415_Unsupported_Media_Type

public static final int __415_Unsupported_Media_Type
Field Value:
415

__416_Requested_Range_Not_Satisfiable

public static final int __416_Requested_Range_Not_Satisfiable
Field Value:
416

__417_Expectation_Failed

public static final int __417_Expectation_Failed
Field Value:
417

__422_Unprocessable_Entity

public static final int __422_Unprocessable_Entity
Field Value:
422

__423_Locked

public static final int __423_Locked
Field Value:
423

__424_Failed_Dependency

public static final int __424_Failed_Dependency
Field Value:
424

__500_Internal_Server_Error

public static final int __500_Internal_Server_Error
Field Value:
500

__501_Not_Implemented

public static final int __501_Not_Implemented
Field Value:
501

__502_Bad_Gateway

public static final int __502_Bad_Gateway
Field Value:
502

__503_Service_Unavailable

public static final int __503_Service_Unavailable
Field Value:
503

__504_Gateway_Timeout

public static final int __504_Gateway_Timeout
Field Value:
504

__505_HTTP_Version_Not_Supported

public static final int __505_HTTP_Version_Not_Supported
Field Value:
505

__507_Insufficient_Storage

public static final int __507_Insufficient_Storage
Field Value:
507

__statusMsg

public static final HashMap __statusMsg

Constructor Details

HttpResponse

public HttpResponse()
Constructor.

HttpResponse

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

Method Details

addSetCookie

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

addSetCookie

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

commit

public void commit()
            throws IOException

completing

public void completing()

destroy

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

getHttpContext

public HttpContext getHttpContext()
Get the HttpContext handling this reponse.
Returns:
The HttpContext that is handling this request.

getHttpRequest

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

getReason

public String getReason()

getRequest

public HttpRequest getRequest()

Deprecated. use getHttpRequest()


getStatus

public int getStatus()

isDirty

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

readHeader

public void readHeader(HttpInputStream in)
            throws IOException
Not Implemented.
Parameters:
in -

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 interface HttpMessage

sendError

public void sendError(int code)
            throws IOException
Sends an error response to the client using the specified status code and no default message.
Parameters:
code - the status code

sendError

public void sendError(int code,
                      String message)
            throws IOException
Send Error Response.

sendRedirect

public void sendRedirect(String location)
            throws IOException
Sends a redirect response to the client using the specified redirect location URL.
Parameters:
location - the redirect location URL

setHttpContext

public void setHttpContext(HttpContext context)
Set the HttpContext handling this reponse.
Parameters:
context - The HttpContext handling this reponse.

setReason

public void setReason(String reason)

setStatus

public void setStatus(int status)

setStatus

public void setStatus(int code,
                      String message)

writeHeader

public void writeHeader(Writer writer)
            throws IOException
Write the message header.
Parameters:
writer -

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