1

我正在使用 JAX WS 调用 SOAP Web 服务。如果出现错误,我会从客户端收到以下响应(我在跟踪日志中看到了这一点):

<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP- ENV="http://schemas.xmlsoap.org/soap/envelope/"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
    <SOAP-ENV:Fault>
        <faultcode>Error</faultcode>
        <faultstring>Error</faultstring>
        <SOAP-ENV:detail>
            <BLAServiceFault xmlns:ns="http://messages.testservice.com/TestService/2012/10">
                <ns:ReturnStatus>
                    <ns:ReturnCode>-97</ns:ReturnCode>
                    <ns:ReturnStatusSpecification>
                        <ns:SubCode xsi:nil="true"/>
                        <ns:Description>The price of productA must be higher than 30.</ns:Description>
                    </ns:ReturnStatusSpecification>
                </ns:ReturnStatus>
            </BLAServiceFault>
        </SOAP-ENV:detail>
    </SOAP-ENV:Fault>
</SOAP-ENV:Body>

如您所见,有用的错误在详细节点中:

<SOAP-ENV:Envelope>  
<SOAP-ENV:Body>  
    <SOAP-ENV:Fault>  
        <SOAP-ENV:detail>

在我的客户端中,我得到一个具有 SOAPFault 对象的 SOAPFaultException。SOAPFault 对象似乎缺少我在上面发布的节点。SOAPFaultException.getFault().getDetail() 为 null。异常为 javax.xml.ws.soap.SOAPFaultException: Error。如何获取带有描述的详细节点?

谢谢。

4

2 回答 2

0

看来来自服务的消息不符合 SOAP 1.1。在他们从“详细信息”节点中删除前缀“SOAP-ENV”后,它工作正常。

于 2014-05-08T11:49:00.583 回答
0

看看这个问题。可能使用格式错误的故障消息?

} 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());
    }

}
于 2015-09-15T14:51:30.290 回答