/** * Adds an exception-to-target state mapping to this handler. * @param exceptionClass the type of exception to map * @param targetStateId the id of the state to transition to if the specified type of exception is handled * @return this handler, to allow for adding multiple mappings in a single statement */ public TransitionExecutingFlowExecutionExceptionHandler add(Class<? extends Throwable> exceptionClass, String targetStateId) { return add(exceptionClass, new DefaultTargetStateResolver(targetStateId)); }
private FlowExecutionExceptionHandler parseTransitionExecutingExceptionHandler(TransitionModel transition) { TransitionExecutingFlowExecutionExceptionHandler handler = new TransitionExecutingFlowExecutionExceptionHandler(); Class<Throwable> exceptionClass = toClass(transition.getOnException(), Throwable.class); TargetStateResolver targetStateResolver = (TargetStateResolver) fromStringTo(TargetStateResolver.class) .execute(transition.getTo()); handler.add(exceptionClass, targetStateResolver); handler.getActionList().addAll(parseActions(transition.getActions())); return handler; }
/** * Create default global exception handlers. * * @param flow the flow */ protected void createDefaultGlobalExceptionHandlers(final Flow flow) { val h = new TransitionExecutingFlowExecutionExceptionHandler(); h.add(UnauthorizedSsoServiceException.class, CasWebflowConstants.STATE_ID_VIEW_LOGIN_FORM); h.add(NoSuchFlowExecutionException.class, CasWebflowConstants.STATE_ID_VIEW_SERVICE_ERROR); h.add(UnauthorizedServiceException.class, CasWebflowConstants.STATE_ID_SERVICE_UNAUTHZ_CHECK); h.add(UnauthorizedServiceForPrincipalException.class, CasWebflowConstants.STATE_ID_SERVICE_UNAUTHZ_CHECK); h.add(PrincipalException.class, CasWebflowConstants.STATE_ID_SERVICE_UNAUTHZ_CHECK); flow.getExceptionHandlerSet().add(h); }
/** * Adds an exception-to-target state mapping to this handler. * @param exceptionClass the type of exception to map * @param targetStateId the id of the state to transition to if the specified type of exception is handled * @return this handler, to allow for adding multiple mappings in a single statement */ public TransitionExecutingFlowExecutionExceptionHandler add(Class<? extends Throwable> exceptionClass, String targetStateId) { return add(exceptionClass, new DefaultTargetStateResolver(targetStateId)); }
/** * Adds an exception-to-target state mapping to this handler. * @param exceptionClass the type of exception to map * @param targetStateId the id of the state to transition to if the specified type of exception is handled * @return this handler, to allow for adding multiple mappings in a single statement */ public TransitionExecutingFlowExecutionExceptionHandler add(Class exceptionClass, String targetStateId) { return add(exceptionClass, new DefaultTargetStateResolver(targetStateId)); }
/** * Add global transition if exception is thrown. * * @param flow the flow * @param targetStateId the target state id * @param clazz the exception class */ protected void addGlobalTransitionIfExceptionIsThrown(final Flow flow, final String targetStateId, final Class<? extends Throwable> clazz) { try { final TransitionExecutingFlowExecutionExceptionHandler handler = new TransitionExecutingFlowExecutionExceptionHandler(); final TargetStateResolver targetStateResolver = (TargetStateResolver) fromStringTo(TargetStateResolver.class) .execute(targetStateId); handler.add(clazz, targetStateResolver); LOGGER.debug("Added transition {} to execute on the occurrence of {}", targetStateId, clazz.getName()); flow.getExceptionHandlerSet().add(handler); } catch (final Exception e) { LOGGER.error(e.getMessage(), e); } }
/** * Add global transition if exception is thrown. * * @param flow the flow * @param targetStateId the target state id * @param clazz the exception class */ protected void createGlobalTransition(final Flow flow, final String targetStateId, final Class<? extends Throwable> clazz) { try { final TransitionExecutingFlowExecutionExceptionHandler handler = new TransitionExecutingFlowExecutionExceptionHandler(); final TargetStateResolver targetStateResolver = (TargetStateResolver) fromStringTo(TargetStateResolver.class) .execute(targetStateId); handler.add(clazz, targetStateResolver); logger.debug("Added transition {} to execute on the occurrence of {}", targetStateId, clazz.getName()); flow.getExceptionHandlerSet().add(handler); } catch (final Exception e) { logger.error(e.getMessage(), e); } }
public void buildExceptionHandlers() throws FlowBuilderException { getFlow().getExceptionHandlerSet().add( new TransitionExecutingFlowExecutionExceptionHandler().add(Exception.class, "showError")); }
private FlowExecutionExceptionHandler parseTransitionExecutingExceptionHandler(TransitionModel transition) { TransitionExecutingFlowExecutionExceptionHandler handler = new TransitionExecutingFlowExecutionExceptionHandler(); Class<Throwable> exceptionClass = toClass(transition.getOnException(), Throwable.class); TargetStateResolver targetStateResolver = (TargetStateResolver) fromStringTo(TargetStateResolver.class) .execute(transition.getTo()); handler.add(exceptionClass, targetStateResolver); handler.getActionList().addAll(parseActions(transition.getActions())); return handler; }
private FlowExecutionExceptionHandler parseTransitionExecutingExceptionHandler(TransitionModel transition) { TransitionExecutingFlowExecutionExceptionHandler handler = new TransitionExecutingFlowExecutionExceptionHandler(); Class exceptionClass = toClass(transition.getOnException()); TargetStateResolver targetStateResolver = (TargetStateResolver) fromStringTo(TargetStateResolver.class) .execute(transition.getTo()); handler.add(exceptionClass, targetStateResolver); handler.getActionList().addAll(parseActions(transition.getActions())); return handler; }
public void testStateExceptionHandlingTransitionNoSuchState() { TransitionExecutingFlowExecutionExceptionHandler handler = new TransitionExecutingFlowExecutionExceptionHandler(); handler.add(TestException.class, "end"); flow.getExceptionHandlerSet().add(handler); FlowExecution execution = new FlowExecutionImplFactory().createFlowExecution(flow); try { execution.start(null, new MockExternalContext()); fail("Should have failed no such state"); } catch (IllegalArgumentException e) { } }
public void testTransitionExecutorHandlesExceptionSuperclassMatch() { TransitionExecutingFlowExecutionExceptionHandler handler = new TransitionExecutingFlowExecutionExceptionHandler(); handler.add(Exception.class, "state"); FlowExecutionException e = new FlowExecutionException(state.getOwner().getId(), state.getId(), "Oops", new TestException()); assertTrue("Doesn't handle state exception", handler.canHandle(e)); e = new FlowExecutionException(state.getOwner().getId(), state.getId(), "Oops", new RuntimeException()); assertTrue("Doesn't handle state exception", handler.canHandle(e)); }
public void testTransitionExecutorHandlesExceptionExactMatch() { TransitionExecutingFlowExecutionExceptionHandler handler = new TransitionExecutingFlowExecutionExceptionHandler(); handler.add(TestException.class, "state"); FlowExecutionException e = new FlowExecutionException(state.getOwner().getId(), state.getId(), "Oops", new TestException()); assertTrue("Doesn't handle state exception", handler.canHandle(e)); e = new FlowExecutionException(state.getOwner().getId(), state.getId(), "Oops", new Exception()); assertFalse("Shouldn't handle exception", handler.canHandle(e)); }
public void testFlowStateExceptionHandlingTransition() { new EndState(flow, "end"); TransitionExecutingFlowExecutionExceptionHandler handler = new TransitionExecutingFlowExecutionExceptionHandler(); handler.add(TestException.class, "end"); flow.getExceptionHandlerSet().add(handler); FlowExecutionListener listener = new FlowExecutionListener() { @SuppressWarnings("unused") public void sessionEnding(RequestContext context, FlowSession session, MutableAttributeMap<?> output) { assertTrue(context.getFlashScope().contains("flowExecutionException")); assertTrue(context.getFlashScope().contains("rootCauseException")); assertTrue(context.getFlashScope().get("rootCauseException") instanceof TestException); } }; FlowExecutionImplFactory factory = new FlowExecutionImplFactory(); factory.setExecutionListenerLoader(new StaticFlowExecutionListenerLoader(listener)); FlowExecution execution = factory.createFlowExecution(flow); execution.start(null, new MockExternalContext()); assertTrue("Should have ended", !execution.isActive()); }
public void testHandleException() { flow.getExceptionHandlerSet().add( new TransitionExecutingFlowExecutionExceptionHandler().add(TestException.class, "myState2")); MockRequestControlContext context = new MockRequestControlContext(flow); context.setCurrentState(flow.getStateInstance("myState1")); FlowExecutionException e = new FlowExecutionException(flow.getId(), flow.getStartState().getId(), "Oops!", new TestException()); flow.handleException(e, context); assertFalse(context.getFlowExecutionContext().isActive()); }