org.apache.catalina.connector

Class Response

public class Response extends Object implements HttpServletResponse

Wrapper object for the Coyote response.

Version: $Revision: 832206 $ $Date: 2009-11-03 00:52:06 +0100 (Tue, 03 Nov 2009) $

Author: Remy Maucherat Craig R. McClanahan

Field Summary
protected booleanappCommitted
The application commit flag.
protected Connectorconnector
Associated Catalina connector.
protected ArrayListcookies
The set of Cookies associated with this Response.
protected ResponsecoyoteResponse
Coyote response.
protected booleanerror
The error flag.
protected ResponseFacadefacade
The facade associated with this response.
protected SimpleDateFormatformat
The date format we will use for creating date headers.
protected booleanincluded
The included flag.
protected static Stringinfo
Descriptive information about this Response implementation.
protected OutputBufferoutputBuffer
The associated output buffer.
protected CoyoteOutputStreamoutputStream
The associated output stream.
protected CharChunkredirectURLCC
Recyclable buffer to hold the redirect URL.
protected Requestrequest
The request with which this response is associated.
protected static StringManagersm
The string manager for this package.
protected UEncoderurlEncoder
URL encoder.
protected booleanusingOutputStream
Using output stream flag.
protected booleanusingWriter
Using writer flag.
protected CoyoteWriterwriter
The associated writer.
Constructor Summary
Response()
Method Summary
voidaddCookie(Cookie cookie)
Add the specified Cookie to those that will be included with this Response.
voidaddCookieInternal(Cookie cookie)
Add the specified Cookie to those that will be included with this Response.
voidaddCookieInternal(Cookie cookie, boolean httpOnly)
Add the specified Cookie to those that will be included with this Response.
voidaddDateHeader(String name, long value)
Add the specified date header to the specified value.
voidaddHeader(String name, String value)
Add the specified header to the specified value.
voidaddIntHeader(String name, int value)
Add the specified integer header to the specified value.
voidclearEncoders()
Clear cached encoders (to save memory for Comet requests).
booleancontainsHeader(String name)
Has the specified header been set already in this response?
ServletOutputStreamcreateOutputStream()
Create and return a ServletOutputStream to write the content associated with this Response.
StringencodeRedirectUrl(String url)
Encode the session identifier associated with this response into the specified redirect URL, if necessary.
StringencodeRedirectURL(String url)
Encode the session identifier associated with this response into the specified redirect URL, if necessary.
StringencodeUrl(String url)
Encode the session identifier associated with this response into the specified URL, if necessary.
StringencodeURL(String url)
Encode the session identifier associated with this response into the specified URL, if necessary.
voidfinishResponse()
Perform whatever actions are required to flush and close the output stream or writer, in a single operation.
voidflushBuffer()
Flush the buffer and commit this response.
intgetBufferSize()
Return the actual buffer size used for this Response.
StringgetCharacterEncoding()
Return the character encoding used for this Response.
ConnectorgetConnector()
Return the Connector through which this Request was received.
intgetContentCount()
Return the number of bytes actually written to the output stream.
longgetContentCountLong()
Return the number of bytes actually written to the output stream.
intgetContentLength()
Return the content length that was set or calculated for this Response.
StringgetContentType()
Return the content type that was set or calculated for this response, or null if no content type was set.
ContextgetContext()
Return the Context within which this Request is being processed.
Cookie[]getCookies()
Return an array of all cookies set for this response, or a zero-length array if no cookies have been set.
ResponsegetCoyoteResponse()
Get the Coyote response.
StringgetHeader(String name)
Return the value for the specified header, or null if this header has not been set.
String[]getHeaderNames()
Return an array of all the header names set for this response, or a zero-length array if no headers have been set.
String[]getHeaderValues(String name)
Return an array of all the header values associated with the specified header name, or an zero-length array if there are no such header values.
booleangetIncluded()
Return the "processing inside an include" flag.
StringgetInfo()
Return descriptive information about this Response implementation and the corresponding version number, in the format <description>/<version>.
LocalegetLocale()
Return the Locale assigned to this response.
StringgetMessage()
Return the error message that was set with sendError() for this Response.
ServletOutputStreamgetOutputStream()
Return the servlet output stream associated with this Response.
PrintWritergetReporter()
Return a PrintWriter that can be used to render error messages, regardless of whether a stream or writer has already been acquired.
RequestgetRequest()
Return the Request with which this Response is associated.
HttpServletResponsegetResponse()
Return the ServletResponse for which this object is the facade.
intgetStatus()
Return the HTTP status code associated with this Response.
OutputStreamgetStream()
Return the output stream associated with this Response.
PrintWritergetWriter()
Return the writer associated with this Response.
booleanisAppCommitted()
Application commit flag accessor.
booleanisClosed()
Closed flag accessor.
booleanisCommitted()
Has the output of this response already been committed?
protected booleanisEncodeable(String location)
Return true if the specified URL should be encoded with a session identifier.
booleanisError()
Error flag accessor.
booleanisSuspended()
Suspended flag accessor.
voidrecycle()
Release all object references, and initialize instance variables, in preparation for reuse of this object.
voidreset()
Clear any content written to the buffer.
voidreset(int status, String message)
Reset this response, and specify the values for the HTTP status code and corresponding message.
voidresetBuffer()
Reset the data buffer but not any status or header information.
voidresetBuffer(boolean resetWriterStreamFlags)
Reset the data buffer and the using Writer/Stream flags but not any status or header information.
voidsendAcknowledgement()
Send an acknowledgment of a request.
voidsendError(int status)
Send an error response with the specified status and a default message.
voidsendError(int status, String message)
Send an error response with the specified status and message.
voidsendRedirect(String location)
Send a temporary redirect to the specified redirect location URL.
voidsetAppCommitted(boolean appCommitted)
Set the application commit flag.
voidsetBufferSize(int size)
Set the buffer size to be used for this Response.
voidsetCharacterEncoding(String charset)
voidsetConnector(Connector connector)
Set the Connector through which this Request was received.
voidsetContentLength(int length)
Set the content length (in bytes) for this Response.
voidsetContentType(String type)
Set the content type for this Response.
voidsetContext(Context context)
Set the Context within which this Request is being processed.
voidsetCoyoteResponse(Response coyoteResponse)
Set the Coyote response.
voidsetDateHeader(String name, long value)
Set the specified date header to the specified value.
voidsetError()
Set the error flag.
voidsetHeader(String name, String value)
Set the specified header to the specified value.
voidsetIncluded(boolean included)
Set the "processing inside an include" flag.
voidsetIntHeader(String name, int value)
Set the specified integer header to the specified value.
voidsetLocale(Locale locale)
Set the Locale that is appropriate for this response, including setting the appropriate character encoding.
voidsetRequest(Request request)
Set the Request with which this Response is associated.
voidsetStatus(int status)
Set the HTTP status to be returned with this response.
voidsetStatus(int status, String message)
Set the HTTP status and message to be returned with this response.
voidsetStream(OutputStream stream)
Set the output stream associated with this Response.
voidsetSuspended(boolean suspended)
Set the suspended flag.
protected StringtoEncoded(String url, String sessionId)
Return the specified URL with the specified session identifier suitably encoded.

Field Detail

appCommitted

protected boolean appCommitted
The application commit flag.

connector

protected Connector connector
Associated Catalina connector.

cookies

protected ArrayList cookies
The set of Cookies associated with this Response.

coyoteResponse

protected Response coyoteResponse
Coyote response.

error

protected boolean error
The error flag.

facade

protected ResponseFacade facade
The facade associated with this response.

format

protected SimpleDateFormat format
The date format we will use for creating date headers.

included

protected boolean included
The included flag.

info

protected static final String info
Descriptive information about this Response implementation.

outputBuffer

protected OutputBuffer outputBuffer
The associated output buffer.

outputStream

protected CoyoteOutputStream outputStream
The associated output stream.

redirectURLCC

protected CharChunk redirectURLCC
Recyclable buffer to hold the redirect URL.

request

protected Request request
The request with which this response is associated.

sm

protected static StringManager sm
The string manager for this package.

urlEncoder

protected UEncoder urlEncoder
URL encoder.

usingOutputStream

protected boolean usingOutputStream
Using output stream flag.

usingWriter

protected boolean usingWriter
Using writer flag.

writer

protected CoyoteWriter writer
The associated writer.

Constructor Detail

Response

public Response()

Method Detail

addCookie

public void addCookie(Cookie cookie)
Add the specified Cookie to those that will be included with this Response.

Parameters: cookie Cookie to be added

addCookieInternal

public void addCookieInternal(Cookie cookie)
Add the specified Cookie to those that will be included with this Response.

Parameters: cookie Cookie to be added

addCookieInternal

public void addCookieInternal(Cookie cookie, boolean httpOnly)
Add the specified Cookie to those that will be included with this Response.

Parameters: cookie Cookie to be added httpOnly Should the httpOnly falg be set on this cookie

addDateHeader

public void addDateHeader(String name, long value)
Add the specified date header to the specified value.

Parameters: name Name of the header to set value Date value to be set

addHeader

public void addHeader(String name, String value)
Add the specified header to the specified value.

Parameters: name Name of the header to set value Value to be set

addIntHeader

public void addIntHeader(String name, int value)
Add the specified integer header to the specified value.

Parameters: name Name of the header to set value Integer value to be set

clearEncoders

public void clearEncoders()
Clear cached encoders (to save memory for Comet requests).

containsHeader

public boolean containsHeader(String name)
Has the specified header been set already in this response?

Parameters: name Name of the header to check

createOutputStream

public ServletOutputStream createOutputStream()
Create and return a ServletOutputStream to write the content associated with this Response.

Throws: IOException if an input/output error occurs

encodeRedirectUrl

public String encodeRedirectUrl(String url)

Deprecated: As of Version 2.1 of the Java Servlet API, use encodeRedirectURL() instead.

Encode the session identifier associated with this response into the specified redirect URL, if necessary.

Parameters: url URL to be encoded

encodeRedirectURL

public String encodeRedirectURL(String url)
Encode the session identifier associated with this response into the specified redirect URL, if necessary.

Parameters: url URL to be encoded

encodeUrl

public String encodeUrl(String url)

Deprecated: As of Version 2.1 of the Java Servlet API, use encodeURL() instead.

Encode the session identifier associated with this response into the specified URL, if necessary.

Parameters: url URL to be encoded

encodeURL

public String encodeURL(String url)
Encode the session identifier associated with this response into the specified URL, if necessary.

Parameters: url URL to be encoded

finishResponse

public void finishResponse()
Perform whatever actions are required to flush and close the output stream or writer, in a single operation.

Throws: IOException if an input/output error occurs

flushBuffer

public void flushBuffer()
Flush the buffer and commit this response.

Throws: IOException if an input/output error occurs

getBufferSize

public int getBufferSize()
Return the actual buffer size used for this Response.

getCharacterEncoding

public String getCharacterEncoding()
Return the character encoding used for this Response.

getConnector

public Connector getConnector()
Return the Connector through which this Request was received.

getContentCount

public int getContentCount()
Return the number of bytes actually written to the output stream.

getContentCountLong

public long getContentCountLong()
Return the number of bytes actually written to the output stream.

getContentLength

public int getContentLength()
Return the content length that was set or calculated for this Response.

getContentType

public String getContentType()
Return the content type that was set or calculated for this response, or null if no content type was set.

getContext

public Context getContext()
Return the Context within which this Request is being processed.

getCookies

public Cookie[] getCookies()
Return an array of all cookies set for this response, or a zero-length array if no cookies have been set.

getCoyoteResponse

public Response getCoyoteResponse()
Get the Coyote response.

getHeader

public String getHeader(String name)
Return the value for the specified header, or null if this header has not been set. If more than one value was added for this name, only the first is returned; use getHeaderValues() to retrieve all of them.

Parameters: name Header name to look up

getHeaderNames

public String[] getHeaderNames()
Return an array of all the header names set for this response, or a zero-length array if no headers have been set.

getHeaderValues

public String[] getHeaderValues(String name)
Return an array of all the header values associated with the specified header name, or an zero-length array if there are no such header values.

Parameters: name Header name to look up

getIncluded

public boolean getIncluded()
Return the "processing inside an include" flag.

getInfo

public String getInfo()
Return descriptive information about this Response implementation and the corresponding version number, in the format <description>/<version>.

getLocale

public Locale getLocale()
Return the Locale assigned to this response.

getMessage

public String getMessage()
Return the error message that was set with sendError() for this Response.

getOutputStream

public ServletOutputStream getOutputStream()
Return the servlet output stream associated with this Response.

Throws: IllegalStateException if getWriter has already been called for this response IOException if an input/output error occurs

getReporter

public PrintWriter getReporter()
Return a PrintWriter that can be used to render error messages, regardless of whether a stream or writer has already been acquired.

Returns: Writer which can be used for error reports. If the response is not an error report returned using sendError or triggered by an unexpected exception thrown during the servlet processing (and only in that case), null will be returned if the response stream has already been used.

Throws: IOException if an input/output error occurs

getRequest

public Request getRequest()
Return the Request with which this Response is associated.

getResponse

public HttpServletResponse getResponse()
Return the ServletResponse for which this object is the facade.

getStatus

public int getStatus()
Return the HTTP status code associated with this Response.

getStream

public OutputStream getStream()
Return the output stream associated with this Response.

getWriter

public PrintWriter getWriter()
Return the writer associated with this Response.

Throws: IllegalStateException if getOutputStream has already been called for this response IOException if an input/output error occurs

isAppCommitted

public boolean isAppCommitted()
Application commit flag accessor.

isClosed

public boolean isClosed()
Closed flag accessor.

isCommitted

public boolean isCommitted()
Has the output of this response already been committed?

isEncodeable

protected boolean isEncodeable(String location)
Return true if the specified URL should be encoded with a session identifier. This will be true if all of the following conditions are met:

Parameters: location Absolute URL to be validated

isError

public boolean isError()
Error flag accessor.

isSuspended

public boolean isSuspended()
Suspended flag accessor.

recycle

public void recycle()
Release all object references, and initialize instance variables, in preparation for reuse of this object.

reset

public void reset()
Clear any content written to the buffer.

Throws: IllegalStateException if this response has already been committed

reset

public void reset(int status, String message)
Reset this response, and specify the values for the HTTP status code and corresponding message.

Throws: IllegalStateException if this response has already been committed

resetBuffer

public void resetBuffer()
Reset the data buffer but not any status or header information.

Throws: IllegalStateException if the response has already been committed

resetBuffer

public void resetBuffer(boolean resetWriterStreamFlags)
Reset the data buffer and the using Writer/Stream flags but not any status or header information.

Parameters: resetWriterStreamFlags true if the internal usingWriter, usingOutputStream, isCharacterEncodingSet flags should also be reset

Throws: IllegalStateException if the response has already been committed

sendAcknowledgement

public void sendAcknowledgement()
Send an acknowledgment of a request.

Throws: IOException if an input/output error occurs

sendError

public void sendError(int status)
Send an error response with the specified status and a default message.

Parameters: status HTTP status code to send

Throws: IllegalStateException if this response has already been committed IOException if an input/output error occurs

sendError

public void sendError(int status, String message)
Send an error response with the specified status and message.

Parameters: status HTTP status code to send message Corresponding message to send

Throws: IllegalStateException if this response has already been committed IOException if an input/output error occurs

sendRedirect

public void sendRedirect(String location)
Send a temporary redirect to the specified redirect location URL.

Parameters: location Location URL to redirect to

Throws: IllegalStateException if this response has already been committed IOException if an input/output error occurs

setAppCommitted

public void setAppCommitted(boolean appCommitted)
Set the application commit flag.

Parameters: appCommitted The new application committed flag value

setBufferSize

public void setBufferSize(int size)
Set the buffer size to be used for this Response.

Parameters: size The new buffer size

Throws: IllegalStateException if this method is called after output has been committed for this response

setCharacterEncoding

public void setCharacterEncoding(String charset)

setConnector

public void setConnector(Connector connector)
Set the Connector through which this Request was received.

Parameters: connector The new connector

setContentLength

public void setContentLength(int length)
Set the content length (in bytes) for this Response.

Parameters: length The new content length

setContentType

public void setContentType(String type)
Set the content type for this Response.

Parameters: type The new content type

setContext

public void setContext(Context context)
Set the Context within which this Request is being processed. This must be called as soon as the appropriate Context is identified, because it identifies the value to be returned by getContextPath(), and thus enables parsing of the request URI.

Parameters: context The newly associated Context

setCoyoteResponse

public void setCoyoteResponse(Response coyoteResponse)
Set the Coyote response.

Parameters: coyoteResponse The Coyote response

setDateHeader

public void setDateHeader(String name, long value)
Set the specified date header to the specified value.

Parameters: name Name of the header to set value Date value to be set

setError

public void setError()
Set the error flag.

setHeader

public void setHeader(String name, String value)
Set the specified header to the specified value.

Parameters: name Name of the header to set value Value to be set

setIncluded

public void setIncluded(boolean included)
Set the "processing inside an include" flag.

Parameters: included true if we are currently inside a RequestDispatcher.include(), else false

setIntHeader

public void setIntHeader(String name, int value)
Set the specified integer header to the specified value.

Parameters: name Name of the header to set value Integer value to be set

setLocale

public void setLocale(Locale locale)
Set the Locale that is appropriate for this response, including setting the appropriate character encoding.

Parameters: locale The new locale

setRequest

public void setRequest(Request request)
Set the Request with which this Response is associated.

Parameters: request The new associated request

setStatus

public void setStatus(int status)
Set the HTTP status to be returned with this response.

Parameters: status The new HTTP status

setStatus

public void setStatus(int status, String message)

Deprecated: As of Version 2.1 of the Java Servlet API, this method has been deprecated due to the ambiguous meaning of the message parameter.

Set the HTTP status and message to be returned with this response.

Parameters: status The new HTTP status message The associated text message

setStream

public void setStream(OutputStream stream)
Set the output stream associated with this Response.

Parameters: stream The new output stream

setSuspended

public void setSuspended(boolean suspended)
Set the suspended flag.

Parameters: suspended The new suspended flag value

toEncoded

protected String toEncoded(String url, String sessionId)
Return the specified URL with the specified session identifier suitably encoded.

Parameters: url URL to be encoded with the session id sessionId Session id to be included in the encoded URL

Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.