OgnlExpression now unwraps the ognl.OgnlException to make the real exception available to the caller (SWF-255).
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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".
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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 {
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<flow xmlns="http://www.springframework.org/schema/webflow"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/webflow
|
||||
http://www.springframework.org/schema/webflow/spring-webflow-1.0.xsd">
|
||||
|
||||
<var name="flowAction" scope="flow" class="org.springframework.webflow.engine.impl.FooFlowAction" />
|
||||
|
||||
<start-state idref="action1" />
|
||||
|
||||
<action-state id="action1">
|
||||
<evaluate-action expression="flowScope.flowAction.action1()" />
|
||||
<transition on-exception="org.springframework.webflow.engine.impl.FooException" to="fooException" />
|
||||
<transition on-exception="ognl.MethodFailedException" to="methodFailedException" />
|
||||
</action-state>
|
||||
|
||||
<end-state id="fooException" view="showFooException" />
|
||||
|
||||
<end-state id="methodFailedException" view="showMethodFailedException" />
|
||||
|
||||
</flow>
|
||||
Reference in New Issue
Block a user