首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用简单驼峰代理传播SOAPFault

使用简单驼峰代理传播SOAPFault
EN

Stack Overflow用户
提问于 2014-09-08 16:30:39
回答 1查看 1.7K关注 0票数 2

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

--> PromotedService -->驼峰--> ProxifiedService

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

我如何才能确保PromotedServiceCaller收到SOAPFault作为响应?

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

代码语言:javascript
复制
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:

代码语言:javascript
复制
<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>

这就是呼叫者真正收到的信息:

代码语言:javascript
复制
<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>

谢谢!

EN

回答 1

Stack Overflow用户

发布于 2014-09-09 18:35:46

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

这将会起作用

代码语言:javascript
复制
onException(SOAPException.class)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25720152

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档