How do you throw a custom soap fault on a JAX-WS web service? How can I specify the faultCode
, faultString
and detail
of the soap fault? Is it possible to set the value of the detail
as bean instead of a String
?
Please note that I'm developing using code-first approach.
To choose the right fault code, see http://www.tutorialspoint.com/soap/soap_fault.htm .
Use the
@WebFault
annotation.You can see a good example in Using SOAP Faults and Exceptions in Java JAX-WS Web Services - Eben Hewitt on Java.
You will see the example:
UPDATE
Another way is to declare the typical exception in the
throws
clause.e.g. Suppose the following is my exception class:
And the next class is the service implementation.
If my request is:
There is no problem:
But...
Then...