com.opensymphony.oscache.web.filter
Class CacheHttpServletResponseWrapper

java.lang.Object
  extended by javax.servlet.ServletResponseWrapper
      extended by javax.servlet.http.HttpServletResponseWrapper
          extended by com.opensymphony.oscache.web.filter.CacheHttpServletResponseWrapper
All Implemented Interfaces:
javax.servlet.http.HttpServletResponse, javax.servlet.ServletResponse

public class CacheHttpServletResponseWrapper
extends javax.servlet.http.HttpServletResponseWrapper

CacheServletResponse is a serialized representation of a response

Version:
$Revision: 469 $
Author:
Serge Knystautas

Field Summary
private  long cacheControl
           
private  PrintWriter cachedWriter
          We cache the printWriter so we can maintain a single instance of it no matter how many times it is requested.
private  SplitServletOutputStream cacheOut
           
private  long expires
           
private  boolean fragment
           
private  long lastModified
           
private  org.apache.commons.logging.Log log
           
private  ResponseContent result
           
private  int status
           
 
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
CacheHttpServletResponseWrapper(javax.servlet.http.HttpServletResponse response)
          Constructor
CacheHttpServletResponseWrapper(javax.servlet.http.HttpServletResponse response, boolean fragment, long time, long lastModified, long expires, long cacheControl)
          Constructor
 
Method Summary
 void addDateHeader(String name, long value)
          Add the date of a header
 void addHeader(String name, String value)
          Add a header field
private  void flush()
          Flushes all streams.
 void flushBuffer()
           
 ResponseContent getContent()
          Get a response content
 javax.servlet.ServletOutputStream getOutputStream()
          Get an output stream
 int getStatus()
          Retrieves the captured HttpResponse status.
 PrintWriter getWriter()
          Get a print writer
 boolean isCommitted()
          Returns a boolean indicating if the response has been committed.
 void reset()
          Clears any data that exists in the buffer as well as the status code and headers.
 void resetBuffer()
          Clears the content of the underlying buffer in the response without clearing headers or status code.
 void sendError(int status)
          We override this so we can catch the response status.
 void sendError(int status, String string)
          We override this so we can catch the response status.
 void sendRedirect(String location)
          We override this so we can catch the response status.
 void setContentType(String value)
          Set the content type
 void setDateHeader(String name, long value)
          Set the date of a header
 void setHeader(String name, String value)
          Set a header field
 void setIntHeader(String name, int value)
          Set the int value of the header
 void setLocale(Locale value)
          Set the locale
 void setStatus(int status)
          We override this so we can catch the response status.
 void setStatus(int status, String string)
          We override this so we can catch the response status.
 
Methods inherited from class javax.servlet.http.HttpServletResponseWrapper
addCookie, addIntHeader, containsHeader, encodeRedirectUrl, encodeRedirectURL, encodeUrl, encodeURL
 
Methods inherited from class javax.servlet.ServletResponseWrapper
getBufferSize, getCharacterEncoding, getLocale, getResponse, setBufferSize, setContentLength, 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, setBufferSize, setContentLength
 

Field Detail

log

private final org.apache.commons.logging.Log log

cachedWriter

private PrintWriter cachedWriter
We cache the printWriter so we can maintain a single instance of it no matter how many times it is requested.


result

private ResponseContent result

cacheOut

private SplitServletOutputStream cacheOut

fragment

private boolean fragment

status

private int status

expires

private long expires

lastModified

private long lastModified

cacheControl

private long cacheControl
Constructor Detail

CacheHttpServletResponseWrapper

public CacheHttpServletResponseWrapper(javax.servlet.http.HttpServletResponse response)
Constructor

Parameters:
response - The servlet response

CacheHttpServletResponseWrapper

public CacheHttpServletResponseWrapper(javax.servlet.http.HttpServletResponse response,
                                       boolean fragment,
                                       long time,
                                       long lastModified,
                                       long expires,
                                       long cacheControl)
Constructor

Parameters:
response - The servlet response
fragment - true if the repsonse indicates that it is a fragement of a page
time - the refresh time in millis
lastModified - defines if last modified header will be send, @see CacheFilter
expires - defines if expires header will be send, @see CacheFilter
cacheControl - defines if cache control header will be send, @see CacheFilter
Method Detail

getContent

public ResponseContent getContent()
Get a response content

Returns:
The content

setContentType

public void setContentType(String value)
Set the content type

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

setDateHeader

public void setDateHeader(String name,
                          long value)
Set the date of a header

Specified by:
setDateHeader in interface javax.servlet.http.HttpServletResponse
Overrides:
setDateHeader in class javax.servlet.http.HttpServletResponseWrapper
Parameters:
name - The header name
value - The date

addDateHeader

public void addDateHeader(String name,
                          long value)
Add the date of a header

Specified by:
addDateHeader in interface javax.servlet.http.HttpServletResponse
Overrides:
addDateHeader in class javax.servlet.http.HttpServletResponseWrapper
Parameters:
name - The header name
value - The date

setHeader

public void setHeader(String name,
                      String value)
Set a header field

Specified by:
setHeader in interface javax.servlet.http.HttpServletResponse
Overrides:
setHeader in class javax.servlet.http.HttpServletResponseWrapper
Parameters:
name - The header name
value - The header value

addHeader

public void addHeader(String name,
                      String value)
Add a header field

Specified by:
addHeader in interface javax.servlet.http.HttpServletResponse
Overrides:
addHeader in class javax.servlet.http.HttpServletResponseWrapper
Parameters:
name - The header name
value - The header value

setIntHeader

public void setIntHeader(String name,
                         int value)
Set the int value of the header

Specified by:
setIntHeader in interface javax.servlet.http.HttpServletResponse
Overrides:
setIntHeader in class javax.servlet.http.HttpServletResponseWrapper
Parameters:
name - The header name
value - The int value

setStatus

public void setStatus(int status)
We override this so we can catch the response status. Only responses with a status of 200 (SC_OK) will be cached.

Specified by:
setStatus in interface javax.servlet.http.HttpServletResponse
Overrides:
setStatus in class javax.servlet.http.HttpServletResponseWrapper

sendError

public void sendError(int status,
                      String string)
               throws IOException
We override this so we can catch the response status. Only responses with a status of 200 (SC_OK) will be cached.

Specified by:
sendError in interface javax.servlet.http.HttpServletResponse
Overrides:
sendError in class javax.servlet.http.HttpServletResponseWrapper
Throws:
IOException

sendError

public void sendError(int status)
               throws IOException
We override this so we can catch the response status. Only responses with a status of 200 (SC_OK) will be cached.

Specified by:
sendError in interface javax.servlet.http.HttpServletResponse
Overrides:
sendError in class javax.servlet.http.HttpServletResponseWrapper
Throws:
IOException

setStatus

public void setStatus(int status,
                      String string)
We override this so we can catch the response status. Only responses with a status of 200 (SC_OK) will be cached.

Specified by:
setStatus in interface javax.servlet.http.HttpServletResponse
Overrides:
setStatus in class javax.servlet.http.HttpServletResponseWrapper

sendRedirect

public void sendRedirect(String location)
                  throws IOException
We override this so we can catch the response status. Only responses with a status of 200 (SC_OK) will be cached.

Specified by:
sendRedirect in interface javax.servlet.http.HttpServletResponse
Overrides:
sendRedirect in class javax.servlet.http.HttpServletResponseWrapper
Throws:
IOException

getStatus

public int getStatus()
Retrieves the captured HttpResponse status.


setLocale

public void setLocale(Locale value)
Set the locale

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

getOutputStream

public javax.servlet.ServletOutputStream getOutputStream()
                                                  throws IOException
Get an output stream

Specified by:
getOutputStream in interface javax.servlet.ServletResponse
Overrides:
getOutputStream in class javax.servlet.ServletResponseWrapper
Throws:
IOException

getWriter

public PrintWriter getWriter()
                      throws IOException
Get a print writer

Specified by:
getWriter in interface javax.servlet.ServletResponse
Overrides:
getWriter in class javax.servlet.ServletResponseWrapper
Throws:
IOException

flush

private void flush()
            throws IOException
Flushes all streams.

Throws:
IOException

flushBuffer

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

isCommitted

public boolean isCommitted()
Returns a boolean indicating if the response has been committed. A commited response has already had its status code and headers written.

Specified by:
isCommitted in interface javax.servlet.ServletResponse
Overrides:
isCommitted in class javax.servlet.ServletResponseWrapper
See Also:
ServletResponseWrapper.isCommitted()

reset

public void reset()
Clears any data that exists in the buffer as well as the status code and headers. If the response has been committed, this method throws an IllegalStateException.

Specified by:
reset in interface javax.servlet.ServletResponse
Overrides:
reset in class javax.servlet.ServletResponseWrapper
See Also:
ServletResponseWrapper.reset()

resetBuffer

public void resetBuffer()
Clears the content of the underlying buffer in the response without clearing headers or status code. If the response has been committed, this method throws an IllegalStateException.

Specified by:
resetBuffer in interface javax.servlet.ServletResponse
Overrides:
resetBuffer in class javax.servlet.ServletResponseWrapper
See Also:
ServletResponseWrapper.resetBuffer()


Copyright © 2011 OpenSymphony. All Rights Reserved.