Java EE 5 SDK

com.sun.appserv.web.cache.filter
Class CachingResponseWrapper

java.lang.Object
  extended by javax.servlet.ServletResponseWrapper
      extended by javax.servlet.http.HttpServletResponseWrapper
          extended by com.sun.appserv.web.cache.filter.CachingResponseWrapper
All Implemented Interfaces:
HttpServletResponse, ServletResponse

public class CachingResponseWrapper
extends HttpServletResponseWrapper

a wrapper to HttpServletResponse to cache the outbound headers and content

See Also:
and, HttpServletResponse, org.apache.catalina.connector.HttpResponseBase

Field Summary
 
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_FOUND, 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
CachingResponseWrapper(HttpServletResponse response)
          Constructs a response adaptor wrapping the given response.
 
Method Summary
 void addCookie(Cookie cookie)
          The default behavior of this method is to call addCookie(Cookie cookie) on the wrapped response object.
 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.
 HttpCacheEntry cacheResponse()
          called by doFilter to cache the response that was just sent out
 void clear()
          clear the contents of this wrapper
 Long getExpiresDateHeader()
          return the Expires: date header value
 ServletOutputStream getOutputStream()
          Return the servlet output stream associated with this Response.
 PrintWriter getWriter()
          Return the writer associated with this Response.
 boolean isError()
          has the response been set to error
 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 setContentLength(int len)
          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 sc)
          Set the HTTP status to be returned with this response.
 
Methods inherited from class javax.servlet.http.HttpServletResponseWrapper
containsHeader, encodeRedirectUrl, encodeRedirectURL, encodeUrl, encodeURL, sendRedirect, setStatus
 
Methods inherited from class javax.servlet.ServletResponseWrapper
flushBuffer, getBufferSize, getCharacterEncoding, getContentType, getLocale, getResponse, isCommitted, reset, resetBuffer, setBufferSize, setCharacterEncoding, setResponse
 
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
flushBuffer, getBufferSize, getCharacterEncoding, getContentType, getLocale, isCommitted, reset, resetBuffer, setBufferSize, setCharacterEncoding
 

Constructor Detail

CachingResponseWrapper

public CachingResponseWrapper(HttpServletResponse response)
Constructs a response adaptor wrapping the given response.

Throws:
IllegalArgumentException - if the response is null
Method Detail

getOutputStream

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

Specified by:
getOutputStream in interface ServletResponse
Overrides:
getOutputStream in class ServletResponseWrapper
Returns:
a ServletOutputStream for writing binary data
Throws:
IllegalStateException - if getWriter has already been called for this response
IOException - if an input/output error occurs
See Also:
ServletResponse.getWriter()

getWriter

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

Specified by:
getWriter in interface ServletResponse
Overrides:
getWriter in class ServletResponseWrapper
Returns:
a PrintWriter object that can return character data to the client
Throws:
IllegalStateException - if getOutputStream has already been called for this response
IOException - if an input/output error occurs
See Also:
ServletResponse.getOutputStream(), ServletResponse.setCharacterEncoding(java.lang.String)

setContentLength

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

Specified by:
setContentLength in interface ServletResponse
Overrides:
setContentLength in class ServletResponseWrapper
Parameters:
len - The new content length

setContentType

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

Specified by:
setContentType in interface ServletResponse
Overrides:
setContentType in class ServletResponseWrapper
Parameters:
type - The new content type
See Also:
ServletResponse.setLocale(java.util.Locale), ServletResponse.setCharacterEncoding(java.lang.String), ServletResponse.getOutputStream(), ServletResponse.getWriter()

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 ServletResponse
Overrides:
setLocale in class ServletResponseWrapper
Parameters:
locale - The new locale
See Also:
ServletResponse.getLocale(), ServletResponse.setContentType(java.lang.String), ServletResponse.setCharacterEncoding(java.lang.String)

addCookie

public void addCookie(Cookie cookie)
The default behavior of this method is to call addCookie(Cookie cookie) on the wrapped response object.

Specified by:
addCookie in interface HttpServletResponse
Overrides:
addCookie in class HttpServletResponseWrapper
Parameters:
cookie - the Cookie to return to the client

setHeader

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

Specified by:
setHeader in interface HttpServletResponse
Overrides:
setHeader in class HttpServletResponseWrapper
Parameters:
name - Name of the header to set
value - Value to be set
See Also:
HttpServletResponse.containsHeader(java.lang.String), HttpServletResponse.addHeader(java.lang.String, java.lang.String)

setIntHeader

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

Specified by:
setIntHeader in interface HttpServletResponse
Overrides:
setIntHeader in class HttpServletResponseWrapper
Parameters:
name - Name of the header to set
value - Integer value to be set
See Also:
HttpServletResponse.containsHeader(java.lang.String), HttpServletResponse.addIntHeader(java.lang.String, int)

addHeader

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

Specified by:
addHeader in interface HttpServletResponse
Overrides:
addHeader in class HttpServletResponseWrapper
Parameters:
name - Name of the header to set
value - Value to be set
See Also:
HttpServletResponse.setHeader(java.lang.String, java.lang.String)

addIntHeader

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

Specified by:
addIntHeader in interface HttpServletResponse
Overrides:
addIntHeader in class HttpServletResponseWrapper
Parameters:
name - Name of the header to set
value - Integer value to be set
See Also:
HttpServletResponse.setIntHeader(java.lang.String, int)

setDateHeader

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

Specified by:
setDateHeader in interface HttpServletResponse
Overrides:
setDateHeader in class HttpServletResponseWrapper
Parameters:
name - Name of the header to set
value - Date value to be set
See Also:
HttpServletResponse.containsHeader(java.lang.String), HttpServletResponse.addDateHeader(java.lang.String, long)

addDateHeader

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

Specified by:
addDateHeader in interface HttpServletResponse
Overrides:
addDateHeader in class HttpServletResponseWrapper
Parameters:
name - Name of the header to set
value - Date value to be set
See Also:
HttpServletResponse.setDateHeader(java.lang.String, long)

setStatus

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

Specified by:
setStatus in interface HttpServletResponse
Overrides:
setStatus in class HttpServletResponseWrapper
Parameters:
sc - The new HTTP status
See Also:
HttpServletResponse.sendError(int, java.lang.String)

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 HttpServletResponse
Overrides:
sendError in class HttpServletResponseWrapper
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 HttpServletResponse
Overrides:
sendError in class HttpServletResponseWrapper
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

isError

public boolean isError()
has the response been set to error


getExpiresDateHeader

public Long getExpiresDateHeader()
return the Expires: date header value


cacheResponse

public HttpCacheEntry cacheResponse()
                             throws IOException
called by doFilter to cache the response that was just sent out

Returns:
the entry with cached response headers and body.
Throws:
IOException

clear

public void clear()
clear the contents of this wrapper


Java EE 5 SDK

Submit a bug or feature

Copyright 2006 Sun Microsystems, Inc. All rights reserved.