- Revision
- 320
- Author
- mward
- Date
- 2007-10-09 12:42:22 -0500 (Tue, 09 Oct 2007)
Log Message
updated InterceptingActionMethodExecutor to handle ActionMethodExceptions
Modified Paths
- trunk/core/src/main/java/org/codehaus/waffle/action/ActionMethodInvocationException.java
- trunk/core/src/main/java/org/codehaus/waffle/action/InterceptingActionMethodExecutor.java
- trunk/core/src/test/java/org/codehaus/waffle/action/InterceptingActionMethodExecutorTest.java
- trunk/core/src/test/java/org/codehaus/waffle/testmodel/FakeController.java
Added Paths
Diff
Added: trunk/core/src/main/java/org/codehaus/waffle/action/ActionMethodException.java (0 => 320)
--- trunk/core/src/main/java/org/codehaus/waffle/action/ActionMethodException.java (rev 0) +++ trunk/core/src/main/java/org/codehaus/waffle/action/ActionMethodException.java 2007-10-09 17:42:22 UTC (rev 320) @@ -0,0 +1,20 @@ +/***************************************************************************** + * Copyright (C) 2005 - 2007 Michael Ward * + * All rights reserved. * + * ------------------------------------------------------------------------- * + * The software in this package is published under the terms of the BSD * + * style license a copy of which has been included with this distribution in * + * the LICENSE.txt file. * + * * + * Original code by: Michael Ward * + *****************************************************************************/ +package org.codehaus.waffle.action; + +import org.codehaus.waffle.WaffleException; + +/** + * This is a specialized exception that will be thrown directly from an ActionMethod. Exceptions of this type + * will set the response status code and response body specially. + */ +public class ActionMethodException extends WaffleException { +}
Modified: trunk/core/src/main/java/org/codehaus/waffle/action/ActionMethodInvocationException.java (319 => 320)
--- trunk/core/src/main/java/org/codehaus/waffle/action/ActionMethodInvocationException.java 2007-10-09 14:51:34 UTC (rev 319) +++ trunk/core/src/main/java/org/codehaus/waffle/action/ActionMethodInvocationException.java 2007-10-09 17:42:22 UTC (rev 320) @@ -13,7 +13,7 @@ import org.codehaus.waffle.WaffleException; /** - * Thrown when unable to invoke the Action method. + * Thrown when Waffle is unable to invoke the Action method. * * @author Michael Ward */
Modified: trunk/core/src/main/java/org/codehaus/waffle/action/InterceptingActionMethodExecutor.java (319 => 320)
--- trunk/core/src/main/java/org/codehaus/waffle/action/InterceptingActionMethodExecutor.java 2007-10-09 14:51:34 UTC (rev 319) +++ trunk/core/src/main/java/org/codehaus/waffle/action/InterceptingActionMethodExecutor.java 2007-10-09 17:42:22 UTC (rev 320) @@ -10,13 +10,13 @@ *****************************************************************************/ package org.codehaus.waffle.action; -import org.codehaus.waffle.controller.ControllerDefinition; import org.codehaus.waffle.action.intercept.InterceptorChain; import org.codehaus.waffle.action.intercept.InterceptorChainImpl; 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 java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -27,7 +27,7 @@ /** * Default implementation of action method executor, which uses an interceptor chain. - * + * * @author Michael Ward */ public class InterceptingActionMethodExecutor implements ActionMethodExecutor { @@ -46,12 +46,15 @@ } catch (InvocationTargetException e) { Throwable cause = e.getCause(); - // If cause is ActionMethodInvocationException it should be re-thrown - if(cause instanceof ActionMethodInvocationException) { + if (cause instanceof ActionMethodException) { + // ActionMethodExceptions will be processed by ActionMethodResponseHandlers + actionMethodResponse.setReturnValue(cause); + } else if (cause instanceof ActionMethodInvocationException) { + // If cause is ActionMethodInvocationException it should be re-thrown throw (ActionMethodInvocationException) cause; + } else { + throw new ActionMethodInvocationException(cause.getMessage(), cause); } - - throw new ActionMethodInvocationException(cause.getMessage(), cause); } }
Modified: trunk/core/src/test/java/org/codehaus/waffle/action/InterceptingActionMethodExecutorTest.java (319 => 320)
--- trunk/core/src/test/java/org/codehaus/waffle/action/InterceptingActionMethodExecutorTest.java 2007-10-09 14:51:34 UTC (rev 319) +++ trunk/core/src/test/java/org/codehaus/waffle/action/InterceptingActionMethodExecutorTest.java 2007-10-09 17:42:22 UTC (rev 320) @@ -126,4 +126,18 @@ } } + @Test + public void shouldSetActionResponseValueToExceptionIfTypeIsActionMethodException() throws NoSuchMethodException { + FakeController fakeController = new FakeController(); + Method method = FakeController.class.getMethod("actionThrowsActionMethodException"); + MethodDefinition methodDefinition = new MethodDefinition(method); + + ControllerDefinition controllerDefinition = new ControllerDefinition("FakeController", fakeController, methodDefinition); + ActionMethodResponse actionMethodResponse = new ActionMethodResponse(); + + actionMethodExecutor.execute(actionMethodResponse, controllerDefinition); + + Assert.assertTrue(actionMethodResponse.getReturnValue() instanceof ActionMethodException); + } + }
Modified: trunk/core/src/test/java/org/codehaus/waffle/testmodel/FakeController.java (319 => 320)
--- trunk/core/src/test/java/org/codehaus/waffle/testmodel/FakeController.java 2007-10-09 14:51:34 UTC (rev 319) +++ trunk/core/src/test/java/org/codehaus/waffle/testmodel/FakeController.java 2007-10-09 17:42:22 UTC (rev 320) @@ -13,6 +13,7 @@ import org.codehaus.waffle.context.ContextLevel; import org.codehaus.waffle.view.View; import org.codehaus.waffle.action.ActionMethodInvocationException; +import org.codehaus.waffle.action.ActionMethodException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -62,6 +63,10 @@ throw new ActionMethodInvocationException(msg); } + public void actionThrowsActionMethodException() throws ActionMethodException { + throw new ActionMethodException(); + } + public void sayHello() { setName("hello"); }
To unsubscribe from this list please visit:
