2

我是骆驼和 CXF 的新手。我正在尝试发布从我的 Web 服务抛出的错误消息。但是 CXF 仅将它们作为故障异常抛出,因此骆驼路由被中止并调用错误处理程序。

如何调整 Camel 或 CXF 以获取 CXF 本身收到的故障消息?

  1. 有什么配置可以实现这个吗?
  2. 或者我是否需要提供一个拦截器来实现这一点?
  3. 还是我需要在错误处理程序中处理?
4

3 回答 3

4

你可以试试这个:

from("endpoint")
  .doTry()
    .to("endpoint")
  .doCatch()
    .process(new Processor(
      @Override
      public void process(Exchange exchange) throws Exception {
        //Get the exception
        SoapFault fault = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, SoapFault.class);

        //Then you can change the body
      }
    ))
  .endDoTry()
.end();
于 2012-11-09T14:32:09.313 回答
1

这是 spring DSL 中的示例路由。你可以试试这个。如果提供者有 SOAP 错误,这将完美地工作。

<route id="test-route-id">
        <from uri="direct:from-route"/>
        <doTry>
          <log message="Request Payload : ${body}" loggingLevel="INFO" logName="test-route-id"/>

          <to uri="direct:cxf-endpoint"/>

          <log message="Response Payload : ${body}" loggingLevel="INFO" logName="test-route-id"/>

          <doCatch>
            <exception>org.apache.cxf.binding.soap.SoapFault</exception>
            <to uri="direct:fault-handling-route"/>
          </doCatch>
        </doTry>
    </route>
于 2016-06-01T06:30:52.657 回答
0

如果您只想对故障做出反应,您可以执行以下操作:

onException(Fault.class).handled(true).process(new MyFaltProcessor()).stop();

于 2014-07-09T14:33:12.900 回答