FlowExecutionImpl.handleException() now also tries to handle FlowExecutionExceptions that occur during exception handling (SWF-261).
This commit is contained in:
@@ -22,6 +22,10 @@ Package org.springframework.webflow.conversation
|
||||
* The SessionBindingConversationManager now re-binds the ConversationContainer in the session
|
||||
every time a contained conversation is unlocked (SWF-244).
|
||||
|
||||
Package org.springframework.webflow.engine
|
||||
* FlowExecutionImpl.handleException() now also tries to handle FlowExecutionExceptions that
|
||||
occur during exception handling (SWF-261).
|
||||
|
||||
Package org.springframework.webflow.execution
|
||||
* Added FlowExecutionListener.sessionCreated(RequestContext, FlowSession) callback, useful for
|
||||
setting flow attributes before the flow starts (SWF-223).
|
||||
|
||||
@@ -307,14 +307,20 @@ public class FlowExecutionImpl implements FlowExecution, Externalizable {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Attempting to handle [" + exception + "]");
|
||||
}
|
||||
// the state could be null if the flow was attempting a start operation
|
||||
ViewSelection selectedView = tryStateHandlers(exception, context);
|
||||
if (selectedView != null) {
|
||||
return selectedView;
|
||||
try {
|
||||
// the state could be null if the flow was attempting a start operation
|
||||
ViewSelection selectedView = tryStateHandlers(exception, context);
|
||||
if (selectedView != null) {
|
||||
return selectedView;
|
||||
}
|
||||
selectedView = tryFlowHandlers(exception, context);
|
||||
if (selectedView != null) {
|
||||
return selectedView;
|
||||
}
|
||||
}
|
||||
selectedView = tryFlowHandlers(exception, context);
|
||||
if (selectedView != null) {
|
||||
return selectedView;
|
||||
catch (FlowExecutionException newException) {
|
||||
// exception handling resulted in a new FlowExecutionException, try to handle it
|
||||
return handleException(newException, context);
|
||||
}
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Rethrowing unhandled flow execution exception");
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import org.springframework.webflow.action.AbstractAction;
|
||||
import org.springframework.webflow.execution.Event;
|
||||
import org.springframework.webflow.execution.RequestContext;
|
||||
|
||||
/**
|
||||
* Test action that throws an exception.
|
||||
*
|
||||
* @author Erwin Vervaet
|
||||
*/
|
||||
public class ExceptionThrowingAction extends AbstractAction {
|
||||
|
||||
protected Event doExecute(RequestContext context) throws Exception {
|
||||
Class exceptionType = Class.forName(context.getAttributes().getString("exceptionType"));
|
||||
throw (Exception)exceptionType.newInstance();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -50,8 +50,10 @@ import org.springframework.webflow.execution.FlowExecutionListener;
|
||||
import org.springframework.webflow.execution.MockFlowExecutionListener;
|
||||
import org.springframework.webflow.execution.RequestContext;
|
||||
import org.springframework.webflow.execution.TestAction;
|
||||
import org.springframework.webflow.execution.ViewSelection;
|
||||
import org.springframework.webflow.execution.support.ApplicationView;
|
||||
import org.springframework.webflow.test.MockExternalContext;
|
||||
import org.springframework.webflow.test.MockFlowServiceLocator;
|
||||
|
||||
/**
|
||||
* General flow execution tests.
|
||||
@@ -61,6 +63,19 @@ import org.springframework.webflow.test.MockExternalContext;
|
||||
* @author Ben Hale
|
||||
*/
|
||||
public class FlowExecutionImplTests extends TestCase {
|
||||
|
||||
public void testExceptionWhileHandlingException() {
|
||||
MockFlowServiceLocator serviceLocator = new MockFlowServiceLocator();
|
||||
serviceLocator.registerBean("testAction", new ExceptionThrowingAction());
|
||||
XmlFlowBuilder flowBuilder =
|
||||
new XmlFlowBuilder(new ClassPathResource("exceptionHandlingFlow.xml", this.getClass()));
|
||||
flowBuilder.setFlowServiceLocator(serviceLocator);
|
||||
Flow flow = new FlowAssembler("flow", flowBuilder).assembleFlow();
|
||||
FlowExecution flowExecution = new FlowExecutionImpl(flow);
|
||||
ViewSelection view = flowExecution.start(null, new MockExternalContext());
|
||||
assertEquals("failed", ((ApplicationView)view).getViewName());
|
||||
assertFalse(flowExecution.isActive());
|
||||
}
|
||||
|
||||
public void testFlowExecutionListener() {
|
||||
Flow flow = new Flow("myFlow");
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<?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">
|
||||
|
||||
<start-state idref="firstTry" />
|
||||
|
||||
<action-state id="firstTry">
|
||||
<action bean="testAction">
|
||||
<attribute name="exceptionType" value="java.sql.SQLException"/>
|
||||
</action>
|
||||
<transition on-exception="java.sql.SQLException" to="secondTry"/>
|
||||
</action-state>
|
||||
|
||||
<action-state id="secondTry">
|
||||
<action bean="testAction">
|
||||
<attribute name="exceptionType" value="java.sql.SQLException"/>
|
||||
</action>
|
||||
<transition on-exception="java.sql.SQLException" to="failed"/>
|
||||
</action-state>
|
||||
|
||||
<end-state id="failed" view="failed"/>
|
||||
|
||||
</flow>
|
||||
@@ -1,7 +1,9 @@
|
||||
<?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">
|
||||
|
||||
<?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">
|
||||
|
||||
<start-state idref="subflow" />
|
||||
|
||||
<subflow-state id="subflow" flow="inline-subflow">
|
||||
|
||||
Reference in New Issue
Block a user