org.springframework.webflow.engine.Flow.getExceptionHandlerSet()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(12.3k)|赞(0)|评价(0)|浏览(144)

本文整理了Java中org.springframework.webflow.engine.Flow.getExceptionHandlerSet()方法的一些代码示例,展示了Flow.getExceptionHandlerSet()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Flow.getExceptionHandlerSet()方法的具体详情如下:
包路径:org.springframework.webflow.engine.Flow
类名称:Flow
方法名:getExceptionHandlerSet

Flow.getExceptionHandlerSet介绍

[英]Returns the set of exception handlers, allowing manipulation of how exceptions are handled when thrown during flow execution. Exception handlers are invoked when an exception occurs at execution time and can execute custom exception handling logic as well as select an error view to display. Exception handlers attached at the flow level have an opportunity to handle exceptions that aren't handled at the state level.
[中]返回异常处理程序集,允许在流执行期间抛出异常时处理异常的方式。异常处理程序在执行时发生异常时调用,可以执行自定义异常处理逻辑,也可以选择要显示的错误视图。在流级别附加的异常处理程序有机会处理在状态级别未处理的异常。

代码示例

代码示例来源:origin: org.springframework.webflow/spring-webflow

/**
 * Handle an exception that occurred during an execution of this flow.
 * @param exception the exception that occurred
 * @param context the flow execution control context
 */
public boolean handleException(FlowExecutionException exception, RequestControlContext context)
    throws FlowExecutionException {
  return getExceptionHandlerSet().handleException(exception, context);
}

代码示例来源:origin: org.springframework.webflow/spring-webflow

/**
 * Creates and adds all exception handlers to the flow built by this builder.
 * @throws FlowBuilderException an exception occurred building this flow
 */
public void buildExceptionHandlers() throws FlowBuilderException {
  getFlow().getExceptionHandlerSet().addAll(
      parseExceptionHandlers(flowModel.getExceptionHandlers(), flowModel.getGlobalTransitions()));
}

代码示例来源:origin: spring-projects/spring-webflow

/**
 * Handle an exception that occurred during an execution of this flow.
 * @param exception the exception that occurred
 * @param context the flow execution control context
 */
public boolean handleException(FlowExecutionException exception, RequestControlContext context)
    throws FlowExecutionException {
  return getExceptionHandlerSet().handleException(exception, context);
}

代码示例来源:origin: org.springframework.webflow/org.springframework.webflow

/**
 * Handle an exception that occurred during an execution of this flow.
 * @param exception the exception that occurred
 * @param context the flow execution control context
 */
public boolean handleException(FlowExecutionException exception, RequestControlContext context)
    throws FlowExecutionException {
  return getExceptionHandlerSet().handleException(exception, context);
}

代码示例来源:origin: org.springframework/spring-webflow

/**
 * Handle an exception that occured during an execution of this flow.
 * @param exception the exception that occured
 * @param context the flow execution control context
 * @return the selected error view, or <code>null</code> if no handler matched or returned a non-null view
 * selection
 */
public ViewSelection handleException(FlowExecutionException exception, RequestControlContext context)
    throws FlowExecutionException {
  return getExceptionHandlerSet().handleException(exception, context);
}

代码示例来源:origin: net.unicon/cas-mfa-java

/**
 * 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);
  }
}

代码示例来源:origin: org.jasig.cas/cas-server-core-webflow

/**
 * 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);
  }
}

代码示例来源:origin: org.springframework/spring-webflow

public void buildExceptionHandlers() throws FlowBuilderException {
  getFlow().getExceptionHandlerSet().addAll(parseExceptionHandlers(getDocumentElement()));
}

代码示例来源:origin: spring-projects/spring-webflow

/**
 * Creates and adds all exception handlers to the flow built by this builder.
 * @throws FlowBuilderException an exception occurred building this flow
 */
public void buildExceptionHandlers() throws FlowBuilderException {
  getFlow().getExceptionHandlerSet().addAll(
      parseExceptionHandlers(flowModel.getExceptionHandlers(), flowModel.getGlobalTransitions()));
}

代码示例来源:origin: org.springframework.webflow/org.springframework.webflow

/**
 * Creates and adds all exception handlers to the flow built by this builder.
 * @throws FlowBuilderException an exception occurred building this flow
 */
public void buildExceptionHandlers() throws FlowBuilderException {
  getFlow().getExceptionHandlerSet().addAll(
      parseExceptionHandlers(flowModel.getExceptionHandlers(), flowModel.getGlobalTransitions()));
}

代码示例来源:origin: org.apereo.cas/cas-server-core-webflow-api

/**
 * 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);
}

代码示例来源:origin: spring-projects/spring-webflow

public void buildExceptionHandlers() throws FlowBuilderException {
  getFlow().getExceptionHandlerSet().add(
      new TransitionExecutingFlowExecutionExceptionHandler().add(Exception.class, "showError"));
}

代码示例来源:origin: org.springframework/spring-webflow

private void buildInlineFlow(Element flowElement, Flow inlineFlow) {
  parseAndAddFlowVariables(flowElement, inlineFlow);
  inlineFlow.setInputMapper(parseInputMapper(flowElement));
  parseAndAddStartActions(flowElement, inlineFlow);
  parseAndAddInlineFlowDefinitions(flowElement, inlineFlow);
  parseAndAddStateDefinitions(flowElement, inlineFlow);
  parseAndAddGlobalTransitions(flowElement, inlineFlow);
  parseAndAddEndActions(flowElement, inlineFlow);
  inlineFlow.setOutputMapper(parseOutputMapper(flowElement));
  inlineFlow.getExceptionHandlerSet().addAll(parseExceptionHandlers(flowElement));
  destroyLocalServiceRegistry();
}

代码示例来源:origin: spring-projects/spring-webflow

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) {
  }
}

代码示例来源:origin: spring-projects/spring-webflow

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());
}

代码示例来源:origin: spring-projects/spring-webflow

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());
}

代码示例来源:origin: spring-projects/spring-webflow

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());
}

代码示例来源:origin: spring-projects/spring-webflow

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());
}

代码示例来源:origin: spring-projects/spring-webflow

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());
}

代码示例来源:origin: spring-projects/spring-webflow

public void testExceptionHandlers() {
  FlowModel model = new FlowModel();
  model.setStates(asList(new EndStateModel("state")));
  model.setExceptionHandlers(asList(new ExceptionHandlerModel("exceptionHandler")));
  FlowExecutionExceptionHandler handler = new FlowExecutionExceptionHandler() {
    public boolean canHandle(FlowExecutionException exception) {
      return true;
    }
    public void handle(FlowExecutionException exception, RequestControlContext context) {
    }
  };
  FlowModelFlowBuilder builder = new FlowModelFlowBuilder(new StaticFlowModelHolder(model));
  MockFlowBuilderContext context = new MockFlowBuilderContext("foo");
  context.registerBean("exceptionHandler", handler);
  FlowAssembler assembler = new FlowAssembler(builder, context);
  Flow flow = assembler.assembleFlow();
  assertEquals(1, flow.getExceptionHandlerSet().size());
}

相关文章