org.apache.commons.messagelet.impl
Class HttpServletResponseImpl

java.lang.Object
  extended by org.apache.commons.messagelet.impl.ServletResponseImpl
      extended by org.apache.commons.messagelet.impl.HttpServletResponseImpl
All Implemented Interfaces:
javax.servlet.http.HttpServletResponse, javax.servlet.ServletResponse

public class HttpServletResponseImpl
extends ServletResponseImpl
implements javax.servlet.http.HttpServletResponse

Based on the HttpRequestBase code from Catalina.

Version:
$Revision: 155459 $ $Date: 2005-02-26 13:24:44 +0000 (Sat, 26 Feb 2005) $
Author:
Craig R. McClanahan, James Strachan

Field Summary
protected  ArrayList cookies
          The set of Cookies associated with this Response.
protected static SimpleDateFormat format
          The date format we will use for creating date headers.
protected  HashMap headers
          The HTTP headers explicitly added via addHeader(), but not including those to be added with setContentLength(), setContentType(), and so on.
protected  String message
          The error message set by sendError().
protected  int status
          The HTTP status code associated with this Response.
protected static TimeZone zone
          The time zone with which to construct date headers.
 
Fields inherited from class org.apache.commons.messagelet.impl.ServletResponseImpl
buffer, bufferCount, committed, contentCount, contentLength, contentType, encoding, error, included, locale, output, stream, writer
 
Fields inherited from interface javax.servlet.http.HttpServletResponse
SC_ACCEPTED, SC_BAD_GATEWAY, SC_BAD_REQUEST, SC_CONFLICT, SC_CONTINUE, SC_CREATED, SC_EXPECTATION_FAILED, SC_FORBIDDEN, SC_GATEWAY_TIMEOUT, SC_GONE, SC_HTTP_VERSION_NOT_SUPPORTED, SC_INTERNAL_SERVER_ERROR, SC_LENGTH_REQUIRED, SC_METHOD_NOT_ALLOWED, SC_MOVED_PERMANENTLY, SC_MOVED_TEMPORARILY, SC_MULTIPLE_CHOICES, SC_NO_CONTENT, SC_NON_AUTHORITATIVE_INFORMATION, SC_NOT_ACCEPTABLE, SC_NOT_FOUND, SC_NOT_IMPLEMENTED, SC_NOT_MODIFIED, SC_OK, SC_PARTIAL_CONTENT, SC_PAYMENT_REQUIRED, SC_PRECONDITION_FAILED, SC_PROXY_AUTHENTICATION_REQUIRED, SC_REQUEST_ENTITY_TOO_LARGE, SC_REQUEST_TIMEOUT, SC_REQUEST_URI_TOO_LONG, SC_REQUESTED_RANGE_NOT_SATISFIABLE, SC_RESET_CONTENT, SC_SEE_OTHER, SC_SERVICE_UNAVAILABLE, SC_SWITCHING_PROTOCOLS, SC_TEMPORARY_REDIRECT, SC_UNAUTHORIZED, SC_UNSUPPORTED_MEDIA_TYPE, SC_USE_PROXY
 
Constructor Summary
HttpServletResponseImpl()
           
 
Method Summary
 void addCookie(javax.servlet.http.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?
 String encodeRedirectUrl(String url)
          Deprecated. As of Version 2.1 of the Java Servlet API, use encodeRedirectURL() instead.
 String encodeRedirectURL(String url)
          Encode the session identifier associated with this response into the specified redirect URL, if necessary.
 String encodeUrl(String url)
          Deprecated. As of Version 2.1 of the Java Servlet API, use encodeURL() instead.
 String encodeURL(String url)
          Encode the session identifier associated with this response into the specified URL, if necessary.
 void flushBuffer()
          Flush the buffer and commit this response.
 javax.servlet.http.Cookie[] getCookies()
          Return an array of all cookies set for this response, or a zero-length array if no cookies have been set.
 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.
 String getMessage()
          Return the error message that was set with sendError() for this Response.
 int getStatus()
          Return the HTTP status code associated with this Response.
protected  String getStatusMessage(int status)
          Returns a default status message for the specified HTTP status code.
 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 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 setContentLength(int length)
          Set the content length (in bytes) for this Response.
 void setContentType(String type)
          Set the content type for this Response.
 void setDateHeader(String name, long value)
          Set the specified date header to the specified value.
 void setHeader(String name, String value)
          Set the specified header to the specified value.
 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 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.
 
Methods inherited from class org.apache.commons.messagelet.impl.ServletResponseImpl
createOutputStream, finishResponse, getBufferSize, getCharacterEncoding, getContentCount, getContentLength, getContentType, getLocale, getOutputStream, getStream, getWriter, isCommitted, resetBuffer, setBufferSize, setStream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.servlet.ServletResponse
getBufferSize, getCharacterEncoding, getLocale, getOutputStream, getWriter, isCommitted, resetBuffer, setBufferSize
 

Field Detail

cookies

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


format

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


headers

protected HashMap headers
The HTTP headers explicitly added via addHeader(), but not including those to be added with setContentLength(), setContentType(), and so on. This collection is keyed by the header name, and the elements are ArrayLists containing the associated values that have been set.


message

protected String message
The error message set by sendError().


status

protected int status
The HTTP status code associated with this Response.


zone

protected static final TimeZone zone
The time zone with which to construct date headers.

Constructor Detail

HttpServletResponseImpl

public HttpServletResponseImpl()
Method Detail

getCookies

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


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

getMessage

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


getStatus

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


recycle

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


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

getStatusMessage

protected String getStatusMessage(int status)
Returns a default status message for the specified HTTP status code.

Parameters:
status - The status code for which a message is desired

flushBuffer

public void flushBuffer()
                 throws IOException
Flush the buffer and commit this response. If this is the first output, send the HTTP headers prior to the user data.

Specified by:
flushBuffer in interface javax.servlet.ServletResponse
Overrides:
flushBuffer in class ServletResponseImpl
Throws:
IOException - if an input/output error occurs

reset

public void reset()
Clear any content written to the buffer. In addition, all cookies and headers are cleared, and the status is reset.

Specified by:
reset in interface javax.servlet.ServletResponse
Overrides:
reset in class ServletResponseImpl
Throws:
IllegalStateException - if this response has already been committed

setContentLength

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

Specified by:
setContentLength in interface javax.servlet.ServletResponse
Overrides:
setContentLength in class ServletResponseImpl
Parameters:
length - The new content length

setContentType

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

Specified by:
setContentType in interface javax.servlet.ServletResponse
Overrides:
setContentType in class ServletResponseImpl
Parameters:
type - The new content type

setLocale

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

Specified by:
setLocale in interface javax.servlet.ServletResponse
Overrides:
setLocale in class ServletResponseImpl
Parameters:
locale - The new locale

addCookie

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

Specified by:
addCookie in interface javax.servlet.http.HttpServletResponse
Parameters:
cookie - Cookie to be added

addDateHeader

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

Specified by:
addDateHeader in interface javax.servlet.http.HttpServletResponse
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.

Specified by:
addHeader in interface javax.servlet.http.HttpServletResponse
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.

Specified by:
addIntHeader in interface javax.servlet.http.HttpServletResponse
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?

Specified by:
containsHeader in interface javax.servlet.http.HttpServletResponse
Parameters:
name - Name of the header to check

encodeRedirectURL

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

Specified by:
encodeRedirectURL in interface javax.servlet.http.HttpServletResponse
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.

Specified by:
encodeRedirectUrl in interface javax.servlet.http.HttpServletResponse
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.

Specified by:
encodeURL in interface javax.servlet.http.HttpServletResponse
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.

Specified by:
encodeUrl in interface javax.servlet.http.HttpServletResponse
Parameters:
url - URL to be encoded

sendError

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

Specified by:
sendError in interface javax.servlet.http.HttpServletResponse
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)
               throws IOException
Send an error response with the specified status and message.

Specified by:
sendError in interface javax.servlet.http.HttpServletResponse
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)
                  throws IOException
Send a temporary redirect to the specified redirect location URL.

Specified by:
sendRedirect in interface javax.servlet.http.HttpServletResponse
Parameters:
location - Location URL to redirect to
Throws:
IllegalStateException - if this response has already been committed
IOException - if an input/output error occurs

setDateHeader

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

Specified by:
setDateHeader in interface javax.servlet.http.HttpServletResponse
Parameters:
name - Name of the header to set
value - Date value to be set

setHeader

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

Specified by:
setHeader in interface javax.servlet.http.HttpServletResponse
Parameters:
name - Name of the header to set
value - Value to be set

setIntHeader

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

Specified by:
setIntHeader in interface javax.servlet.http.HttpServletResponse
Parameters:
name - Name of the header to set
value - Integer value to be set

setStatus

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

Specified by:
setStatus in interface javax.servlet.http.HttpServletResponse
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.

Specified by:
setStatus in interface javax.servlet.http.HttpServletResponse
Parameters:
status - The new HTTP status
message - The associated text message


Copyright © 2001-2010 The Apache Software Foundation. All Rights Reserved.