1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.struts2.interceptor;
19
20 import org.apache.struts2.dispatcher.Dispatcher;
21
22 import com.opensymphony.xwork2.ActionInvocation;
23 import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
24 import com.opensymphony.xwork2.util.profiling.UtilTimerStack;
25
26 /***
27 * Allows profiling to be enabled or disabled via request parameters, when
28 * devMode is enabled.
29 */
30 public class ProfilingActivationInterceptor extends AbstractInterceptor {
31
32 private String profilingKey = "profiling";
33
34 /***
35 * @return the profilingKey
36 */
37 public String getProfilingKey() {
38 return profilingKey;
39 }
40
41 /***
42 * @param profilingKey the profilingKey to set
43 */
44 public void setProfilingKey(String profilingKey) {
45 this.profilingKey = profilingKey;
46 }
47
48 @Override
49 public String intercept(ActionInvocation invocation) throws Exception {
50 if (Dispatcher.getInstance().isDevMode()) {
51 Object val = invocation.getInvocationContext().getParameters().get(profilingKey);
52 if (val != null) {
53 String sval = (val instanceof String ? (String)val : ((String[])val)[0]);
54 boolean enable = "yes".equalsIgnoreCase(sval) || "true".equalsIgnoreCase(sval);
55 UtilTimerStack.setActive(enable);
56 invocation.getInvocationContext().getParameters().remove(profilingKey);
57 }
58 }
59 return invocation.invoke();
60
61 }
62
63 }