在java端异常后继续消息流

时间:2013-08-22 07:19:51

标签: exception routing apache-camel

我只是想在异常发生后继续处理消息。我知道,可以使用'<'continue'>'..'<'/ continue>'来自xml的声明,但我想隐藏xml文档中的复杂性。并且不想改变我们目前构建的每个模块。因此,我想通过java在中心位置设置它。

案例: 如果发生异常,将从onException块调用java bean,该块分析异常并检查异常的类型。现在我想配置,如果它是一个ExampleException,应该忽略该异常并继续路由。只是处理类似,可以通过ExchangeHelper设置,但不同的是,处理的只是一个简单的标题而不是。

有没有办法在实际的交换对象上设置java继续?

提前致谢!

的Stefan

1 个答案:

答案 0 :(得分:0)

我找到了以下内容,并试一试。

异常捕获= exchange.getException();

    // we continue so clear any exceptions
    exchange.setException(null);
    // clear rollback flags
    exchange.setProperty(Exchange.ROLLBACK_ONLY, null);
    // reset cached streams so they can be read again
    MessageHelper.resetStreamCache(exchange.getIn());

    // its continued then remove traces of redelivery attempted and caught exception
    exchange.getIn().removeHeader(Exchange.REDELIVERED);
    exchange.getIn().removeHeader(Exchange.REDELIVERY_COUNTER);
    exchange.getIn().removeHeader(Exchange.REDELIVERY_MAX_COUNTER);
    exchange.removeProperty(Exchange.FAILURE_HANDLED);
    // keep the Exchange.EXCEPTION_CAUGHT as property so end user knows the caused exception
相关问题