diff --git a/spring-binding/src/main/java/org/springframework/binding/expression/support/OgnlExpression.java b/spring-binding/src/main/java/org/springframework/binding/expression/support/OgnlExpression.java index 778ba8ee..65757697 100644 --- a/spring-binding/src/main/java/org/springframework/binding/expression/support/OgnlExpression.java +++ b/spring-binding/src/main/java/org/springframework/binding/expression/support/OgnlExpression.java @@ -74,7 +74,14 @@ class OgnlExpression implements SettableExpression { return Ognl.getValue(expression, contextAttributes, target); } catch (OgnlException e) { - throw new EvaluationException(new EvaluationAttempt(this, target, context), e); + if (e.getReason() != null && e.getReason() != e) { + // unwrap the OgnlException since the actual exception is wrapped inside it + // and there is not generic (getCause) way to get to it later on + throw new EvaluationException(new EvaluationAttempt(this, target, context), e.getReason()); + } + else { + throw new EvaluationException(new EvaluationAttempt(this, target, context), e); + } } } diff --git a/spring-webflow/changelog.txt b/spring-webflow/changelog.txt index 0e0c0bdc..9c7716bf 100644 --- a/spring-webflow/changelog.txt +++ b/spring-webflow/changelog.txt @@ -9,6 +9,8 @@ Package org.springframework.binding * GenericConversionService.getConversionExecutor() now uses isAssignableFrom to detect situations where no conversion is necessary (SWF-264). * Fixed possbile NullPointerException in MethodKey.parameterTypesString() (SWF-265). +* OgnlExpression now unwraps the ognl.OgnlException to make the real exception available to the + caller (SWF-255). Package org.springframework.webflow.action * FormAction methods doBind() and createBinder() now declare "throws Exception". diff --git a/spring-webflow/src/test/java/org/springframework/webflow/engine/impl/FlowExecutionImplTests.java b/spring-webflow/src/test/java/org/springframework/webflow/engine/impl/FlowExecutionImplTests.java index 688ee1ea..a7e54008 100644 --- a/spring-webflow/src/test/java/org/springframework/webflow/engine/impl/FlowExecutionImplTests.java +++ b/spring-webflow/src/test/java/org/springframework/webflow/engine/impl/FlowExecutionImplTests.java @@ -35,6 +35,7 @@ import org.springframework.webflow.engine.ViewSelector; import org.springframework.webflow.engine.ViewState; import org.springframework.webflow.engine.builder.AbstractFlowBuilder; import org.springframework.webflow.engine.builder.FlowAssembler; +import org.springframework.webflow.engine.builder.FlowBuilder; import org.springframework.webflow.engine.builder.FlowBuilderException; import org.springframework.webflow.engine.builder.xml.TestFlowServiceLocator; import org.springframework.webflow.engine.builder.xml.XmlFlowBuilder; @@ -64,6 +65,15 @@ import org.springframework.webflow.test.MockFlowServiceLocator; */ public class FlowExecutionImplTests extends TestCase { + public void testExceptionHandlingWithEvaluateAction() { + FlowBuilder flowBuilder = new XmlFlowBuilder(new ClassPathResource("fooFlow.xml", getClass())); + Flow flow = new FlowAssembler("fooFlow", flowBuilder).assembleFlow(); + FlowExecution flowExecution = new FlowExecutionImpl(flow); + ViewSelection view = flowExecution.start(null, new MockExternalContext()); + assertEquals("showFooException", ((ApplicationView)view).getViewName()); + assertFalse(flowExecution.isActive()); + } + public void testExceptionWhileHandlingException() { MockFlowServiceLocator serviceLocator = new MockFlowServiceLocator(); serviceLocator.registerBean("testAction", new ExceptionThrowingAction()); diff --git a/spring-webflow/src/test/java/org/springframework/webflow/engine/impl/FooException.java b/spring-webflow/src/test/java/org/springframework/webflow/engine/impl/FooException.java new file mode 100644 index 00000000..0dc98ad2 --- /dev/null +++ b/spring-webflow/src/test/java/org/springframework/webflow/engine/impl/FooException.java @@ -0,0 +1,20 @@ +/* + * Copyright 2004-2007 the original author or authors. + * + * 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.springframework.webflow.engine.impl; + +public class FooException extends RuntimeException { + +} diff --git a/spring-webflow/src/test/java/org/springframework/webflow/engine/impl/FooFlowAction.java b/spring-webflow/src/test/java/org/springframework/webflow/engine/impl/FooFlowAction.java new file mode 100644 index 00000000..6c5015ca --- /dev/null +++ b/spring-webflow/src/test/java/org/springframework/webflow/engine/impl/FooFlowAction.java @@ -0,0 +1,24 @@ +/* + * Copyright 2004-2007 the original author or authors. + * + * 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.springframework.webflow.engine.impl; + +public class FooFlowAction { + + public String action1() { + throw new FooException(); + } + +} diff --git a/spring-webflow/src/test/java/org/springframework/webflow/engine/impl/fooFlow.xml b/spring-webflow/src/test/java/org/springframework/webflow/engine/impl/fooFlow.xml new file mode 100644 index 00000000..81afca17 --- /dev/null +++ b/spring-webflow/src/test/java/org/springframework/webflow/engine/impl/fooFlow.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + +