【问题标题】:Camel is not intercepting SoapFault with camel-cxf correctly骆驼没有正确拦截带有骆驼cxf的SoapFault
【发布时间】:2015-07-07 05:39:50
【问题描述】:

我需要帮助。我无法得到我的网络服务抛出的异常,我不知道为什么。

我在 camel 中创建了一个简单的路由,我想从 Web 服务捕获错误消息作为异常并解释错误。

路线如下:

    onException(Exception.class)
        .handled(true)
        .to("log:info")
        .process(new FailureResponseProcessor())
        .to("file:data/outbox?fileName=error.xml");

    from("file:data/inbox?noop=true")   
        .process(loggerProcessor)
        .to("cxf://http://localhost:8080/TestWebService?dataFormat=PAYLOAD"
          + "&properties.exceptionMessageCauseEnabled=true"
          + "&properties.faultStackTraceEnabled=true")
        .to("file:data/outbox?fileName=response.xml");

在上下文配置中我有这个:

context.setHandleFault(true);

我为测试创建的 Web 服务就这么简单:

@WebService
public class TestWebService {
    @WebMethod
    public double suma(double a, double b) throws Exception {
        System.out.println("Webservice invocado!!!");
        throw new Exception("Mi excepcion");
        //return a + b;
    }
}

但我无法从异常“Mi excepcion”中获取消息。

我猜问题出在这一行:

2015-04-28 13:05:15 DEBUG DefaultErrorHandler:71 - Failed delivery for (MessageId: ID-saqqara-40731-1430219108400-0-3 on ExchangeId: ID-saqqara-40731-1430219108400-0-2). On delivery attempt: 0 caught: org.apache.cxf.binding.soap.SoapFault: No se ha encontrado el método de distribución de {http://schemas.xmlsoap.org/soap/envelope/}Envelope

因为捕获的异常是我的异常策略是这个:

Error: No se ha encontrado el método de distribución de {http://schemas.xmlsoap.org/soap/envelope/}Envelope

编辑:

我已经更改了一点代码以记录更多信息。这就是我所做的:

onException(SoapFault.class)
    .handled(true)
    .log("Response ON ERROR: ${body}")
    .log("Response ON FAULT: ${exception}")
    .process(new FailureResponseProcessor())
    .to("file:data/outbox?fileName=error.xml");

from("file:data/inbox?noop=true")
    .id("miRuta")
    .log("File content: ${body}")
    .to("cxf://http://localhost:8080/TestWebService?dataFormat=PAYLOAD"
      + "&properties.exceptionMessageCauseEnabled=true"
      + "&properties.faultStackTraceEnabled=true")
    .log("WS Response: ${body}");

我发现当异常被捕获时,记录的消息如下:

.log("Response ON ERROR: ${body}")

是这个吗:

2015-04-29 09:53:28 INFO  route1:95 - Response ON ERROR:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
                  xmlns:test="http://test_ws.testing.com/">
    <soapenv:Header/>
    <soapenv:Body>
        <test:suma>
           <arg0>?</arg0>
           <arg1>?</arg1>
        </test:suma>
    </soapenv:Body>
</soapenv:Envelope>

什么时候应该是错误消息,不是吗?

编辑 2

XML 回复如下:

<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Body>
        <S:Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope">
            <faultcode>S:Server</faultcode>
            <faultstring>Mi excepcion</faultstring>
            <detail>
                <ns2:Exception xmlns:ns2="http://test_ws.testing.com/">
                    <message>Mi excepcion</message>
                </ns2:Exception>
            </detail>
        </S:Fault>
    </S:Body>
</S:Envelope>

【问题讨论】:

  • 翻译成英文的错误是:{schemas.xmlsoap.org/soap/envelope}Envelope的分发方法没有找到
  • 这个异常是否被抛出并存储在消息的soap fault部分中。
  • 我用 TestWebService 类抛出的异常给出了以下肥皂:schemas.xmlsoap.org/soap/envelope/… xmlns:ns4="w3.org/2003/05/…excepciontest_ws.testing.com/"><message>Miexcepcion信封>
  • 我不知道我之前的评论是否回答了您的问题@Namphibian,以防万一,请告诉我尝试更准确。
  • 豪尔赫能否在问题中发布回复 XML。您评论中的那个有点坏,所以我不能确定问题出在哪里。

标签: java apache-camel cxf


【解决方案1】:

终于找到问题了。

我正在捕获的 xml 文件:

from("file:data/inbox?noop=true")

有以下内容:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:test="http://test_ws.testing.com/">
   <soapenv:Header/>
   <soapenv:Body>
      <test:suma>
         <arg0>5</arg0>
         <arg1>5</arg1>
      </test:suma>
   </soapenv:Body>
</soapenv:Envelope>

错误是由测试 Web 服务正确生成的,但另一个说没有找到方法 Envelope,这是正确的,因为 Web 服务中不存在方法 Envelop。存在的方法是“suma”。

所以我把xml改成如下:

<test:suma xmlns:test="http://test_ws.testing.com/">
  <arg0>5</arg0>
  <arg1>5</arg1>
</test:suma>

我得到了预期的异常:“Mi excepcion”。

还是谢谢你的帮助!!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-14
    相关资源
    最近更新 更多