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

1

7

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:

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:

<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.

Daggett answered 18/3, 2014 at 9:23 Comment(0)
C
11

To get details from the 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:

Cruz answered 22/3, 2014 at 1:14 Comment(1)
You need to remove the parenthesis after soapFaultException on the line soapFaultException().getFault(). I tried to edit but the edit wasn't long enoughCupronickel

© 2022 - 2024 — McMap. All rights reserved.