我有一条路线如下,即使我尝试用
onException()
子句替换 try-catch 并在下面的路线中设置 handled to true
:
from("direct:create-soap-request")
.process(exchange -> {
// creating GetAliases soap request
GetAliases soapRequest = requestConverter.createRequestObject(exchange);
exchange.getMessage().setBody(soapRequest);
})
// setting SOAP Operation in header
.setHeader(CxfConstants.OPERATION_NAME, constant("getAliases"))
.doTry()
// Invoking the SOAP service
.to("cxf:bean:coreWebServiceAdapter")
.to("direct:map-soap-response-nppAliases")
.doCatch(FaultDetail_Exception.class)
.process("throwIntegrationServiceException"); // this is the processor where exception object is captured.
问题是,当服务器响应 SOAP FAULT(下面的示例 xml)时,会使用空的soapFaultDetails 创建异常对象。错误消息在异常对象上填充得很好。附上变量实例的屏幕截图。
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soap_enc="http://schemas.xmlsoap.org/soap/encoding/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>Exception: abcd12345: Please enter a valid phone number</faultstring>
<detail>
<cor:faultDetail
xmlns:cor="http://abc/123/2012/04/">
<requestId>abcd12345</requestId>
<errorCode>Random_Code</errorCode>
<errorMessage>Please enter a valid phone number</errorMessage>
</cor:faultDetail>
</detail>
</soap:Fault>
`
我不确定这里缺少什么。该消息被转换为从 wsdl 生成的异常对象。我已经交叉检查了响应的名称空间,它匹配得很好。
我的处理器代码如下:
@Override
public void process(final Exchange exchange) throws Exception {
FaultDetail_Exception exception = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, FaultDetail_Exception.class);
// business logic below
}
问题现已解决,它似乎是来自服务器的无效 xml wrt 命名空间。在下面粘贴正确的 xml :
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soap_enc="http://schemas.xmlsoap.org/soap/encoding/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>Exception: abcd12345: Please enter a valid phone number</faultstring>
<detail>
<cor:faultDetail
xmlns:cor="http://abc/123/2012/04/">
<cor:requestId>abcd12345</cor:requestId>
<cor:errorCode>Random_Code</cor:errorCode>
<cor:errorMessage>Please enter a valid phone number</cor:errorMessage>
</cor:faultDetail>
</detail>
</soap:Fault>