• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Bobby Anderson
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13073
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bobby Anderson
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Billy, This looks all setup and should work
 
Bobby Anderson
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic