使用简单的Camel代理传播SOAPFault

时间:2014-09-08 08:30:39

标签: web-services soap apache-camel

我正在尝试使用带有Camel的Switchyard 1.1创建一个简单的WS代理:

- > PromotedService - >骆驼 - > ProxifiedService

使用当前配置,我能够毫无问题地发送和接收消息。 但是,当ProxifiedService抛出SoapFault时,它不会传播到PromotedService的调用者。

我可以做些什么来确保PromotedServiceCaller接收SOAPFault作为响应?

这是我到目前为止所尝试的:

onException(Exception.class)  
       .process(  
          new Processor() {  
             public void process(Exchange exchange) throws Exception {           
                SoapFault fault = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, SoapFault.class);
                System.out.println("Fault: " +  fault); // --> This returns NULL

                Exception excep = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);
                System.out.println("excep: " +  excep);
                System.out.println("excep message: " + excep.getMessage());
                System.out.println("excep cause: " +  excep.getCause());

                SoapFault SOAP_FAULT = new SoapFault(excep.getMessage(), SoapFault.FAULT_CODE_CLIENT);
                Element detail = SOAP_FAULT.getOrCreateDetail();
                Document doc = detail.getOwnerDocument();
                Text tn = doc.createTextNode("this is a test");
                detail.appendChild(tn);

                exchange.getOut().setFault(true);
                exchange.getOut().setBody(SOAP_FAULT);

                exchange.setProperty(Exchange.ERRORHANDLER_HANDLED, false); 
                exchange.removeProperty("CamelExceptionCaught");  
             }  
          })  
       .handled(true)  
       .end();

        from("switchyard://PromotedService") 
            .process(myProc) // --> I just add some headers here to the original request. 
            .handleFault()   
            .to("switchyard://ProxifiedService").end();

这是ProxifiedService生成的SOAPFault:

<soapenv:Envelope xmlns:ser="http://service.admin.ws.my.company/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
 </soapenv:Header>
<soapenv:Body>
   <soapenv:Fault>
      <faultcode>soapenv:Server</faultcode>
      <faultstring>Missing valid token.</faultstring>
   </soapenv:Fault>
</soapenv:Body>

这是调用者真正收到的消息:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Header/>
    <soap:Body>
       <soap:Fault>
          <faultcode>soap:Server</faultcode>
          <faultstring>org.switchyard.HandlerException: org.apache.cxf.binding.soap.SoapFault: javax.xml.transform.dom.DOMSource@663dcb96</faultstring>
      </soap:Fault>
    </soap:Body>
 </soap:Envelope>

谢谢!

1 个答案:

答案 0 :(得分:2)

onException()只接受Throwable。在你的代码中,参数是SoapFault,它不是Throwable。

这将有效

onException(SOAPException.class)