I would like to add some SOAP Faults to my JAX-WS web service, but I would like not to change content of WSDL schema. As far as I read I would have to use annotation @WebFault to define SOAP Fault and it automatically causes changes in WSDL during next build. Is there any way to use SOAP Faults without changing content of WSDL scheme?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Test your web service using Soap Ui. I just tested mine, using a custom message in the exception and when I see the Response from Soap Ui, I see that the Fault String has my custom Message.
When you throw an Exception from your code it will be automatically mapped to a SOAP fault by JAX-WS in the response. There's no need to define a fault in your WSDL.
Using
@WebFault
or defining a<soap:fault>
element in the WSDL file is used to declare that a specific operation might return a custom SOAP fault.@WebFault
will definitely add a<soap:fault>
element in the resulting WSDL.To recap, throwing an Exception will insert a element in the soap response.
Update
Custom faultstring:
The string message that you pass as a parameter to the
Exception
constructor represents the faultstring element in the<soap:fault>
. Example:Resulting fault in the soap response:
Custom faultcode:
I don't think you can change the faultcode with normal Java exceptions. If you really need to do that you can take a look at JAX-WS SOAPFaultException.
Keep in mind that faultcodes are used to indicate the type of error produced, and most of the time you are going to return a Server fault from your webservice.
This are the four existing fault codes in SOAP 1.1 and 1.2:
The first three are going to be created by JAX-WS when parsing the SOAP request and unless there's a very specific situation or you are writing your own JAX-WS handlers/interceptors you will not need to return any other faultcode besides 'Server'.
Custom detail:
The
<detail>
element will be populated with an element representing the Exception. For example if you are throwing anew MyCustomException("custom message")
it will be something like this: