2012-12-17 11 views
5

Wywołuję usługę sieciową SOAP przy użyciu JAX WS 2.0. W przypadku błędu otrzymuję następującą odpowiedź:SOAPFaultException.getFault(). GetDetail() ma wartość 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> 

Jak widać użyteczny błędu w węźle szczegółach:

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

w moim klientem Otrzymuję SOAPFaultException który ma Obiekt SOAPFault. Wydaje się, że obiekt SOAPFault nie ma węzła, który napisałem powyżej. SOAPFaultException.getFault(). GetDetail() ma wartość null. Jednak ma każdy inny węzeł, w tym mydło: Reason. Masz pomysł, dlaczego brakuje węzła detali?

Dzięki.

Odpowiedz

3

Okazuje się, że węzeł szczegółów musi również zawierać przestrzeń nazw SOAP. Więc to musi być:

<soap:detail> 

Ponieważ nie mam kontroli nad usługą internetową udało mi się dokonać tej zmiany w sposobie handleFault niestandardowej SOAPHandler I wtryskiwanego do mojego klienta. Po tej zmianie szczegół błędu nie jest już pusty i ma wszystkie węzły.

Na podstawie, http://www.w3.org/TR/soap12-part1/#soapfault, uważam, że programista musi poprawić odpowiedź podczas usterki.

0

Ten pracował dla mnie:

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

}