aspose file tools*
The moose likes Web Services and the fly likes How do I catch a user define exception on the client (SOAP/JAX-RPC/WSDL) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "How do I catch a user define exception on the client (SOAP/JAX-RPC/WSDL)" Watch "How do I catch a user define exception on the client (SOAP/JAX-RPC/WSDL)" New topic
Author

How do I catch a user define exception on the client (SOAP/JAX-RPC/WSDL)

Bobby Anderson
Ranch Hand

Joined: Oct 28, 2008
Posts: 114
I have a user defined exception:


This generates the following code for the exception:


When I throw this exception on the server side things look ok. However on the client side I catch a SOAPFaultException instead of my TestException. Has anyone successfully defined an exception and caught that exception on the client side?

Thanks,
Billy
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
A SOAPFaultException is what the standard says you should get.

Instead of a custom exception create a SOAPFaultException with the desired message.

Bill
Bobby Anderson
Ranch Hand

Joined: Oct 28, 2008
Posts: 114
This is not true you can define your own exception to throw and catch. I am missing something though as I am not sure what I have wrong. The spec says as long as you define the exception correctly JAX-RPC will throw that exception rather than the SOAPFaultException. I am sure someone has done this before, if so please help.

I.E. as part of the spec:

Checked user exception

A good programming practice often involves explicitly defining checked user exceptions as part of the interface contract. In the JAX-RPC world, programmers need to first define wsdl:faults as part of a wsdl:operation. A wsdl:operation allows multiple wsdl:fault elements, just like a Java method allows multiple exceptions. Each wsdl:fault is mapped to a user exception as part of the SEI. In most cases, Java exceptions do not have complicated data structures; similarly for wsdl:fault, the schema definition referenced by the wsdl:fault is often straightforward. Nevertheless, it's still very important for programmers to think over which kind of exceptions are expected to be thrown, and then define appropriate wsdl:faults.
Vivek Kr Singh
Ranch Hand

Joined: Oct 12, 2007
Posts: 56
Billy Newman wrote:A good programming practice often involves explicitly defining checked user exceptions as part of the interface contract. In the JAX-RPC world, programmers need to first define wsdl:faults as part of a wsdl:operation. A wsdl:operation allows multiple wsdl:fault elements, just like a Java method allows multiple exceptions. Each wsdl:fault is mapped to a user exception as part of the SEI.


If the fault is defined as a wsdl:fault then your client code will be aware of this. For example if you are using axis to generate client class, then there will be suitable Java exception class created for all exceptions declared within wsdl:fault.

SCJP 1.4
Bobby Anderson
Ranch Hand

Joined: Oct 28, 2008
Posts: 114
I am using JAX-RPC and yes there is a well formed user defined exception generated. Please see the code I put in. So everything looks fine and according to the spec I should be able to catch the exception on the client side.

Server code


Client code


As an aside I am using JBoss application server so maybe there is something I need to setup to get this to work correctly.
Vivek Kr Singh
Ranch Hand

Joined: Oct 12, 2007
Posts: 56
Billy, This looks all setup and should work
Bobby Anderson
Ranch Hand

Joined: Oct 28, 2008
Posts: 114
Is this a JBoss or tomcat configuration issue? I.E. when I use 4.0.5.GA I get back a SOAPFaultException. I thought that I would upgrade to JBoss 4.2.3.GA to see if they resolved something but with 4.2.3.GA with the same code I get back a java.rmi.ServerException.

Anyone done this on JBoss/tomcat before?
Bobby Anderson
Ranch Hand

Joined: Oct 28, 2008
Posts: 114
It seems like tomcat/jboss is not adding in the detail portion of the SOAP xml that comes back to the client. Without that tag I don't think that the exception can get translated correctly on the client side.

I.E.


Why is this tag not in the xml I get back?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do I catch a user define exception on the client (SOAP/JAX-RPC/WSDL)