Search code examples
javaeclipseweb-servicessoapwsdl

SOAP fault handling in java


I am pretty new to SOAP and I am trying to understand SOAP fault handling (in Java). I have done reading about this topic but there are still some concepts that remain unclear to me.

More specifically, how to handle various response codes using Eclipse WSDL editor. I have used Eclipse WSDL editor to create my WSDL but I am open to using another tool such as SoapUI to accomplish this (handling faults).

I've attached an image of a simple web service that is supposed to take UserID (request) and return information about the user such as name, age etc (response). I would like to handle warning and error codes that may be returned by the response. E.g. duplicate UserID found > code "ABC" or no UserID found > code "XYZ".

I don't really understand how/where these codes are returned and where to process them. Would the response just return "ABC" as a String?

enter image description here

The following question is based on the attached image. Do I need to setup displayUserInfoFault as a new class that extends the Exception class and add "throws displayUserInfoFault" to the displayUserInfo() method?

Any guidance would be much appreciated. Thanks!


Solution

  • If you want to return a proper response to the caller. Then you need to return an object not only one fields. For example you can create new class you can call it Response that contains the fields you want to display it to the caller like responCode and responseDescription. Using these two fields you can cover the different error cases you have. And of course you need to change the return type of the method playUserInfo to be of type Response