org.apache.coyote.tomcat5

Class CoyoteResponse

Implemented Interfaces:
HttpResponse, HttpServletResponse, Response

public class CoyoteResponse
extends java.lang.Object
implements HttpResponse, HttpServletResponse

Wrapper object for the Coyote response.

Version:
$Revision: 1.18.2.2 $ $Date: 2004/11/18 22:14:24 $

Authors:
Remy Maucherat
Craig R. McClanahan

Field Summary

protected boolean
appCommitted
The application commit flag.
protected Connector
connector
Associated Catalina connector.
protected ArrayList
cookies
The set of Cookies associated with this Response.
protected Response
coyoteResponse
Coyote response.
protected boolean
error
The error flag.
protected CoyoteResponseFacade
facade
The facade associated with this response.
protected SimpleDateFormat
format
The date format we will use for creating date headers.
protected boolean
included
The included flag.
protected static String
info
Descriptive information about this Response implementation.
protected OutputBuffer
outputBuffer
The associated output buffer.
protected CoyoteOutputStream
outputStream
The associated output stream.
protected CharChunk
redirectURLCC
Recyclable buffer to hold the redirect URL.
protected CoyoteRequest
request
The request with which this response is associated.
protected static StringManager
sm
The string manager for this package.
protected UEncoder
urlEncoder
URL encoder.
protected boolean
usingOutputStream
Using output stream flag.
protected boolean
usingWriter
Using writer flag.
protected CoyoteWriter
writer
The associated writer.

Constructor Summary

CoyoteResponse()

Method Summary

void
addCookie(Cookie cookie)
Add the specified Cookie to those that will be included with this Response.
void
addDateHeader(String name, long value)
Add the specified date header to the specified value.
void
addHeader(String name, String value)
Add the specified header to the specified value.
void
addIntHeader(String name, int value)
Add the specified integer header to the specified value.
boolean
containsHeader(String name)
Has the specified header been set already in this response?
ServletOutputStream
createOutputStream()
Create and return a ServletOutputStream to write the content associated with this Response.
String
encodeRedirectURL(String url)
Encode the session identifier associated with this response into the specified redirect URL, if necessary.
String
encodeRedirectUrl(String url)
Deprecated. As of Version 2.1 of the Java Servlet API, use encodeRedirectURL() instead.
String
encodeURL(String url)
Encode the session identifier associated with this response into the specified URL, if necessary.
String
encodeUrl(String url)
Deprecated. As of Version 2.1 of the Java Servlet API, use encodeURL() instead.
void
finishResponse()
Perform whatever actions are required to flush and close the output stream or writer, in a single operation.
void
flushBuffer()
Flush the buffer and commit this response.
int
getBufferSize()
Return the actual buffer size used for this Response.
String
getCharacterEncoding()
Return the character encoding used for this Response.
Connector
getConnector()
Return the Connector through which this Request was received.
int
getContentCount()
Return the number of bytes actually written to the output stream.
int
getContentLength()
Return the content length that was set or calculated for this Response.
String
getContentType()
Return the content type that was set or calculated for this response, or null if no content type was set.
Context
getContext()
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.
Response
getCoyoteResponse()
Get the Coyote response.
String
getHeader(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.
boolean
getIncluded()
Return the "processing inside an include" flag.
String
getInfo()
Return descriptive information about this Response implementation and the corresponding version number, in the format <description>/<version>.
Locale
getLocale()
Return the Locale assigned to this response.
String
getMessage()
Return the error message that was set with sendError() for this Response.
ServletOutputStream
getOutputStream()
Return the servlet output stream associated with this Response.
PrintWriter
getReporter()
Return a PrintWriter that can be used to render error messages, regardless of whether a stream or writer has already been acquired.
Request
getRequest()
Return the Request with which this Response is associated.
ServletResponse
getResponse()
Return the ServletResponse for which this object is the facade.
int
getStatus()
Return the HTTP status code associated with this Response.
OutputStream
getStream()
Return the output stream associated with this Response.
PrintWriter
getWriter()
Return the writer associated with this Response.
boolean
isAppCommitted()
Application commit flag accessor.
boolean
isCommitted()
Has the output of this response already been committed?
protected boolean
isEncodeable(String location)
Return true if the specified URL should be encoded with a session identifier.
boolean
isError()
Error flag accessor.
boolean
isSuspended()
Suspended flag accessor.
void
recycle()
Release all object references, and initialize instance variables, in preparation for reuse of this object.
void
reset()
Clear any content written to the buffer.
void
reset(int status, String message)
Reset this response, and specify the values for the HTTP status code and corresponding message.
void
resetBuffer()
Reset the data buffer but not any status or header information.
void
sendAcknowledgement()
Send an acknowledgment of a request.
void
sendError(int status)
Send an error response with the specified status and a default message.
void
sendError(int status, String message)
Send an error response with the specified status and message.
void
sendRedirect(String location)
Send a temporary redirect to the specified redirect location URL.
void
setAppCommitted(boolean appCommitted)
Set the application commit flag.
void
setBufferSize(int size)
Set the buffer size to be used for this Response.
void
setCharacterEncoding(String charset)
void
setConnector(Connector connector)
Set the Connector through which this Request was received.
void
setContentLength(int length)
Set the content length (in bytes) for this Response.
void
setContentType(String type)
Set the content type for this Response.
void
setContext(Context context)
Set the Context within which this Request is being processed.
void
setCoyoteResponse(Response coyoteResponse)
Set the Coyote response.
void
setDateHeader(String name, long value)
Set the specified date header to the specified value.
void
setError()
Set the error flag.
void
setHeader(String name, String value)
Set the specified header to the specified value.
void
setIncluded(boolean included)
Set the "processing inside an include" flag.
void
setIntHeader(String name, int value)
Set the specified integer header to the specified value.
void
setLocale(Locale locale)
Set the Locale that is appropriate for this response, including setting the appropriate character encoding.
void
setRequest(Request request)
Set the Request with which this Response is associated.
void
setStatus(int status)
Set the HTTP status to be returned with this response.
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.
void
setStream(OutputStream stream)
Set the output stream associated with this Response.
void
setSuspended(boolean suspended)
Set the suspended flag.

Field Details

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 CoyoteResponseFacade 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 CoyoteRequest 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 Details

CoyoteResponse

public CoyoteResponse()

Method Details

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


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


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()
            throws IOException
Create and return a ServletOutputStream to write the content associated with this Response.
Specified by:
createOutputStream in interface Response


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


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


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


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


finishResponse

public void finishResponse()
            throws IOException
Perform whatever actions are required to flush and close the output stream or writer, in a single operation.
Specified by:
finishResponse in interface Response


flushBuffer

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


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.
Specified by:
getConnector in interface Response


getContentCount

public int getContentCount()
Return the number of bytes actually written to the output stream.
Specified by:
getContentCount in interface Response


getContentLength

public int getContentLength()
Return the content length that was set or calculated for this Response.
Specified by:
getContentLength in interface 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.
Specified by:
getContentType in interface Response


getContext

public Context getContext()
Return the Context within which this Request is being processed.
Specified by:
getContext in interface Response


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.
Specified by:
getCookies in interface HttpResponse


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.
Specified by:
getHeader in interface HttpResponse

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.
Specified by:
getHeaderNames in interface HttpResponse


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.
Specified by:
getHeaderValues in interface HttpResponse

Parameters:
name - Header name to look up


getIncluded

public boolean getIncluded()
Return the "processing inside an include" flag.
Specified by:
getIncluded in interface Response


getInfo

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


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.
Specified by:
getMessage in interface HttpResponse


getOutputStream

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


getReporter

public PrintWriter getReporter()
            throws IOException
Return a PrintWriter that can be used to render error messages, regardless of whether a stream or writer has already been acquired.
Specified by:
getReporter in interface Response

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.


getRequest

public Request getRequest()
Return the Request with which this Response is associated.
Specified by:
getRequest in interface Response


getResponse

public ServletResponse getResponse()
Return the ServletResponse for which this object is the facade.
Specified by:
getResponse in interface Response


getStatus

public int getStatus()
Return the HTTP status code associated with this Response.
Specified by:
getStatus in interface HttpResponse


getStream

public OutputStream getStream()
Return the output stream associated with this Response.
Specified by:
getStream in interface Response


getWriter

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


isAppCommitted

public boolean isAppCommitted()
Application commit flag accessor.
Specified by:
isAppCommitted in interface Response


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:
  • The request we are responding to asked for a valid session
  • The requested session ID was not received via a cookie
  • The specified URL points back to somewhere within the web application that is responding to this request

Parameters:
location - Absolute URL to be validated


isError

public boolean isError()
Error flag accessor.
Specified by:
isError in interface Response


isSuspended

public boolean isSuspended()
Suspended flag accessor.
Specified by:
isSuspended in interface Response


recycle

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


reset

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


reset

public void reset(int status,
                  String message)
Reset this response, and specify the values for the HTTP status code and corresponding message.
Specified by:
reset in interface HttpResponse


resetBuffer

public void resetBuffer()
Reset the data buffer but not any status or header information.
Specified by:
resetBuffer in interface Response


sendAcknowledgement

public void sendAcknowledgement()
            throws IOException
Send an acknowledgment of a request.
Specified by:
sendAcknowledgement in interface Response


sendError

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

Parameters:
status - HTTP status code to send


sendError

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

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


sendRedirect

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

Parameters:
location - Location URL to redirect to


setAppCommitted

public void setAppCommitted(boolean appCommitted)
Set the application commit flag.
Specified by:
setAppCommitted in interface Response

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


setCharacterEncoding

public void setCharacterEncoding(String charset)


setConnector

public void setConnector(Connector connector)
Set the Connector through which this Request was received.
Specified by:
setConnector in interface Response

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.
Specified by:
setContext in interface Response

Parameters:
context - The newly associated Context


setCoyoteResponse

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

Parameters:


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.
Specified by:
setError in interface Response


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.
Specified by:
setIncluded in interface Response

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.
Specified by:
setRequest in interface Response

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.
Specified by:
setStream in interface Response

Parameters:
stream - The new output stream


setSuspended

public void setSuspended(boolean suspended)
Set the suspended flag.
Specified by:
setSuspended in interface Response

Parameters:
suspended - The new suspended flag value


Copyright B) 2000-2003 Apache Software Foundation. All Rights Reserved.