Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get SOAP fault's faultcode when handling custom fault exception
    text
    copied!<p>Our system consumes SOAP Web Service, using JAX-WS client stubs generated based on service's WSDL. In case of error server returns SOAP faults like this:</p> <pre><code>&lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt; &lt;s:Header /&gt; &lt;s:Body&gt; &lt;s:Fault&gt; &lt;faultcode&gt;SomeErrorCode&lt;/faultcode&gt; &lt;faultstring xml:lang="en-US"&gt;Some error message&lt;/faultstring&gt; &lt;detail&gt; &lt;ApiFault xmlns="http://somenamespace.com/v1.0" xmlns:a="http://somenamespace.com/v1.0" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"&gt; &lt;a:RequestId&gt;123456789&lt;/a:RequestId&gt; &lt;a:CanRetry&gt;true&lt;/a:CanRetry&gt; &lt;/ApiFault&gt; &lt;/detail&gt; &lt;/s:Fault&gt; &lt;/s:Body&gt; </code></pre> <p>Based on WSDL <code>SomeCustomFault</code> exception class is generated and all service methods are declared to throw this (see below) exception.</p> <pre><code>@WebFault(name = "ApiFault", targetNamespace = "http://services.altasoft.ge/orders/v1.0") public class SomeCustomFault extends Exception { private ApiFault faultInfo; public SomeCustomFault(String message, ApiFault faultInfo) { super(message); this.faultInfo = faultInfo; } public SomeCustomFault(String message, ApiFault faultInfo, Throwable cause) { super(message, cause); this.faultInfo = faultInfo; } public ApiFault getFaultInfo() { return faultInfo; } } </code></pre> <p>As you can see this custom fault exception extends <code>Exception</code> and not <a href="http://docs.oracle.com/javaee/1.4/api/javax/xml/rpc/soap/SOAPFaultException.html" rel="noreferrer">SOAPFaultException</a>. Hovewer I need to get SOAP fault's faultcode which could be retrieved only from <a href="http://docs.oracle.com/javaee/1.4/api/javax/xml/rpc/soap/SOAPFaultException.html" rel="noreferrer">SOAPFaultException</a> using <a href="http://docs.oracle.com/javaee/1.4/api/javax/xml/rpc/soap/SOAPFaultException.html#getFaultCode%28%29" rel="noreferrer">getFaultCode</a> method. Could you tell me how can I reach <a href="http://docs.oracle.com/javaee/1.4/api/javax/xml/rpc/soap/SOAPFaultException.html" rel="noreferrer">SOAPFaultException</a> or SOAP fault's faultcode in place where I catch above mentioned custom fault exception?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload