2012-12-17 13 views
5

Sto chiamando un servizio web SOAP utilizzando JAX WS 2.0. Nel caso di errore sto ottenendo la seguente risposta:SOAPFaultException.getFault(). GetDetail() è null

<?xml version="1.0"?> 
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://www.w3.org/2003/05/soap- envelope"> 
    <soap:Header/> 
    <soap:Body> 
     <soap:Fault xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://www.w3.org/2003/05/soap- envelope" xmlns:xml="http://www.w3.org/XML/1998/namespace"> 
      <soap:Code> 
       <soap:Value>soap:Receiver</soap:Value> 
      </soap:Code> 
      <soap:Reason> 
       <soap:Text xml:lang="en">Exception of type 'blah blah' was thrown. 
       </soap:Text> 
      </soap:Reason> 
      <soap:Node>{SOME URL}</soap:Node> 
      <detail> 
       <error>345</error> 
       <message>Cannot find user. Blah blah</message> 
      </detail> 
     </soap:Fault> 
    </soap:Body> 
</soap:Envelope> 

Come si può vedere l'errore utile è nel nodo dettaglio:

<soap:Envelope> 
    <soap:Body> 
     <soap:Fault> 
      <detail> 

Nel mio cliente mi stanno un SOAPFaultException che ha un Oggetto SOAPFault. L'oggetto SOAPFault sembra mancare il nodo che ho postato sopra. SOAPFaultException.getFault(). GetDetail() è null. Tuttavia, ha ogni altro nodo che include il sapone: Reason. Qualche idea del perché manca il nodo dei dettagli?

Grazie.

risposta

3

Si scopre che il nodo di dettaglio deve includere anche lo spazio dei nomi SOAP. Quindi ha bisogno di essere:

<soap:detail> 

Dal momento che non ho il controllo sul servizio web sono riuscito a fare questo cambiamento nel metodo handleFault di un SOAPHandler personalizzato ho iniettato nel mio cliente. Dopo questa modifica, il dettaglio dell'errore non è più nullo e ha tutti i sottonodi.

In base a, http://www.w3.org/TR/soap12-part1/#soapfault, credo che lo sviluppatore debba correggere la risposta durante un errore.

0

questo ha funzionato per me:

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

}