Author: tmjee
Date: Tue Oct 10 05:31:52 2006
New Revision: 454720
URL: http://svn.apache.org/viewvc?view=rev&rev=454720
Log:
WW-727
- added profiling to FilterDispatcher and ActionContextCleanUp
Modified:
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/ActionContextCleanUp.java
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/FilterDispatcher.java
Modified:
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/ActionContextCleanUp.java
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/ActionContextCleanUp.java?view=diff&rev=454720&r1=454719&r2=454720
==============================================================================
---
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/ActionContextCleanUp.java
(original)
+++
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/ActionContextCleanUp.java
Tue Oct 10 05:31:52 2006
@@ -33,6 +33,7 @@
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 @@
* </ul>
* <!-- SNIPPET END: description -->
*
+ * @version $Date$ $Id$
+ *
* @see FilterDispatcher
*/
public class ActionContextCleanUp implements Filter {
@@ -77,7 +80,7 @@
}
- /* (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 @@
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);
}
}
Modified:
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/FilterDispatcher.java
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/FilterDispatcher.java?view=diff&rev=454720&r1=454719&r2=454720
==============================================================================
---
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/FilterDispatcher.java
(original)
+++
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/FilterDispatcher.java
Tue Oct 10 05:31:52 2006
@@ -50,6 +50,7 @@
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 @@
* @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 @@
HttpServletResponse response = (HttpServletResponse) res;
ServletContext servletContext = filterConfig.getServletContext();
- 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);
-
- 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;
+ String timerKey = "FilterDispatcher_doFilter: ";
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 ("".equals(resourcePath) && null != request.getPathInfo()) {
- resourcePath = request.getPathInfo();
- }
+ 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);
+
+ 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;
+ }
+
+ 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
("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);
}
}