我正在尝试使用Switchyard 1.1和Camel创建一个简单的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>谢谢!
发布于 2014-09-09 18:35:46
onException()只接受Throwable。在您的代码中,参数是SoapFault,它不是Throwable的。
这将会起作用
onException(SOAPException.class)https://stackoverflow.com/questions/25720152
复制相似问题