java2db

How to handle custom exceptions using SOAP faults in web services



When a (JAX-WS) Web service request is being processed, if any error is encountered, the nature of the error needs to be send to the client, or sender of the request. So that the web service client can understand the problem or the mistake(Ex : Passing a wrong or null input parameter).

handle custom exceptions using SOAP faults Example to handle custom exceptions in Web services :

 

handle custom exceptions using SOAP faults Step 1 : Create a dynamic web project in Eclipse (Choose any IDE) and create two packages bookInfo , errorHandling .

 

 Step 2 :  Create a java class BookInfoWebService  under bookInfo package.

 

 Step 3 :  Create CustomErrorClass under errorHandling  package . The directory structure as follows.

 

handle custom exceptions using SOAP faults

 

 

 Step 4 :  Copy the below code (having web service annotations) in BookInfoWebService  class .

 

 

 Step 5 :  Copy the below code in CustomErrorClass to handle custom exceptions (Ex: Handle the user entered input validation Exceptions) .

Deploy the above application in any Web/Application server (Ex : Tomcat , GlassFish or JBoss).

 

 

handle custom exceptions using SOAP faults Step 6 : To test the application , create a new soap project (see how to create a project in soap) by passing the wsdl URL .

handle custom exceptions using SOAP faultsWe can test the application by creating a web service client (See) or from admin console (See).

 

handle custom exceptions using SOAP faults

 

 

 

 Step 7 : Open bookPrice (function) and click Request 1 link . It opens the below window .

To send request , click the top left run button (Green button) without passing any argument to <arg0></arg0>.

Finally it will display the error type , its description .
Create a java web service using bottom up approach

 

 

 

 Step 8 : Now pass an argument to <arg0></arg0> and click the run button  .This time  it sends a response to the client without any exception .
Create a java web service using bottom up approach




Related Posts :
How to create WCF web service in C# .NET ( visual studio 2013 )
How to call java SOAP web service in php ( php web service client )
What is RESTful web service (Introduction to RESTful web services)
How to call a web service from another web service (web service chain)
How to provide security to SOAP web services ( JAX-WS )
How to Create a java web service using bottom up approach
Create a java web service from WSDL (Top down approach) in Eclipse
Top down and Bottom up approach ( java web service )
   [will not be published]



^ <