ActionContextCleanUppublic class ActionContextCleanUp extends Object implements Filter
Special filter designed to work with the {@link FilterDispatcher} and allow
for easier integration with SiteMesh. Normally, ordering your filters to have
SiteMesh go first, and then {@link FilterDispatcher} go second is perfectly fine.
However, sometimes you may wish to access Struts features, including the
value stack, from within your SiteMesh decorators. Because {@link FilterDispatcher}
cleans up the {@link ActionContext}, your decorator won't have access to the
data you want.
By adding this filter, the {@link FilterDispatcher} will know to not clean up and
instead defer cleanup to this filter. The ordering of the filters should then be:
- this filter
- SiteMesh filter
- {@link FilterDispatcher}
|
Fields Summary |
---|
private static final Log | LOG | private static final String | COUNTER |
Methods Summary |
---|
protected static void | cleanUp(javax.servlet.ServletRequest req)Clean up the request of threadlocals if this is the last execution
// should we clean up yet?
Integer count = (Integer) req.getAttribute(COUNTER);
if (count != null && count > 0 ) {
if (LOG.isDebugEnabled()) {
LOG.debug("skipping cleanup counter="+count);
}
return;
}
// always dontClean up the thread request, even if an action hasn't been executed
ActionContext.setContext(null);
Dispatcher.setInstance(null);
| public void | destroy()
| public void | doFilter(javax.servlet.ServletRequest req, javax.servlet.ServletResponse res, javax.servlet.FilterChain chain)
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
String timerKey = "ActionContextCleanUp_doFilter: ";
try {
UtilTimerStack.push(timerKey);
try {
Integer count = (Integer)request.getAttribute(COUNTER);
if (count == null) {
count = new Integer(1);
}
else {
count = new Integer(count.intValue()+1);
}
request.setAttribute(COUNTER, count);
//LOG.debug("filtering counter="+count);
chain.doFilter(request, response);
} finally {
int counterVal = ((Integer)request.getAttribute(COUNTER)).intValue();
counterVal -= 1;
request.setAttribute(COUNTER, new Integer(counterVal));
cleanUp(request);
}
}
finally {
UtilTimerStack.pop(timerKey);
}
| public void | init(javax.servlet.FilterConfig arg0)
|
|