|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.lowagie.servlets.OutputFilterBase
Base filter to enable filtering on the output of a resource, instead of the input. This filter calls the filter chain before calling the
perform()
method, making the output of the filter chain available to said method.
Field Summary | |
static String |
EXCEPTION_KEY
Where the exception caught when executing perform() is stored in the request (so that it can be used on customized error pages). |
protected FilterConfig |
fConfig
|
private static String |
FILTER_APPLIED
|
static String |
PREVENT_FILTER
Key where to store an object in the request if you do not want the output filter applied on this request. |
Constructor Summary | |
OutputFilterBase()
|
Method Summary | |
void |
destroy()
|
void |
doFilter(ServletRequest request,
ServletResponse response,
FilterChain chain)
Prepares the filter before calling the filter chain. |
protected void |
dump(BufferedResponse data,
ServletResponse res)
Dumps the contents of the passed BufferedResponse to the ServletResponse. |
protected void |
dump(InputStream in,
ServletResponse res)
Dumps the data from the InputStream passed to the ServletResponse's OutputStream. |
FilterConfig |
getFilterConfig()
|
void |
init(FilterConfig filterConfig)
|
protected abstract void |
perform(ServletRequest request,
ServletResponse response,
InputStream data)
This method should contain the logic to manipulate the data coming from the resources called by the filter chain and send the data to the response object received. |
protected ServletRequest |
prepareRequest(ServletRequest request)
This method is called before executing the filter chain. |
protected BufferedResponse |
prepareResponse(ServletRequest request,
ServletResponse response)
This method is called before executing the filter chain, and should return a BufferedResponse objeto to be sent to the chain. |
protected void |
sendError(ServletRequest req,
HttpServletResponse res,
Throwable t)
Stores the throwable in the EXCEPTION_KEY attribute of the request and sends an "Internal Server Error" to the response with the message from the error. |
void |
setFilterConfig(FilterConfig filterConfig)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private static final String FILTER_APPLIED
public static final String PREVENT_FILTER
public static final String EXCEPTION_KEY
protected FilterConfig fConfig
Constructor Detail |
public OutputFilterBase()
Method Detail |
public final void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
Prepares the filter before calling the filter chain. This enables the implementing class to provide customized ServletRequest and ServletResponse objects to the chain.
After calling the chain, if a object is found under the "PREVENT_FILTER" key in the ServletRequest objeto, the output filter is not executed (that is, the perform() method is not called). If this situation is detected, the buffer received from the chain is copied to the original ServletResponse object.
Also, if the response has been committed (e.g., by calling sendError() on the response), the filter is not applied.
If an exception occurs during the execution of the perform() method, a Internal Server Error is sent to the response with the exception message. The exception is stored under the "EXCEPTION_KEY" key of the request.
request
- The request from the filter chain (or from the browser,
if this is the first filter).response
- The response from the filter chain (or browser).chain
- The filter chain.
IOException
ServletException
protected ServletRequest prepareRequest(ServletRequest request)
This method is called before executing the filter chain. It should return a ServletRequest object to be provided to the chain. The default implementation just returns the request object passed.
request
- The request received from the filter chain.
protected BufferedResponse prepareResponse(ServletRequest request, ServletResponse response) throws IOException
This method is called before executing the filter chain, and should return a BufferedResponse objeto to be sent to the chain. This implementation uses the default BufferedResponse implementation, that stores data received from the resources called from the chain in a memory buffer.
request
- The request from the filter chain.response
- The response from the filter chain.
IOException
protected abstract void perform(ServletRequest request, ServletResponse response, InputStream data) throws Exception
This method should contain the logic to manipulate the data coming from the resources called by the filter chain and send the data to the response object received.
request
- The original request received from the chain.response
- The original response received from the chain.data
- An InputStream containing the buffer that stores
the data from the called resources.
Exception
protected void dump(BufferedResponse data, ServletResponse res) throws IOException
Dumps the contents of the passed BufferedResponse to the ServletResponse. Before dumping the data itself, sets the original content type and the original content length.
data
- A BufferedResponse object.res
- A ServletResponse where to dump the data to.
IOException
protected void dump(InputStream in, ServletResponse res) throws IOException
Dumps the data from the InputStream passed to the ServletResponse's OutputStream.
in
- An input stream.res
- A ServletResponse where to dump the data to.
IOException
protected void sendError(ServletRequest req, HttpServletResponse res, Throwable t) throws IOException
Stores the throwable in the EXCEPTION_KEY attribute of the request and sends an "Internal Server Error" to the response with the message from the error.
IOException
public void init(FilterConfig filterConfig) throws ServletException
ServletException
public void destroy()
public FilterConfig getFilterConfig()
public void setFilterConfig(FilterConfig filterConfig)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |