简体   繁体   English

Camel并没有正确拦截使用camel-cxf的SoapFault

[英]Camel is not intercepting SoapFault with camel-cxf correctly

I need help. 我需要帮助。 I can't get the exception my web service is throwing and I don't know why. 我不能得到我的网络服务抛出的异常,我不知道为什么。

I have created a simple route in camel and I want to catch fault messages from a web service as an exception with the explanation of the error. 我已经在camel中创建了一个简单的路由,我想从Web服务中捕获错误消息作为异常并解释错误。

The route is the following: 路线如下:

    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");

In the context configuration I have this: 在上下文配置中我有这个:

context.setHandleFault(true);

The web service that I created for testing is as simple as this: 我为测试创建的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;
    }
}

But I'm not able to get the message from the exception "Mi excepcion". 但我无法从“Mi excepcion”异常中获取消息。

I guess the problem comes from this line: 我猜问题来自这条线:

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

Because the caught exception is my exception policy is this one: 因为捕获的异常是我的例外策略是这个:

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

EDIT: 编辑:

I have changed a little bit the code to log more info. 我已经更改了一些代码来记录更多信息。 This what I've done: 这就是我所做的:

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

What I found is that when the exception is caught, the message that is logged with the following line: 我发现当捕获异常时,使用以下行记录的消息:

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

is this one: 就是这个:

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>

When it should be the fault message, shouldn't it?. 什么时候应该是故障信息,不应该吗?

EDIT 2 编辑2

The XML reply is the following: 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>

Finally I found the problem. 最后我发现了问题。

The xml file that I was catching in: 我捕获的xml文件:

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

Had the following content: 有以下内容:

<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>

The fault was generated correctly by the testing web service but a different one saying that the method Envelope wasn't found, which is correct because the method Envelop doesn't exist in the web service. 错误是由测试Web服务正确生成的,但另一个错误是说找不到方法Envelope,这是正确的,因为Web服务中不存在Envelop方法。 The method that exists is "suma". 存在的方法是“suma”。

So I changed the xml to the following: 所以我将xml更改为以下内容:

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

And I got the expected exception: "Mi excepcion". 我得到了预期的例外:“Mi excepcion”。

Thanks for the help anyway!! 无论如何,谢谢你的帮助!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM