You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by mr...@apache.org on 2006/10/01 02:48:25 UTC
svn commit: r451703 - in /struts/struts2/trunk/core/src/main:
java/org/apache/struts2/dispatcher/Dispatcher.java
java/org/apache/struts2/interceptor/ProfilingActivationInterceptor.java
resources/struts-default.xml
Author: mrdon
Date: Sat Sep 30 17:48:24 2006
New Revision: 451703
URL: http://svn.apache.org/viewvc?view=rev&rev=451703
Log:
Adding activation interceptor, and added profiling hook in dispatcher
WW-1460
Added:
struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/ProfilingActivationInterceptor.java
Modified:
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
struts/struts2/trunk/core/src/main/resources/struts-default.xml
Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java?view=diff&rev=451703&r1=451702&r2=451703
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java (original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java Sat Sep 30 17:48:24 2006
@@ -65,6 +65,7 @@
import com.opensymphony.xwork2.util.XWorkContinuationConfig;
import com.opensymphony.xwork2.util.location.Location;
import com.opensymphony.xwork2.util.location.LocationUtils;
+import com.opensymphony.xwork2.util.profiling.UtilTimerStack;
import freemarker.template.Template;
@@ -296,7 +297,9 @@
extraContext.put(ActionContext.VALUE_STACK, ValueStackFactory.getFactory().createValueStack(stack));
}
+ String timerKey = "Handling request from Dispatcher";
try {
+ UtilTimerStack.push(timerKey);
String namespace = mapping.getNamespace();
String name = mapping.getName();
String method = mapping.getMethod();
@@ -335,6 +338,8 @@
} catch (Exception e) {
LOG.error("Could not execute action", e);
sendError(request, response, context, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
+ } finally {
+ UtilTimerStack.pop(timerKey);
}
}
@@ -643,4 +648,19 @@
public void setConfigurationManager(ConfigurationManager mgr) {
this.configurationManager = mgr;
}
+
+ /**
+ * @return the devMode
+ */
+ public boolean isDevMode() {
+ return devMode;
+ }
+
+ /**
+ * @param devMode the devMode to set
+ */
+ public void setDevMode(boolean devMode) {
+ this.devMode = devMode;
+ }
+
}
Added: struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/ProfilingActivationInterceptor.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/ProfilingActivationInterceptor.java?view=auto&rev=451703
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/ProfilingActivationInterceptor.java (added)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/ProfilingActivationInterceptor.java Sat Sep 30 17:48:24 2006
@@ -0,0 +1,63 @@
+/*
+ * $Id: CreateSessionInterceptor.java 439747 2006-09-03 09:22:46Z mrdon $
+ *
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.struts2.interceptor;
+
+import org.apache.struts2.dispatcher.Dispatcher;
+
+import com.opensymphony.xwork2.ActionInvocation;
+import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
+import com.opensymphony.xwork2.util.profiling.UtilTimerStack;
+
+/**
+ * Allows profiling to be enabled or disabled via request parameters, when
+ * devMode is enabled.
+ */
+public class ProfilingActivationInterceptor extends AbstractInterceptor {
+
+ private String profilingKey = "profiling";
+
+ /**
+ * @return the profilingKey
+ */
+ public String getProfilingKey() {
+ return profilingKey;
+ }
+
+ /**
+ * @param profilingKey the profilingKey to set
+ */
+ public void setProfilingKey(String profilingKey) {
+ this.profilingKey = profilingKey;
+ }
+
+ @Override
+ public String intercept(ActionInvocation invocation) throws Exception {
+ if (Dispatcher.getInstance().isDevMode()) {
+ Object val = invocation.getInvocationContext().getParameters().get(profilingKey);
+ if (val != null) {
+ String sval = (val instanceof String ? (String)val : ((String[])val)[0]);
+ boolean enable = "yes".equalsIgnoreCase(sval) || "true".equalsIgnoreCase(sval);
+ UtilTimerStack.setActive(enable);
+ invocation.getInvocationContext().getParameters().remove(profilingKey);
+ }
+ }
+ return invocation.invoke();
+
+ }
+
+}
Modified: struts/struts2/trunk/core/src/main/resources/struts-default.xml
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/resources/struts-default.xml?view=diff&rev=451703&r1=451702&r2=451703
==============================================================================
--- struts/struts2/trunk/core/src/main/resources/struts-default.xml (original)
+++ struts/struts2/trunk/core/src/main/resources/struts-default.xml Sat Sep 30 17:48:24 2006
@@ -47,6 +47,7 @@
<interceptor name="workflow" class="com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor"/>
<interceptor name="store" class="org.apache.struts2.interceptor.MessageStoreInterceptor" />
<interceptor name="checkbox" class="org.apache.struts2.interceptor.CheckboxInterceptor" />
+ <interceptor name="profiling" class="org.apache.struts2.interceptor.ProfilingActivationInterceptor" />
<!-- Basic stack -->
<interceptor-stack name="basicStack">
@@ -142,6 +143,7 @@
<interceptor-ref name="i18n"/>
<interceptor-ref name="chain"/>
<interceptor-ref name="debugging"/>
+ <interceptor-ref name="profiling"/>
<interceptor-ref name="scoped-model-driven"/>
<interceptor-ref name="model-driven"/>
<interceptor-ref name="fileUpload"/>