Java SOAPFaultException.getFault().getDetail()为空
我正在使用JAX WS 2.0调用SOAP Web服务。如果出现错误,我将得到以下响应:Java SOAPFaultException.getFault().getDetail()为空,java,soap,jax-ws,soapfault,Java,Soap,Jax Ws,Soapfault,我正在使用JAX WS 2.0调用SOAP Web服务。如果出现错误,我将得到以下响应: <?xml version="1.0"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://www.w3.org/2003/05/soap- envelope"&
<?xml version="1.0"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://www.w3.org/2003/05/soap- envelope">
<soap:Header/>
<soap:Body>
<soap:Fault xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://www.w3.org/2003/05/soap- envelope" xmlns:xml="http://www.w3.org/XML/1998/namespace">
<soap:Code>
<soap:Value>soap:Receiver</soap:Value>
</soap:Code>
<soap:Reason>
<soap:Text xml:lang="en">Exception of type 'blah blah' was thrown.
</soap:Text>
</soap:Reason>
<soap:Node>{SOME URL}</soap:Node>
<detail>
<error>345</error>
<message>Cannot find user. Blah blah</message>
</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>
肥皂:接收器
引发了类型为“blah blah”的异常。
{某个URL}
345
找不到用户。废话
如您所见,有用的错误出现在“详细信息”节点中:
<soap:Envelope>
<soap:Body>
<soap:Fault>
<detail>
在我的客户机中,我得到一个SOAPFaultException,它有一个SOAPFault对象。SOAPFault对象似乎缺少我在上面发布的节点。SOAPFaultException.getFault().getDetail()为空。但是,它具有包括soap:Reason在内的所有其他节点。知道它为什么缺少细节节点吗
谢谢。事实证明,细节节点也需要包含SOAP名称空间。因此需要:
<soap:detail>
因为我无法控制web服务,所以我设法在注入客户机的自定义SOAPHandler的handleFault方法中进行了此更改。在该更改之后,故障的详细信息不再为空,并且具有所有子节点
基于此,我认为开发人员需要在出现故障时更正响应 这对我很有用:
} catch (SoapFaultClientException e) {
log.error(e);
SoapFaultDetail soapFaultDetail = e.getSoapFault().getFaultDetail();
SoapFaultDetailElement detailElementChild = (SoapFaultDetailElement) soapFaultDetail.getDetailEntries().next();
Source detailSource = detailElementChild.getSource();
try {
Object detail = (JAXBElement<SearchResponse>) getWebServiceTemplate().getUnmarshaller().unmarshal(detailSource);
// throw new SoapFaultWithDetailException(detail);
} catch (IOException e1) {
throw new IllegalArgumentException("cannot unmarshal SOAP fault detail object: " + soapFaultDetail.getSource());
}
}
}catch(SoapFaultClientException e){
日志错误(e);
SoapFaultDetail SoapFaultDetail=e.getSoapFault().getFaultDetail();
SoapFaultDetailElement detailElementChild=(SoapFaultDetailElement)soapFaultDetail.getDetailEntries().next();
Source detailSource=detailElementChild.getSource();
试一试{
对象详细信息=(JAXBElement)getWebServiceTemplate().getUnmarshaller().unmarshal(detailSource);
//抛出新的SoapFaultWithDetailException(细节);
}捕获(IOE1异常){
抛出新的IllegalArgumentException(“无法解组SOAP错误详细信息对象:+soapFaultDetail.getSource());
}
}