/** * 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); } }
/** * 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); }
public void buildExceptionHandlers() throws FlowBuilderException { getFlow().getExceptionHandlerSet().add( new TransitionExecutingFlowExecutionExceptionHandler().add(Exception.class, "showError")); }
/** * Clone action state. * * @param source the source * @param target the target */ public void cloneActionState(final ActionState source, final ActionState target) { source.getActionList().forEach(a -> target.getActionList().add(a)); source.getExitActionList().forEach(a -> target.getExitActionList().add(a)); source.getAttributes().asMap().forEach((k, v) -> target.getAttributes().put(k, v)); source.getTransitionSet().forEach(t -> target.getTransitionSet().addAll(t)); val field = ReflectionUtils.findField(target.getExceptionHandlerSet().getClass(), "exceptionHandlers"); ReflectionUtils.makeAccessible(field); val list = (List<FlowExecutionExceptionHandler>) ReflectionUtils.getField(field, target.getExceptionHandlerSet()); list.forEach(h -> source.getExceptionHandlerSet().add(h)); target.setDescription(source.getDescription()); target.setCaption(source.getCaption()); }
public void testHandleException() { FlowExecutionExceptionHandlerSet handlerSet = new FlowExecutionExceptionHandlerSet(); handlerSet.add(new TestStateExceptionHandler(NullPointerException.class, "null")); handlerSet.add(new TestStateExceptionHandler(FlowExecutionException.class, "execution 1")); handlerSet.add(new TestStateExceptionHandler(FlowExecutionException.class, "execution 2")); assertEquals(3, handlerSet.size()); FlowExecutionException e = new FlowExecutionException("flowId", "stateId", "Test"); assertTrue(handlerSet.handleException(e, context)); assertFalse(context.getFlowScope().contains("null")); assertTrue(context.getFlowScope().contains("execution 1")); assertFalse(context.getFlowScope().contains("execution 2")); }
public void testStartExceptionThrownByStateHandledByStateExceptionHandler() { Flow flow = new Flow("flow"); flow.getExceptionHandlerSet().add(new StubFlowExecutionExceptionHandler()); final FlowExecutionException e = new FlowExecutionException("flow", "state", "Oops"); State s = new State(flow, "state") { protected void doEnter(RequestControlContext context) throws FlowExecutionException { throw e; } }; StubFlowExecutionExceptionHandler exceptionHandler = new StubFlowExecutionExceptionHandler(); s.getExceptionHandlerSet().add(exceptionHandler); FlowExecutionImpl execution = new FlowExecutionImpl(flow); MockExternalContext context = new MockExternalContext(); assertFalse(execution.hasStarted()); execution.start(null, context); assertTrue(exceptionHandler.getHandled()); }
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 testHandledException() { state.getExceptionHandlerSet().add(new FlowExecutionExceptionHandler() { public boolean canHandle(FlowExecutionException exception) { return true; } public void handle(FlowExecutionException exception, RequestControlContext context) { handled = true; } }); FlowExecutionException e = new FlowExecutionException(flow.getId(), state.getId(), "Whatev"); MockRequestControlContext context = new MockRequestControlContext(flow); assertTrue(state.handleException(e, context)); assertTrue(handled); }
public void testExceptionHandledByNestedExceptionHandler() { Flow flow = new Flow("flow"); ExceptionThrowingExceptionHandler exceptionHandler = new ExceptionThrowingExceptionHandler(true); flow.getExceptionHandlerSet().add(exceptionHandler); new State(flow, "state") { protected void doEnter(RequestControlContext context) throws FlowExecutionException { throw new FlowExecutionException("flow", "state", "Oops"); } }; FlowExecutionImpl execution = new FlowExecutionImpl(flow); MockExternalContext context = new MockExternalContext(); assertFalse(execution.hasStarted()); execution.start(null, context); assertEquals(2, exceptionHandler.getHandleCount()); }
public void testStartExceptionThrownByStateHandledByFlowExceptionHandler() { Flow flow = new Flow("flow"); StubFlowExecutionExceptionHandler exceptionHandler = new StubFlowExecutionExceptionHandler(); flow.getExceptionHandlerSet().add(exceptionHandler); final FlowExecutionException e = new FlowExecutionException("flow", "state", "Oops"); new State(flow, "state") { protected void doEnter(RequestControlContext context) throws FlowExecutionException { throw e; } }; FlowExecutionImpl execution = new FlowExecutionImpl(flow); MockExternalContext context = new MockExternalContext(); assertFalse(execution.hasStarted()); execution.start(null, context); assertTrue(exceptionHandler.getHandled()); }
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()); }
public void testStartExceptionThrownBeforeFirstSessionCreated() { Flow flow = new Flow("flow"); flow.getExceptionHandlerSet().add(new FlowExecutionExceptionHandler() { public boolean canHandle(FlowExecutionException exception) { return true;