我正在使用Spring的WebServiceTemplate.marshalSendAndReceive(Object, WebServiceMessageCallback)
方法,我很难理解如何正确处理错误。现在我正在调用一个SOAP服务,如果有人使用相同的唯一标识符在内部发生错误,该服务将以下面的消息响应。
<SOAP-ENV:Body xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Fault>
<faultcode>BEA-380001</faultcode>
<faultstring>Internal Server Error</faultstring>
<detail>
<ns0:Fault xmlns:ns0="http://www.package.com/CommonEntities/V2" xmlns:ns2="http://www.package.com/package/schema">
<ns0:FaultDateTime>2014-01-22T10:39:56.056-06:00</ns0:FaultDateTime>
<ns0:FaultMessage>An application already exists for ID [987654321].</ns0:FaultMessage>
<ns0:FaultCode>500</ns0:FaultCode>
<ns0:FaultStack>com.package.package.exceptions.MyException: An application already exists for ID [987654321].
at com.package.package.endpoints.MyEndpoint.createObject(MyEndpoint.java:71)
at com.package.package.endpoints.MyEndpoint$$FastClassByCGLIB$$b46dae63.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
...More of this stack trace...
但是,只有将org.springframework
日志设置为trace
时才能找到此消息。实际上,使它退出对marshalSendAndReceive
的调用的消息是以下更通用的SoapFaultClientException
消息。
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Client</faultcode>
<faultstring xml:lang="en">Internal Server Error</faultstring>
<detail>
<ns2:Fault xmlns:ns2="http://www.package.com/package/schema" xmlns:ns3="http://www.package.com/package/schema/update">
<ns2:FaultDateTime>2014-01-22T10:39:56.787-06:00</ns2:FaultDateTime>
<ns2:FaultMessage>Internal Server Error</ns2:FaultMessage>
<ns2:FaultCode>2</ns2:FaultCode>
<ns2:FaultStack>org.springframework.ws.soap.client.SoapFaultClientException: Internal Server Error
at org.springframework.ws.soap.client.core.SoapFaultMessageResolver.resolveFault(SoapFaultMessageResolver.java:37)
at org.springframework.ws.client.core.WebServiceTemplate.handleFault(WebServiceTemplate.java:776)
at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:602)
at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:539)
at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:386)
at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:380)
at com.package.package.package.adapters.MyAdapter.submitObject(MyAdapter.java:48)
如何从原始响应中获取Body\Fault\details\Fault\FaultMessage
并在适配器中将其作为异常抛出?
来自后端请求的实际错误消息将比一般的SoapFaultClientException和堆栈跟踪有用得多。
使用搜索和替换修改了包、类和对象名称以提取个人数据。如果包或类名称看起来很奇怪,这就是原因。
1条答案
按热度按时间q7solyqu1#
您可以实作
CclientInterceptor
类别,以允许自订的客户端消息拦截。查看本教程:https://codenotfound.com/spring-ws-log-client-server-http-headers.html