mirror of
https://github.com/apache/struts.git
synced 2026-08-11 01:27:14 +00:00
WW-727
- added profiling to FilterDispatcher and ActionContextCleanUp git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@454720 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -33,6 +33,7 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.util.profiling.UtilTimerStack;
|
||||
|
||||
/**
|
||||
* <!-- SNIPPET START: description -->
|
||||
@@ -55,6 +56,8 @@ import com.opensymphony.xwork2.ActionContext;
|
||||
* </ul>
|
||||
* <!-- SNIPPET END: description -->
|
||||
*
|
||||
* @version $Date$ $Id$
|
||||
*
|
||||
* @see FilterDispatcher
|
||||
*/
|
||||
public class ActionContextCleanUp implements Filter {
|
||||
@@ -77,7 +80,7 @@ public class ActionContextCleanUp implements Filter {
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
/**
|
||||
* @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
|
||||
*/
|
||||
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
|
||||
@@ -85,35 +88,43 @@ public class ActionContextCleanUp implements Filter {
|
||||
HttpServletRequest request = (HttpServletRequest) req;
|
||||
HttpServletResponse response = (HttpServletResponse) res;
|
||||
|
||||
// prepare the request no matter what - this ensures that the proper character encoding
|
||||
// is used before invoking the mapper (see WW-9127)
|
||||
Dispatcher.setInstance(dispatcher);
|
||||
dispatcher.prepare(request, response);
|
||||
|
||||
ServletContext servletContext = filterConfig.getServletContext();
|
||||
String timerKey = "ActionContextCleanUp_doFilter: ";
|
||||
try {
|
||||
request = dispatcher.wrapRequest(request, servletContext);
|
||||
} catch (IOException e) {
|
||||
String message = "Could not wrap servlet request with MultipartRequestWrapper!";
|
||||
LOG.error(message, e);
|
||||
throw new ServletException(message, e);
|
||||
UtilTimerStack.push(timerKey);
|
||||
|
||||
// prepare the request no matter what - this ensures that the proper character encoding
|
||||
// is used before invoking the mapper (see WW-9127)
|
||||
Dispatcher.setInstance(dispatcher);
|
||||
dispatcher.prepare(request, response);
|
||||
|
||||
ServletContext servletContext = filterConfig.getServletContext();
|
||||
try {
|
||||
request = dispatcher.wrapRequest(request, servletContext);
|
||||
} catch (IOException e) {
|
||||
String message = "Could not wrap servlet request with MultipartRequestWrapper!";
|
||||
LOG.error(message, e);
|
||||
throw new ServletException(message, e);
|
||||
}
|
||||
|
||||
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);
|
||||
chain.doFilter(request, response);
|
||||
} finally {
|
||||
int counterVal = ((Integer)request.getAttribute(COUNTER)).intValue();
|
||||
counterVal -= 1;
|
||||
request.setAttribute(COUNTER, new Integer(counterVal));
|
||||
cleanUp(request);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ import org.apache.struts2.dispatcher.mapper.ActionMapperFactory;
|
||||
import org.apache.struts2.dispatcher.mapper.ActionMapping;
|
||||
|
||||
import com.opensymphony.xwork2.util.ClassLoaderUtil;
|
||||
import com.opensymphony.xwork2.util.profiling.UtilTimerStack;
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
|
||||
/**
|
||||
@@ -114,6 +115,8 @@ import com.opensymphony.xwork2.ActionContext;
|
||||
* @see org.apache.struts2.lifecycle.LifecycleListener
|
||||
* @see ActionMapper
|
||||
* @see ActionContextCleanUp
|
||||
*
|
||||
* @version $Date$ $Id$
|
||||
*/
|
||||
public class FilterDispatcher implements Filter, StrutsStatics {
|
||||
private static final Log LOG = LogFactory.getLog(FilterDispatcher.class);
|
||||
@@ -193,63 +196,70 @@ public class FilterDispatcher implements Filter, StrutsStatics {
|
||||
HttpServletResponse response = (HttpServletResponse) res;
|
||||
ServletContext servletContext = filterConfig.getServletContext();
|
||||
|
||||
Dispatcher du = Dispatcher.getInstance();
|
||||
String timerKey = "FilterDispatcher_doFilter: ";
|
||||
try {
|
||||
UtilTimerStack.push(timerKey);
|
||||
Dispatcher du = Dispatcher.getInstance();
|
||||
|
||||
// Prepare and wrap the request if the cleanup filter hasn't already
|
||||
if (du == null) {
|
||||
du = dispatcher;
|
||||
// prepare the request no matter what - this ensures that the proper character encoding
|
||||
// is used before invoking the mapper (see WW-9127)
|
||||
du.prepare(request, response);
|
||||
// Prepare and wrap the request if the cleanup filter hasn't already
|
||||
if (du == null) {
|
||||
du = dispatcher;
|
||||
// prepare the request no matter what - this ensures that the proper character encoding
|
||||
// is used before invoking the mapper (see WW-9127)
|
||||
du.prepare(request, response);
|
||||
|
||||
try {
|
||||
// Wrap request first, just in case it is multipart/form-data
|
||||
// parameters might not be accessible through before encoding (ww-1278)
|
||||
request = du.wrapRequest(request, servletContext);
|
||||
} catch (IOException e) {
|
||||
String message = "Could not wrap servlet request with MultipartRequestWrapper!";
|
||||
LOG.error(message, e);
|
||||
throw new ServletException(message, e);
|
||||
}
|
||||
Dispatcher.setInstance(du);
|
||||
}
|
||||
try {
|
||||
// Wrap request first, just in case it is multipart/form-data
|
||||
// parameters might not be accessible through before encoding (ww-1278)
|
||||
request = du.wrapRequest(request, servletContext);
|
||||
} catch (IOException e) {
|
||||
String message = "Could not wrap servlet request with MultipartRequestWrapper!";
|
||||
LOG.error(message, e);
|
||||
throw new ServletException(message, e);
|
||||
}
|
||||
Dispatcher.setInstance(du);
|
||||
}
|
||||
|
||||
ActionMapper mapper = null;
|
||||
ActionMapping mapping = null;
|
||||
try {
|
||||
mapper = ActionMapperFactory.getMapper();
|
||||
mapping = mapper.getMapping(request, du.getConfigurationManager());
|
||||
} catch (Exception ex) {
|
||||
du.sendError(request, response, servletContext, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex);
|
||||
ActionContextCleanUp.cleanUp(req);
|
||||
return;
|
||||
}
|
||||
ActionMapper mapper = null;
|
||||
ActionMapping mapping = null;
|
||||
try {
|
||||
mapper = ActionMapperFactory.getMapper();
|
||||
mapping = mapper.getMapping(request, du.getConfigurationManager());
|
||||
} catch (Exception ex) {
|
||||
du.sendError(request, response, servletContext, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex);
|
||||
ActionContextCleanUp.cleanUp(req);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mapping == null) {
|
||||
// there is no action in this request, should we look for a static resource?
|
||||
String resourcePath = RequestUtils.getServletPath(request);
|
||||
if (mapping == null) {
|
||||
// there is no action in this request, should we look for a static resource?
|
||||
String resourcePath = RequestUtils.getServletPath(request);
|
||||
|
||||
if ("".equals(resourcePath) && null != request.getPathInfo()) {
|
||||
resourcePath = request.getPathInfo();
|
||||
}
|
||||
if ("".equals(resourcePath) && null != request.getPathInfo()) {
|
||||
resourcePath = request.getPathInfo();
|
||||
}
|
||||
|
||||
if ("true".equals(Settings.get(StrutsConstants.STRUTS_SERVE_STATIC_CONTENT))
|
||||
if ("true".equals(Settings.get(StrutsConstants.STRUTS_SERVE_STATIC_CONTENT))
|
||||
&& resourcePath.startsWith("/struts")) {
|
||||
String name = resourcePath.substring("/struts".length());
|
||||
findStaticResource(name, response);
|
||||
} else {
|
||||
// this is a normal request, let it pass through
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
// The framework did its job here
|
||||
return;
|
||||
String name = resourcePath.substring("/struts".length());
|
||||
findStaticResource(name, response);
|
||||
} else {
|
||||
// this is a normal request, let it pass through
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
// The framework did its job here
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
dispatcher.serviceAction(request, response, servletContext, mapping);
|
||||
} finally {
|
||||
ActionContextCleanUp.cleanUp(req);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
dispatcher.serviceAction(request, response, servletContext, mapping);
|
||||
} finally {
|
||||
ActionContextCleanUp.cleanUp(req);
|
||||
finally {
|
||||
UtilTimerStack.pop(timerKey);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user