- Revision
- 359
- Author
- mauro
- Date
- 2007-11-12 16:31:12 -0600 (Mon, 12 Nov 2007)
Log Message
Added monitoring to DefaultInterceptorChain and InterceptingActionMethodExecutor.
Modified Paths
- trunk/core/src/main/java/org/codehaus/waffle/action/ActionMethodResponse.java
- trunk/core/src/main/java/org/codehaus/waffle/action/InterceptingActionMethodExecutor.java
- trunk/core/src/main/java/org/codehaus/waffle/action/intercept/DefaultInterceptorChain.java
- trunk/core/src/main/java/org/codehaus/waffle/monitor/AbstractWritingMonitor.java
- trunk/core/src/main/java/org/codehaus/waffle/monitor/ActionMonitor.java
- trunk/core/src/test/java/org/codehaus/waffle/action/InterceptingActionMethodExecutorTest.java
- trunk/core/src/test/java/org/codehaus/waffle/action/intercept/DefaultInterceptorChainTest.java
- trunk/core/src/test/java/org/codehaus/waffle/servlet/WaffleServletTest.java
- trunk/core/src/test/java/org/codehaus/waffle/testmodel/StubMonitor.java
Diff
Modified: trunk/core/src/main/java/org/codehaus/waffle/action/ActionMethodResponse.java (358 => 359)
--- trunk/core/src/main/java/org/codehaus/waffle/action/ActionMethodResponse.java 2007-11-12 21:47:51 UTC (rev 358) +++ trunk/core/src/main/java/org/codehaus/waffle/action/ActionMethodResponse.java 2007-11-12 22:31:12 UTC (rev 359) @@ -26,4 +26,12 @@ this.returnValue = returnValue; } + @Override + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append("[ActionMethodResponse returnValue="); + sb.append(returnValue); + sb.append("]"); + return sb.toString(); + } }
Modified: trunk/core/src/main/java/org/codehaus/waffle/action/InterceptingActionMethodExecutor.java (358 => 359)
--- trunk/core/src/main/java/org/codehaus/waffle/action/InterceptingActionMethodExecutor.java 2007-11-12 21:47:51 UTC (rev 358) +++ trunk/core/src/main/java/org/codehaus/waffle/action/InterceptingActionMethodExecutor.java 2007-11-12 22:31:12 UTC (rev 359) @@ -10,29 +10,37 @@ *****************************************************************************/ package org.codehaus.waffle.action; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +import org.codehaus.waffle.action.intercept.DefaultInterceptorChain; import org.codehaus.waffle.action.intercept.InterceptorChain; -import org.codehaus.waffle.action.intercept.DefaultInterceptorChain; import org.codehaus.waffle.action.intercept.MethodInterceptor; import org.codehaus.waffle.action.intercept.MethodInterceptorComparator; import org.codehaus.waffle.context.ContextContainer; import org.codehaus.waffle.context.RequestLevelContainer; import org.codehaus.waffle.controller.ControllerDefinition; +import org.codehaus.waffle.monitor.ActionMonitor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - /** - * Default implementation of action method executor, which uses an interceptor chain. + * Implementation of action method executor, which uses an interceptor chain. * * @author Michael Ward + * @author Mauro Talevi */ public class InterceptingActionMethodExecutor implements ActionMethodExecutor { + private final Comparator<MethodInterceptor> comparator = new MethodInterceptorComparator(); + private final ActionMonitor actionMonitor; + public InterceptingActionMethodExecutor(ActionMonitor actionMonitor) { + this.actionMonitor = actionMonitor; + } + /** * If no 'action method' exists in the request parameter a View will be created with the Action's name. */ @@ -41,6 +49,7 @@ try { Object returnValue = handleInvocation(controllerDefinition); actionMethodResponse.setReturnValue(returnValue); + actionMonitor.actionMethodExecuted(actionMethodResponse); } catch (IllegalAccessException e) { throw new ActionMethodInvocationException(e.getMessage(), e); } catch (InvocationTargetException e) { @@ -67,7 +76,7 @@ interceptors.add(new MethodInvokingMethodInterceptor()); - InterceptorChain chain = new DefaultInterceptorChain(interceptors); + InterceptorChain chain = new DefaultInterceptorChain(interceptors, actionMonitor); MethodDefinition methodDefinition = controllerDefinition.getMethodDefinition(); Method method = methodDefinition.getMethod(); List<Object> methodArguments = methodDefinition.getMethodArguments();
Modified: trunk/core/src/main/java/org/codehaus/waffle/action/intercept/DefaultInterceptorChain.java (358 => 359)
--- trunk/core/src/main/java/org/codehaus/waffle/action/intercept/DefaultInterceptorChain.java 2007-11-12 21:47:51 UTC (rev 358) +++ trunk/core/src/main/java/org/codehaus/waffle/action/intercept/DefaultInterceptorChain.java 2007-11-12 22:31:12 UTC (rev 359) @@ -11,6 +11,7 @@ package org.codehaus.waffle.action.intercept; import org.codehaus.waffle.controller.ControllerDefinition; +import org.codehaus.waffle.monitor.ActionMonitor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -19,10 +20,12 @@ public class DefaultInterceptorChain implements InterceptorChain { private final Iterator<MethodInterceptor> iterator; + private final ActionMonitor actionMonitor; private Object returnValue; - public DefaultInterceptorChain(List<MethodInterceptor> interceptors) { + public DefaultInterceptorChain(List<MethodInterceptor> interceptors, ActionMonitor actionMonitor) { this.iterator = interceptors.iterator(); + this.actionMonitor = actionMonitor; } public Object proceed(ControllerDefinition controllerDefinition, @@ -32,6 +35,7 @@ MethodInterceptor methodInterceptor = iterator.next(); if (methodInterceptor.accept(method)) { returnValue = methodInterceptor.intercept(controllerDefinition, method, this, arguments); + actionMonitor.methodIntercepted(method, arguments, returnValue); } else { return proceed(controllerDefinition, method, arguments); // recursive }
Modified: trunk/core/src/main/java/org/codehaus/waffle/monitor/AbstractWritingMonitor.java (358 => 359)
--- trunk/core/src/main/java/org/codehaus/waffle/monitor/AbstractWritingMonitor.java 2007-11-12 21:47:51 UTC (rev 358) +++ trunk/core/src/main/java/org/codehaus/waffle/monitor/AbstractWritingMonitor.java 2007-11-12 22:31:12 UTC (rev 359) @@ -10,14 +10,17 @@ *****************************************************************************/ package org.codehaus.waffle.monitor; +import static java.util.Arrays.asList; import static org.codehaus.waffle.monitor.Monitor.Level.DEBUG; import static org.codehaus.waffle.monitor.Monitor.Level.INFO; import static org.codehaus.waffle.monitor.Monitor.Level.WARN; +import java.lang.reflect.Method; import java.util.Set; import javax.servlet.http.HttpServletResponse; +import org.codehaus.waffle.action.ActionMethodResponse; import org.codehaus.waffle.action.MethodDefinition; import org.codehaus.waffle.action.HierarchicalArgumentResolver.Scope; import org.codehaus.waffle.validation.BindErrorMessage; @@ -61,10 +64,23 @@ write(INFO, "ActionMethod found: " + methodDefinition); } + public void actionMethodExecuted(ActionMethodResponse actionMethodResponse) { + write(INFO, "ActionMethod executed with response: " + actionMethodResponse); + } + + public void actionMethodExecutionFailed(Exception exception) { + trace(exception); + } + public void methodNameResolved(String methodName, String methodKey, Set<String> keys) { write(INFO, "Method name '" + methodName + "' found for key '" + methodKey + "' among keys " + keys); } + public void methodIntercepted(Method method, Object[] arguments, Object returnValue) { + write(INFO, "Method '" + method + "' intercepted with arguments '" + asList(arguments) + + "' and returned value '" + returnValue + "'"); + } + public void argumentNameResolved(String name, Object value, Scope scope) { write(INFO, "Argument name '" + name + "' resolved to '" + value + "' in scope " + scope); } @@ -73,16 +89,12 @@ write(WARN, "Argument name '" + name + "' not matched by pattern '" + pattern + "'" ); } - public void actionMethodExecutionFailed(Exception exception) { - trace(exception); - } - public void bindFailed(Object bindModel, BindErrorMessage errorMessage){ - write(WARN, "Bind failed for model " + bindModel + ": " + errorMessage); + write(WARN, "Bind failed for model '" + bindModel + "': " + errorMessage); } public void bindFailed(Object controller, Throwable cause){ - write(WARN, "Bind failed for controller " + controller + ": " + cause); + write(WARN, "Bind failed for controller '" + controller + "': " + cause); } public void responseIsCommitted(HttpServletResponse response) {
Modified: trunk/core/src/main/java/org/codehaus/waffle/monitor/ActionMonitor.java (358 => 359)
--- trunk/core/src/main/java/org/codehaus/waffle/monitor/ActionMonitor.java 2007-11-12 21:47:51 UTC (rev 358) +++ trunk/core/src/main/java/org/codehaus/waffle/monitor/ActionMonitor.java 2007-11-12 22:31:12 UTC (rev 359) @@ -10,10 +10,12 @@ *****************************************************************************/ package org.codehaus.waffle.monitor; +import java.lang.reflect.Method; import java.util.Set; import javax.servlet.http.HttpServletResponse; +import org.codehaus.waffle.action.ActionMethodResponse; import org.codehaus.waffle.action.MethodDefinition; import org.codehaus.waffle.action.HierarchicalArgumentResolver.Scope; import org.codehaus.waffle.view.View; @@ -33,6 +35,8 @@ void actionMethodFound(MethodDefinition methodDefinition); + void actionMethodExecuted(ActionMethodResponse actionMethodResponse); + void actionMethodExecutionFailed(Exception cause); void argumentNameResolved(String name, Object value, Scope scope); @@ -41,6 +45,8 @@ void methodNameResolved(String methodName, String methodKey, Set<String> keys); + void methodIntercepted(Method method, Object[] arguments, Object returnValue); + void responseIsCommitted(HttpServletResponse response); void viewDispatched(View view);
Modified: trunk/core/src/test/java/org/codehaus/waffle/action/InterceptingActionMethodExecutorTest.java (358 => 359)
--- trunk/core/src/test/java/org/codehaus/waffle/action/InterceptingActionMethodExecutorTest.java 2007-11-12 21:47:51 UTC (rev 358) +++ trunk/core/src/test/java/org/codehaus/waffle/action/InterceptingActionMethodExecutorTest.java 2007-11-12 22:31:12 UTC (rev 359) @@ -14,9 +14,12 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import java.lang.reflect.Method; + import org.codehaus.waffle.context.RequestLevelContainer; import org.codehaus.waffle.context.pico.PicoContextContainer; import org.codehaus.waffle.controller.ControllerDefinition; +import org.codehaus.waffle.monitor.SilentMonitor; import org.codehaus.waffle.testmodel.FakeController; import org.junit.After; import org.junit.Assert; @@ -24,11 +27,10 @@ import org.junit.Test; import org.picocontainer.defaults.DefaultPicoContainer; -import java.lang.reflect.Method; - public class InterceptingActionMethodExecutorTest { - private ActionMethodExecutor actionMethodExecutor = new InterceptingActionMethodExecutor(); + private ActionMethodExecutor actionMethodExecutor = new InterceptingActionMethodExecutor(new SilentMonitor()); + @Before public void setUp() throws Exception { RequestLevelContainer.set(new PicoContextContainer(new DefaultPicoContainer()));
Modified: trunk/core/src/test/java/org/codehaus/waffle/action/intercept/DefaultInterceptorChainTest.java (358 => 359)
--- trunk/core/src/test/java/org/codehaus/waffle/action/intercept/DefaultInterceptorChainTest.java 2007-11-12 21:47:51 UTC (rev 358) +++ trunk/core/src/test/java/org/codehaus/waffle/action/intercept/DefaultInterceptorChainTest.java 2007-11-12 22:31:12 UTC (rev 359) @@ -8,6 +8,8 @@ import java.util.List; import org.codehaus.waffle.controller.ControllerDefinition; +import org.codehaus.waffle.monitor.ActionMonitor; +import org.codehaus.waffle.monitor.SilentMonitor; import org.jmock.Expectations; import org.jmock.Mockery; import org.jmock.integration.junit4.JMock; @@ -25,6 +27,9 @@ final Object argument = "foobar"; // Mock MethodInterceptor + final Object[] arguments = new Object[] {argument}; + final String returnValue = "hello"; + final MethodInterceptor methodInterceptor = mockery.mock(MethodInterceptor.class); mockery.checking(new Expectations() {{ one (methodInterceptor).accept(method); @@ -32,14 +37,20 @@ one(methodInterceptor).intercept(with(same(controllerDefinition)), with(same(method)), with(any(InterceptorChain.class)), - with(equal(new Object[] {argument}))); - will(returnValue("hello")); + with(equal(arguments))); + will(returnValue(returnValue)); }}); List<MethodInterceptor> interceptors = new ArrayList<MethodInterceptor>(); interceptors.add(methodInterceptor); - InterceptorChain interceptorChain = new DefaultInterceptorChain(interceptors); + // Mock ActionMonitor + final ActionMonitor actionMonitor = mockery.mock(ActionMonitor.class); + mockery.checking(new Expectations() {{ + one (actionMonitor).methodIntercepted(method, arguments, returnValue); + }}); + + InterceptorChain interceptorChain = new DefaultInterceptorChain(interceptors, actionMonitor); assertEquals("hello", interceptorChain.proceed(controllerDefinition, method, argument)); } @@ -59,7 +70,7 @@ List<MethodInterceptor> interceptors = new ArrayList<MethodInterceptor>(); interceptors.add(methodInterceptor); - DefaultInterceptorChain interceptorChain = new DefaultInterceptorChain(interceptors); + DefaultInterceptorChain interceptorChain = new DefaultInterceptorChain(interceptors, new SilentMonitor()); assertNull(interceptorChain.proceed(controllerDefinition, method, argument)); }
Modified: trunk/core/src/test/java/org/codehaus/waffle/servlet/WaffleServletTest.java (358 => 359)
--- trunk/core/src/test/java/org/codehaus/waffle/servlet/WaffleServletTest.java 2007-11-12 21:47:51 UTC (rev 358) +++ trunk/core/src/test/java/org/codehaus/waffle/servlet/WaffleServletTest.java 2007-11-12 22:31:12 UTC (rev 359) @@ -147,10 +147,11 @@ }}); // stub out what we don't want called ... execute it - WaffleServlet waffleServlet = new WaffleServlet(new InterceptingActionMethodExecutor(), + SilentMonitor monitor = new SilentMonitor(); + WaffleServlet waffleServlet = new WaffleServlet(new InterceptingActionMethodExecutor(monitor), actionMethodResponseHandler, - new SilentMonitor(), - new OgnlDataBinder(new DefaultTypeConverter(), null, new SilentMonitor()), + monitor, + new OgnlDataBinder(new DefaultTypeConverter(), null, monitor), requestAttributeBinder, null, validator) { @Override @@ -208,10 +209,11 @@ }}); // stub out what we don't want called ... execute it - WaffleServlet waffleServlet = new WaffleServlet(new InterceptingActionMethodExecutor(), + SilentMonitor monitor = new SilentMonitor(); + WaffleServlet waffleServlet = new WaffleServlet(new InterceptingActionMethodExecutor(monitor), actionMethodResponseHandler, - new SilentMonitor(), - new OgnlDataBinder(new DefaultTypeConverter(), null, new SilentMonitor()), + monitor, + new OgnlDataBinder(new DefaultTypeConverter(), null, monitor), requestAttributeBinder, null, validator) { @Override
Modified: trunk/core/src/test/java/org/codehaus/waffle/testmodel/StubMonitor.java (358 => 359)
--- trunk/core/src/test/java/org/codehaus/waffle/testmodel/StubMonitor.java 2007-11-12 21:47:51 UTC (rev 358) +++ trunk/core/src/test/java/org/codehaus/waffle/testmodel/StubMonitor.java 2007-11-12 22:31:12 UTC (rev 359) @@ -1,9 +1,11 @@ package org.codehaus.waffle.testmodel; +import java.lang.reflect.Method; import java.util.Set; import javax.servlet.http.HttpServletResponse; +import org.codehaus.waffle.action.ActionMethodResponse; import org.codehaus.waffle.action.MethodDefinition; import org.codehaus.waffle.action.HierarchicalArgumentResolver.Scope; import org.codehaus.waffle.monitor.ActionMonitor; @@ -16,7 +18,7 @@ public void defaultActionMethodFound(MethodDefinition methodDefinition) { } - public void defaultActionMethodCached(Class controllerType, MethodDefinition methodDefinition) { + public void defaultActionMethodCached(Class<?> controllerType, MethodDefinition methodDefinition) { } public void pragmaticActionMethodFound(MethodDefinition methodDefinition) { @@ -25,12 +27,18 @@ public void actionMethodFound(MethodDefinition methodDefinition) { } - public void methodNameResolved(String methodName, String methodKey, Set<String> keys) { - } + public void actionMethodExecuted(ActionMethodResponse actionMethodResponse) { + } public void actionMethodExecutionFailed(Exception exception) { } + public void methodNameResolved(String methodName, String methodKey, Set<String> keys) { + } + + public void methodIntercepted(Method method, Object[] arguments, Object returnValue) { + } + public void argumentNameNotMatched(String name, String pattern) { }
To unsubscribe from this list please visit:
