Package com.sun.appserv.web.cache.filter
Class CachingResponseWrapper
- java.lang.Object
-
- jakarta.servlet.ServletResponseWrapper
-
- jakarta.servlet.http.HttpServletResponseWrapper
-
- com.sun.appserv.web.cache.filter.CachingResponseWrapper
-
- All Implemented Interfaces:
jakarta.servlet.http.HttpServletResponse,jakarta.servlet.ServletResponse
public class CachingResponseWrapper extends jakarta.servlet.http.HttpServletResponseWrappera wrapper to HttpServletResponse to cache the outbound headers and content- See Also:
and,HttpServletResponse
-
-
Field Summary
-
Fields inherited from interface jakarta.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
Constructors Constructor Description CachingResponseWrapper(jakarta.servlet.http.HttpServletResponse response)Constructs a response adaptor wrapping the given response.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddCookie(jakarta.servlet.http.Cookie cookie)The default behavior of this method is to call addCookie(Cookie cookie) on the wrapped response object.voidaddDateHeader(String name, long value)Add the specified date header to the specified value.voidaddHeader(String name, String value)Add the specified header to the specified value.voidaddIntHeader(String name, int value)Add the specified integer header to the specified value.HttpCacheEntrycacheResponse()called by doFilter to cache the response that was just sent outvoidclear()clear the contents of this wrapperLonggetExpiresDateHeader()return the Expires: date header valuejakarta.servlet.ServletOutputStreamgetOutputStream()Return the servlet output stream associated with this Response.PrintWritergetWriter()Return the writer associated with this Response.booleanisError()has the response been set to errorvoidsendError(int status)Send an error response with the specified status and a default message.voidsendError(int status, String message)Send an error response with the specified status and message.voidsetContentLength(int len)Set the content length (in bytes) for this Response.voidsetContentType(String type)Set the content type for this Response.voidsetDateHeader(String name, long value)Set the specified date header to the specified value.voidsetHeader(String name, String value)Set the specified header to the specified value.voidsetIntHeader(String name, int value)Set the specified integer header to the specified value.voidsetLocale(Locale locale)Set the Locale that is appropriate for this response, including setting the appropriate character encoding.voidsetStatus(int sc)Set the HTTP status to be returned with this response.-
Methods inherited from class jakarta.servlet.http.HttpServletResponseWrapper
containsHeader, encodeRedirectURL, encodeURL, getHeader, getHeaderNames, getHeaders, getStatus, getTrailerFields, sendRedirect, setTrailerFields
-
Methods inherited from class jakarta.servlet.ServletResponseWrapper
flushBuffer, getBufferSize, getCharacterEncoding, getContentType, getLocale, getResponse, isCommitted, isWrapperFor, isWrapperFor, reset, resetBuffer, setBufferSize, setCharacterEncoding, setContentLengthLong, setResponse
-
-
-
-
Constructor Detail
-
CachingResponseWrapper
public CachingResponseWrapper(jakarta.servlet.http.HttpServletResponse response)
Constructs a response adaptor wrapping the given response.- Throws:
IllegalArgumentException- if the response is null
-
-
Method Detail
-
getOutputStream
public jakarta.servlet.ServletOutputStream getOutputStream() throws IOExceptionReturn the servlet output stream associated with this Response.- Specified by:
getOutputStreamin interfacejakarta.servlet.ServletResponse- Overrides:
getOutputStreamin classjakarta.servlet.ServletResponseWrapper- Throws:
IllegalStateException- ifgetWriterhas already been called for this responseIOException- if an input/output error occurs
-
getWriter
public PrintWriter getWriter() throws IOException
Return the writer associated with this Response.- Specified by:
getWriterin interfacejakarta.servlet.ServletResponse- Overrides:
getWriterin classjakarta.servlet.ServletResponseWrapper- Throws:
IllegalStateException- ifgetOutputStreamhas already been called for this responseIOException- if an input/output error occurs
-
setContentLength
public void setContentLength(int len)
Set the content length (in bytes) for this Response.- Specified by:
setContentLengthin interfacejakarta.servlet.ServletResponse- Overrides:
setContentLengthin classjakarta.servlet.ServletResponseWrapper- Parameters:
len- The new content length
-
setContentType
public void setContentType(String type)
Set the content type for this Response.- Specified by:
setContentTypein interfacejakarta.servlet.ServletResponse- Overrides:
setContentTypein classjakarta.servlet.ServletResponseWrapper- 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:
setLocalein interfacejakarta.servlet.ServletResponse- Overrides:
setLocalein classjakarta.servlet.ServletResponseWrapper- Parameters:
locale- The new locale
-
addCookie
public void addCookie(jakarta.servlet.http.Cookie cookie)
The default behavior of this method is to call addCookie(Cookie cookie) on the wrapped response object.- Specified by:
addCookiein interfacejakarta.servlet.http.HttpServletResponse- Overrides:
addCookiein classjakarta.servlet.http.HttpServletResponseWrapper
-
setHeader
public void setHeader(String name, String value)
Set the specified header to the specified value.- Specified by:
setHeaderin interfacejakarta.servlet.http.HttpServletResponse- Overrides:
setHeaderin classjakarta.servlet.http.HttpServletResponseWrapper- Parameters:
name- Name of the header to setvalue- Value to be set
-
setIntHeader
public void setIntHeader(String name, int value)
Set the specified integer header to the specified value.- Specified by:
setIntHeaderin interfacejakarta.servlet.http.HttpServletResponse- Overrides:
setIntHeaderin classjakarta.servlet.http.HttpServletResponseWrapper- Parameters:
name- Name of the header to setvalue- Integer value to be set
-
addHeader
public void addHeader(String name, String value)
Add the specified header to the specified value.- Specified by:
addHeaderin interfacejakarta.servlet.http.HttpServletResponse- Overrides:
addHeaderin classjakarta.servlet.http.HttpServletResponseWrapper- Parameters:
name- Name of the header to setvalue- Value to be set
-
addIntHeader
public void addIntHeader(String name, int value)
Add the specified integer header to the specified value.- Specified by:
addIntHeaderin interfacejakarta.servlet.http.HttpServletResponse- Overrides:
addIntHeaderin classjakarta.servlet.http.HttpServletResponseWrapper- Parameters:
name- Name of the header to setvalue- Integer value to be set
-
setDateHeader
public void setDateHeader(String name, long value)
Set the specified date header to the specified value.- Specified by:
setDateHeaderin interfacejakarta.servlet.http.HttpServletResponse- Overrides:
setDateHeaderin classjakarta.servlet.http.HttpServletResponseWrapper- Parameters:
name- Name of the header to setvalue- Date value to be set
-
addDateHeader
public void addDateHeader(String name, long value)
Add the specified date header to the specified value.- Specified by:
addDateHeaderin interfacejakarta.servlet.http.HttpServletResponse- Overrides:
addDateHeaderin classjakarta.servlet.http.HttpServletResponseWrapper- Parameters:
name- Name of the header to setvalue- Date value to be set
-
setStatus
public void setStatus(int sc)
Set the HTTP status to be returned with this response.- Specified by:
setStatusin interfacejakarta.servlet.http.HttpServletResponse- Overrides:
setStatusin classjakarta.servlet.http.HttpServletResponseWrapper- Parameters:
sc- The new HTTP status
-
sendError
public void sendError(int status) throws IOExceptionSend an error response with the specified status and a default message.- Specified by:
sendErrorin interfacejakarta.servlet.http.HttpServletResponse- Overrides:
sendErrorin classjakarta.servlet.http.HttpServletResponseWrapper- Parameters:
status- HTTP status code to send- Throws:
IllegalStateException- if this response has already been committedIOException- if an input/output error occurs
-
sendError
public void sendError(int status, String message) throws IOExceptionSend an error response with the specified status and message.- Specified by:
sendErrorin interfacejakarta.servlet.http.HttpServletResponse- Overrides:
sendErrorin classjakarta.servlet.http.HttpServletResponseWrapper- Parameters:
status- HTTP status code to sendmessage- Corresponding message to send- Throws:
IllegalStateException- if this response has already been committedIOException- 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
-
-