在Camel 3.x中,对于SOAPFault,必须指定命名空间以及SOAP版本。以下是一个示例:
from("cxf:bean:myEndpoint")
.routeId("soapFaultExample")
.onException(SOAPFaultException.class)
.handled(true)
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
SOAPFaultException e = (SOAPFaultException) exchange.getProperty(Exchange.EXCEPTION_CAUGHT);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
exchange.getIn().setBody(sw.toString());
}
})
.to("log:ERROR")
.end()
.to("bean:myService?method=myMethod")
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getOut().setHeader(Client.REQUEST_CONTEXT, getRequestContext());
}
})
.to("cxf:bean:myEndpoint?dataFormat=PAYLOAD&defaultOperationNamespace=urn:MyNamespace&defaultOperationName=myOperation&soapVersion=1.2");
在此示例中,我们针对SOAPFaultException注册了异常处理程序,并将其记录在日志中。我们还指定了命名空间、操作名称和SOAP版本。此外,我们还在请求上下文中设置了请求头,以确保正确的XML格式。