|
Rakesh API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjavax.servlet.ServletResponseWrapper
javax.servlet.http.HttpServletResponseWrapper
org.rakeshv.filters.CachingResponseWrapper
public class CachingResponseWrapper
A HttpServletResponseWrapper class that is used to
create a cached output stream. This class
over-rides appropriate methods in the parent class to create
cached OutputStreams and PrintWriters.
© Copyright 2005, Rakesh Vidyadharan
| Field Summary | |
|---|---|
protected java.io.File |
cacheFile
The file to which the cached contents are to be written. |
private CachingFilter.FileProperties |
fileProperties
The CachingFilter.FileProperties that is to be
modified if the content properties for the response are
modified by objects down the filter chain. |
protected javax.servlet.http.HttpServletResponse |
servletResponse
Original response |
protected javax.servlet.ServletOutputStream |
stream
The ServletOutputStream that has been returned by
getOutputStream(), if any. |
protected java.io.PrintWriter |
writer
The PrintWriter that has been returned by getWriter(), if any. |
| 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(javax.servlet.http.HttpServletResponse response,
java.io.File file,
CachingFilter.FileProperties fileProperties)
Constructs a cached response adaptor wrapping the given response. |
|
| Method Summary | |
|---|---|
void |
addHeader(java.lang.String name,
java.lang.String value)
Add the specified header to the fileProperties |
void |
closeCacheFile()
Closes the cached file in the CachingResponseStream without
closing the underlying stream. |
javax.servlet.ServletOutputStream |
createOutputStream()
Create a new instance of the CachingResponseWrapper
class, that compresses the response. |
void |
flushBuffer()
Forces any content in the buffer to be written to the client. |
javax.servlet.ServletOutputStream |
getOutputStream()
Returns a ServletOutputStream suitable for writing binary data in the response. |
java.io.PrintWriter |
getWriter()
Returns a PrintWriter object that can send character text to the client. |
void |
setCharacterEncoding(java.lang.String charset)
Update the property in the fileProperties and then pass
along to the super class implementation. |
void |
setContentType(java.lang.String type)
Update the property in the fileProperties and then pass
along to the super class implementation. |
void |
setHeader(java.lang.String name,
java.lang.String value)
Add the specified header to the fileProperties |
void |
setLocale(java.util.Locale locale)
Update the property in the fileProperties and then pass
along to the super class implementation. |
void |
setStatus(int status)
If the status is not equal to SC_OK, indicate to the
fileProperties that the response should not be cached. |
| Methods inherited from class javax.servlet.http.HttpServletResponseWrapper |
|---|
addCookie, addDateHeader, addIntHeader, containsHeader, encodeRedirectUrl, encodeRedirectURL, encodeUrl, encodeURL, sendError, sendError, sendRedirect, setDateHeader, setIntHeader, setStatus |
| Methods inherited from class javax.servlet.ServletResponseWrapper |
|---|
getBufferSize, getCharacterEncoding, getContentType, getLocale, getResponse, isCommitted, reset, resetBuffer, 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, getContentType, getLocale, isCommitted, reset, resetBuffer, setBufferSize, setContentLength |
| Field Detail |
|---|
protected javax.servlet.http.HttpServletResponse servletResponse
protected javax.servlet.ServletOutputStream stream
ServletOutputStream that has been returned by
getOutputStream(), if any.
protected java.io.PrintWriter writer
protected java.io.File cacheFile
private CachingFilter.FileProperties fileProperties
CachingFilter.FileProperties that is to be
modified if the content properties for the response are
modified by objects down the filter chain.
| Constructor Detail |
|---|
public CachingResponseWrapper(javax.servlet.http.HttpServletResponse response,
java.io.File file,
CachingFilter.FileProperties fileProperties)
throws java.lang.IllegalArgumentException
super-class constructor, and
set the servletResponse reference.
response - The response that is to be cached.file - The file to which the contents are to be cached.fileProperties - The FileProperties that will
be passed along to the CachingResponseStream.
java.lang.IllegalArgumentException - If the specified response is
null.| Method Detail |
|---|
public javax.servlet.ServletOutputStream createOutputStream()
throws java.io.IOException
CachingResponseWrapper
class, that compresses the response.
DeflaterOutputStream
.
java.io.IOException - If exceptions are encountered while
creating the cached response stream.
public void flushBuffer()
throws java.io.IOException
flushBuffer in interface javax.servlet.ServletResponseflushBuffer in class javax.servlet.ServletResponseWrapperjava.io.IOException
public javax.servlet.ServletOutputStream getOutputStream()
throws java.io.IOException
Writer has not already been
created for the response (through a call to getWriter()
method) a new instance of the CachingResponseStream
is created, and the instance variable stream set to the
new instance created. If the stream has already been
initialised, then the reference is returned.
getOutputStream in interface javax.servlet.ServletResponsegetOutputStream in class javax.servlet.ServletResponseWrapperjava.io.IOException - If errors are encountered while creating
the cached response stream.
java.lang.IllegalStateException - If getWriter() has
already been called on this instance.
public java.io.PrintWriter getWriter()
throws java.io.IOException
CachingResponseStream class. The character encoding
used is the one specified in the charset= property of the
setContentType( java.lang.String ) method, which must
be called before calling this method for the charset to take
effect.
If necessary, the MIME type of the response is modified to reflect the character encoding used.
Either this method or getOutputStream() may be called
to write the body, not both.
getWriter in interface javax.servlet.ServletResponsegetWriter in class javax.servlet.ServletResponseWrapperjava.io.IOException - If errors are encountered while creating
the cached response stream.
java.lang.IllegalStateException - If getWriter() has
already been called on this instance.
public void closeCacheFile()
throws java.io.IOException
CachingResponseStream without
closing the underlying stream.
Note: This method must be invoked by to ensure that the cache file that was generated is properly closed after the actual response was generated.
java.io.IOException - - If errors are encountered while closing
the file.
public void addHeader(java.lang.String name,
java.lang.String value)
fileProperties
addHeader in interface javax.servlet.http.HttpServletResponseaddHeader in class javax.servlet.http.HttpServletResponseWrappername - The name of the headervalue - The value of the header
public void setHeader(java.lang.String name,
java.lang.String value)
fileProperties
setHeader in interface javax.servlet.http.HttpServletResponsesetHeader in class javax.servlet.http.HttpServletResponseWrappername - The name of the headervalue - The value of the headerpublic void setCharacterEncoding(java.lang.String charset)
fileProperties and then pass
along to the super class implementation.
setCharacterEncoding in interface javax.servlet.ServletResponsesetCharacterEncoding in class javax.servlet.ServletResponseWrappercharset - A String specifying only the character set defined
by IANA Character Sets (http://www.iana.org/assignments/character-sets)public void setContentType(java.lang.String type)
fileProperties and then pass
along to the super class implementation.
setContentType in interface javax.servlet.ServletResponsesetContentType in class javax.servlet.ServletResponseWrappertype - A String specifying the MIME type of the contentpublic void setLocale(java.util.Locale locale)
fileProperties and then pass
along to the super class implementation.
setLocale in interface javax.servlet.ServletResponsesetLocale in class javax.servlet.ServletResponseWrapperlocale - The locale of the responsepublic void setStatus(int status)
SC_OK, indicate to the
fileProperties that the response should not be cached.
setStatus in interface javax.servlet.http.HttpServletResponsesetStatus in class javax.servlet.http.HttpServletResponseWrapperstatus - The status code to set for the response.
|
Rakesh API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||