JAX-WS SOAP故障 - 解析SOAPFaultException中错误的详细信息

7

如果SOAP请求有问题,我需要获取错误的详细信息。

我正在使用JAX-WS创建Web服务客户端。我的问题是,在出现故障事务时,Web服务客户端能够捕获SOAPFaultException,但没有提供详细信息:

javax.xml.ws.soap.SOAPFaultException: Component Interface API.    at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:178)

如果我通过SOAPUI发送请求,我可以得到包含以下详细信息的响应:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">   <SOAP-ENV:Body>
     <SOAP-ENV:Fault>
        <faultcode>SOAP-ENV:Server</faultcode>
        <faultstring>Component Interface API.</faultstring>
        <detail>
           <IBResponse type="Error">
              <DefaultTitle>Integration Broker Response</DefaultTitle>
              <StatusCode>20</StatusCode>
              <MessageSetID>180</MessageSetID>
              <MessageID>117</MessageID>
              <DefaultMessage>You are allowed to claim one meal per day</DefaultMessage>
              <MessageParameters>
                 <keyinformation>
                    <EMPLID>112233</EMPLID>
                 </keyinformation>
              </MessageParameters>
           </IBResponse>
        </detail>
     </SOAP-ENV:Fault>   </SOAP-ENV:Body> </SOAP-ENV:Envelope>

我在web服务客户端中是否遗漏了任何配置?非常感谢您的帮助。
1个回答

11

javax.xml.ws.soap.SOAPFaultException中获取详细信息:

try {
    //... invoke service via client
} catch (javax.xml.ws.soap.SOAPFaultException soapFaultException) {
    javax.xml.soap.SOAPFault fault = soapFaultException.getFault(); //<Fault> node
    javax.xml.soap.Detail detail = fault.getDetail(); // <detail> node
    Iterator detailEntries = detail.getDetailEntries(); //nodes under <detail>
    //application / service-provider-specific XML nodes (type javax.xml.soap.DetailEntry) from here
}

请参阅相关 javadocs 以获取可从这些构造中获取的方法/信息:


你需要在soapFaultException().getFault()这一行中删除括号后面的括号。我尝试进行编辑,但编辑不够长。 - Tony Scialo

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接