我正在使用 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 和堆栈跟踪有用得多。
使用搜索和替换来修改包、类和对象名称以提取个人数据。如果包或类名看起来很奇怪,那就是原因。