org.apache.struts2.dispatcher
public class: ActionContextCleanUp [javadoc |
source]
java.lang.Object
org.apache.struts2.dispatcher.ActionContextCleanUp
All Implemented Interfaces:
Filter
Special filter designed to work with the
FilterDispatcher and allow
for easier integration with SiteMesh. Normally, ordering your filters to have
SiteMesh go first, and then
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
FilterDispatcher
cleans up the
ActionContext , your decorator won't have access to the
data you want.
By adding this filter, the
FilterDispatcher will know to not clean up and
instead defer cleanup to this filter. The ordering of the filters should then be:
| Method from org.apache.struts2.dispatcher.ActionContextCleanUp Detail: |
protected static void cleanUp(ServletRequest req) {
// 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);
}
Clean up the request of threadlocals if this is the last execution |
public void destroy() {
}
|
public void doFilter(ServletRequest req,
ServletResponse res,
FilterChain chain) throws IOException, ServletException {
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(FilterConfig arg0) throws ServletException {
}
|