This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Services and the fly likes Proper Exception handling in WebServices Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Proper Exception handling in WebServices" Watch "Proper Exception handling in WebServices" New topic
Author

Proper Exception handling in WebServices

Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Hi

I have developed a web service in java based on JAX WS approach , now i need to implement Exception Handling in my service .

Please tell me whether i should use SOAPFaultException or UserDefinedException .

What will be the best approach ??
Please share your ideas .


Save India From Corruption - Anna Hazare.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12753
    
    5
Seems to me it is preferable to stick to the existing standard if you can get enough information on the reason into the SOAPFaultException and get it out on the client side.

Bill
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
My personal choice would be to use service-specific exceptions, with an eye on the JAX-WS 2.1 specification document, sections 2.5, 3.7 and 6.4.
If you are doing Java-first development, JAX-WS will help you translate the service-specific exceptions to appropriate faults.
When developing a JAX-WS client and if the service declares custom faults, these will be translated into Java exceptions.
SOAPFaultException is the basic type of exception being able to carry SOAP related information and faults that are not mapped to any exception will cause this exception to be thrown on the client side.
Clients to services using service specific exceptions will also be able to use the regular Java exception-handling mechanism in dealing with errors, without having to implement error handling based on the contents of a SOAPFaultException.
Best wishes!
Hany Shafik
Ranch Hand

Joined: Jun 21, 2008
Posts: 80
Hi,

My personal point of view is that exceptions resulting from unanticipated run-time error should be thrown as SOAPFaultException, other validation error or business exception should be mapped to soap fault as custom java exception.
The following is quoted from book "SOA using java Web Services" chapter 7

I distinguish
between Java exceptions that can reasonably be mapped to a wsdl:fault
message (mapped exceptions) and those that have to be represented as
generic SOAP faults (unmapped exceptions). As an example, it is likely that
when an exception is thrown because input message validation fails, this
would be a mapped exception because the WSDL writer could anticipate
such an exception and define a wsdl:fault message for it. On the other
hand, exceptions resulting from unanticipated run-time errors most likely
will not have a corresponding wsdl:fault message and will need to be
returned as generic SOAP faults.
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Thank you all .

Hany , you made it look simple .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Proper Exception handling in WebServices
 
Similar Threads
How to do exception handling in JSF
Data Service problem
exception handling approach for j2ee web apps
Struts Exception Handling Desing
Global exception handling