Java JAX-WS SOAP Faults - 解析 SOAPFaultException 中错误的详细信息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22474994/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 15:58:23  来源:igfitidea点击:

JAX-WS SOAP Faults - parse the details of the error in a SOAPFaultException

javaweb-servicessoapjax-ws

提问by user3432316

I'm having the need to get the details of error if it's a faulty soap request.

如果是错误的肥皂请求,我需要获取错误的详细信息。

I'm using JAX-WS to create web service client. My problem is that during a faulty transaction, the web service client is able to catch the SOAPFaultException but without detail:

我正在使用 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)

If I send the request through SOAPUI, I can get the response with details as:

如果我通过 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>

Did I miss any configuration in web service client? Many thanks in advance.

我是否错过了 Web 服务客户端中的任何配置?提前谢谢了。

回答by Scott Heaberlin

To get details from the javax.xml.ws.soap.SOAPFaultException:

要从以下位置获取详细信息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
}

See associated javadocs for methods / info you can get from these constructs:

有关您可以从这些构造中获得的方法/信息,请参阅相关的 javadoc: