Wrapping exceptions into faults
This recipe explains the definition of faults in web services. Faults are one of the fundamental concepts of handling errors in web services. Usually, web services throw an exception as a result of an unsuccessful operation. This recipe will explain how to define faults for an operation in case of a date format mismatch.
Getting ready
In this recipe, we will amend the implementation of our web service example from the Annotating the service endpoint interface with @SOAPBinding recipe.
How to do it…
We will change the source code of our example so that it will throw an exception in case there is a problem with processing a credit card operation. Now, if we run the example, even if the authorization fails, the processing is performed further. A more correct approach would be to handle faults and stop processing if a fault occurs.
We open the CreditCardGateway.java
file in JDeveloper and search for the AuthoriseCreditCard
method. We change the code so that...