I'm building a web service in Java from an existing WSDL. The wsimport
tool has generated all the Java classes bound to the elements in the service's schema. In particular, the fault declaration yields the following class:
@javax.xml.ws.WebFault(name = "Fault", targetNamespace = "http://my.company.com/service-1")
public class ServiceFault extends java.lang.Exception {
// constructors and faulInfo getter
}
Now I'd like to extend this class, so I can add more behavior:
public class MyServiceFault extends ServiceFault {
// some behavior
}
When I now throw instances of MyServiceFault
from my application, I expect these errors to be properly serialized to XML in the SOAP answer. But instead, I get something like this:
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Header/>
<env:Body>
<env:Fault>
<faultcode>env:Server</faultcode>
<faultstring>Some fault string.</faultstring>
</env:Fault>
</env:Body>
</env:Envelope>
That is, I am completely missing the faultInfo element. My SOAP stack treats MyServiceFault
as any other exception, not as an exception representing a fault in the service.
I thought first it was because the @WebFault
annotation wasn't inherited by MyServiceFault
, but I've tried again after explicitly adding this annotation, without success.
Any idea what I am doing wrong here?