Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse soapfault's detail?

I am trying to get the values inside this soap fault's "detail", but I haven't found any ways of doing so.

The response from the server:

 <?xml version="1.0" encoding="UTF-8"?>
 <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Body>
     <SOAP-ENV:Fault>
       <faultcode>SOAP-ENV:Client</faultcode>
       <faultstring>Many Errors</faultstring>
       <detail>
         <error_id>2</error_id>
         <errors>
           <error>
             <error_id>1</error_id>
             <error_description>Unknown Error</error_description>
           </error>
           <error>
             <error_id>5</error_id>
             <error_description>Not Authorized</error_description>
           </error>
           <error>
             <error_id>9</error_id>
             <error_description>Password should be at least 6 characters including one letter and one number</error_description>
           </error>
         </errors>
       </detail>
     </SOAP-ENV:Fault>
   </SOAP-ENV:Body>
 </SOAP-ENV:Envelope>

I need to get the error_ids along with their respective error_descriptions. So far I've only managed to get the detail via kSOAP with the following way:

    if (envelope.bodyIn instanceof SoapObject) {
        return envelope.bodyIn.toString();
    } else if (envelope.bodyIn instanceof SoapFault) {
        SoapFault e = (SoapFault) envelope.bodyIn;
        Node details = ((SoapFault) envelope.bodyIn).detail;

    }

but I haven't managed to get a single value I need when I try to "navigate" through it.

Any help is greatly appreciated. I have found little to non information about handling soap faults with ksoap2 online...

like image 348
Alex Styl Avatar asked Feb 18 '26 09:02

Alex Styl


1 Answers

The following code handles better

Iterator it = soapFaultClientException.getSoapFault().getFaultDetail().getDetailEntries();
while (it.hasNext())
{
 Source errSource = it.next().getSource();
 @SuppressWarnings("unchecked")
 JAXBElement errJaxb = (JAXBElement) springWebServiceTemplate.getUnmarshaller().unmarshal(errSource);
 ServerCustomizedError err = errJaxb.getValue();
 ....
}
like image 71
Denis Wang Avatar answered Feb 21 '26 13:02

Denis Wang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!