org.riotfamily.cachius.servlet
Class CachiusResponseWrapper

java.lang.Object
  extended by javax.servlet.ServletResponseWrapper
      extended by javax.servlet.http.HttpServletResponseWrapper
          extended by org.riotfamily.cachius.servlet.CachiusResponseWrapper
All Implemented Interfaces:
HttpServletResponse, ServletResponse

public class CachiusResponseWrapper
extends HttpServletResponseWrapper

A HttpServletResponseWrapper that captures the response and updates the associated CacheItem.

Author:
Felix Gnass

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
CachiusResponseWrapper(HttpServletResponse response, CacheItem cacheItem, SessionIdEncoder sessionIdEncoder)
           
 
Method Summary
 void addCookie(Cookie cookie)
           
 void addDateHeader(String name, long date)
           
 void addHeader(String name, String value)
           
 void addIntHeader(String name, int value)
           
 String encodeRedirectUrl(String url)
          Delegates the call to encodeRedirectURL(String).
 String encodeRedirectURL(String url)
          Delegates the call to SessionIdEncoder.encodeRedirectURL(String) to ensure that the session state remains the same during processing.
 String encodeUrl(String url)
          Delegates the call to encodeURL(String).
 String encodeURL(String url)
          Delegates the call to SessionIdEncoder.encodeURL(String) to ensure that the session state remains the same during processing.
 void flushBuffer()
           
 String getContentType()
           
 ServletOutputStream getOutputStream()
          Returns an ServletOutputStream that writes into the OutputStream provided by the CacheItem.
 PrintWriter getWriter()
          Returns a PrintWriter that writes into the Writer provided by the CacheItem.
 boolean isOk()
           
 void setContentLength(int len)
           
 void setContentType(String contentType)
           
 void setDateHeader(String name, long date)
           
 void setHeader(String name, String value)
           
 void setIntHeader(String name, int value)
           
 void setStatus(int status)
           
 void stopCapturing()
           
 void updateHeaders()
          Sets the captured headers on the CacheItem.
 
Methods inherited from class javax.servlet.http.HttpServletResponseWrapper
containsHeader, sendError, sendError, sendRedirect, setStatus
 
Methods inherited from class javax.servlet.ServletResponseWrapper
getBufferSize, getCharacterEncoding, getLocale, getResponse, isCommitted, reset, resetBuffer, setBufferSize, setCharacterEncoding, setLocale, 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
getBufferSize, getCharacterEncoding, getLocale, isCommitted, reset, resetBuffer, setBufferSize, setCharacterEncoding, setLocale
 

Constructor Detail

CachiusResponseWrapper

public CachiusResponseWrapper(HttpServletResponse response,
                              CacheItem cacheItem,
                              SessionIdEncoder sessionIdEncoder)
Method Detail

setStatus

public void setStatus(int status)
Specified by:
setStatus in interface HttpServletResponse
Overrides:
setStatus in class HttpServletResponseWrapper

isOk

public boolean isOk()

getContentType

public String getContentType()
Specified by:
getContentType in interface ServletResponse
Overrides:
getContentType in class ServletResponseWrapper

setContentType

public void setContentType(String contentType)
Specified by:
setContentType in interface ServletResponse
Overrides:
setContentType in class ServletResponseWrapper

setContentLength

public void setContentLength(int len)
Specified by:
setContentLength in interface ServletResponse
Overrides:
setContentLength in class ServletResponseWrapper

addDateHeader

public void addDateHeader(String name,
                          long date)
Specified by:
addDateHeader in interface HttpServletResponse
Overrides:
addDateHeader in class HttpServletResponseWrapper

setDateHeader

public void setDateHeader(String name,
                          long date)
Specified by:
setDateHeader in interface HttpServletResponse
Overrides:
setDateHeader in class HttpServletResponseWrapper

addIntHeader

public void addIntHeader(String name,
                         int value)
Specified by:
addIntHeader in interface HttpServletResponse
Overrides:
addIntHeader in class HttpServletResponseWrapper

setIntHeader

public void setIntHeader(String name,
                         int value)
Specified by:
setIntHeader in interface HttpServletResponse
Overrides:
setIntHeader in class HttpServletResponseWrapper

addHeader

public void addHeader(String name,
                      String value)
Specified by:
addHeader in interface HttpServletResponse
Overrides:
addHeader in class HttpServletResponseWrapper

setHeader

public void setHeader(String name,
                      String value)
Specified by:
setHeader in interface HttpServletResponse
Overrides:
setHeader in class HttpServletResponseWrapper

addCookie

public void addCookie(Cookie cookie)
Specified by:
addCookie in interface HttpServletResponse
Overrides:
addCookie in class HttpServletResponseWrapper

getOutputStream

public ServletOutputStream getOutputStream()
                                    throws IOException
Returns an ServletOutputStream that writes into the OutputStream provided by the CacheItem. All output is redirected so nothing will be sent to the client.

Specified by:
getOutputStream in interface ServletResponse
Overrides:
getOutputStream in class ServletResponseWrapper
Throws:
IllegalStateException - If getWriter() has been called before
IOException

getWriter

public PrintWriter getWriter()
                      throws IOException
Returns a PrintWriter that writes into the Writer provided by the CacheItem. All output is redirected so nothing will be sent to the client.

Specified by:
getWriter in interface ServletResponse
Overrides:
getWriter in class ServletResponseWrapper
Throws:
IllegalStateExcepion - If getOutputStream() has been called before
IOException

flushBuffer

public void flushBuffer()
                 throws IOException
Specified by:
flushBuffer in interface ServletResponse
Overrides:
flushBuffer in class ServletResponseWrapper
Throws:
IOException

stopCapturing

public void stopCapturing()
                   throws IOException
Throws:
IOException

updateHeaders

public void updateHeaders()
Sets the captured headers on the CacheItem.


encodeRedirectURL

public String encodeRedirectURL(String url)
Delegates the call to SessionIdEncoder.encodeRedirectURL(String) to ensure that the session state remains the same during processing.

Specified by:
encodeRedirectURL in interface HttpServletResponse
Overrides:
encodeRedirectURL in class HttpServletResponseWrapper

encodeRedirectUrl

public String encodeRedirectUrl(String url)
Delegates the call to encodeRedirectURL(String).

Specified by:
encodeRedirectUrl in interface HttpServletResponse
Overrides:
encodeRedirectUrl in class HttpServletResponseWrapper

encodeURL

public String encodeURL(String url)
Delegates the call to SessionIdEncoder.encodeURL(String) to ensure that the session state remains the same during processing.

Specified by:
encodeURL in interface HttpServletResponse
Overrides:
encodeURL in class HttpServletResponseWrapper

encodeUrl

public String encodeUrl(String url)
Delegates the call to encodeURL(String).

Specified by:
encodeUrl in interface HttpServletResponse
Overrides:
encodeUrl in class HttpServletResponseWrapper