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; }
public void handle(FlowExecutionException exception, RequestControlContext context) { if (logger.isDebugEnabled()) { logger.debug("Handling flow execution exception " + exception, exception); } exposeException(context, exception, findRootCause(exception)); actionList.execute(context); context.execute(new Transition(getTargetStateResolver(exception))); }
/** * Find the mapped target state resolver for given exception. Returns <code>null</code> if no mapping can be found * for given exception. Will try all exceptions in the exception cause chain. */ protected TargetStateResolver getTargetStateResolver(Throwable e) { TargetStateResolver targetStateResolver; if (isRootCause(e)) { return findTargetStateResolver(e.getClass()); } else { targetStateResolver = exceptionTargetStateMappings.get(e.getClass()); if (targetStateResolver != null) { return targetStateResolver; } else { return getTargetStateResolver(e.getCause()); } } }
/** * 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 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)); }
/** * 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)); }
/** * Find the root cause of given throwable. For use on JDK 1.4 or later. */ private Throwable findRootCause(Throwable e) { Throwable cause = e.getCause(); if (cause == null) { return e; } else { return findRootCause(cause); } }
public boolean canHandle(FlowExecutionException e) { return getTargetStateResolver(e) != null; }
/** * 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); } }
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)); }
/** * 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)); }
/** * Find the root cause of given throwable. For use on JDK 1.4 or later. */ private Throwable findRootCause(Throwable e) { Throwable cause = e.getCause(); if (cause == null) { return e; } else { return findRootCause(cause); } }
public boolean canHandle(FlowExecutionException e) { return getTargetStateResolver(e) != null; }
/** * 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); } }
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; }
public void handle(FlowExecutionException exception, RequestControlContext context) { if (logger.isDebugEnabled()) { logger.debug("Handling flow execution exception " + exception, exception); } exposeException(context, exception, findRootCause(exception)); actionList.execute(context); context.execute(new Transition(getTargetStateResolver(exception))); }
/** * Find the mapped target state resolver for given exception. Returns <code>null</code> if no mapping can be found * for given exception. Will try all exceptions in the exception cause chain. */ protected TargetStateResolver getTargetStateResolver(Throwable e) { TargetStateResolver targetStateResolver; if (isRootCause(e)) { return findTargetStateResolver(e.getClass()); } else { targetStateResolver = exceptionTargetStateMappings.get(e.getClass()); if (targetStateResolver != null) { return targetStateResolver; } else { return getTargetStateResolver(e.getCause()); } } }
/** * 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)); }
/** * Find the root cause of given throwable. For use on JDK 1.4 or later. */ private Throwable findRootCause(Throwable e) { Throwable cause = e.getCause(); if (cause == null) { return e; } else { return findRootCause(cause); } }
public boolean canHandle(FlowExecutionException e) { return getTargetStateResolver(e) != null; }