*
The moose likes Web Services and the fly likes how to handle exception propagation in webservice client? 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 "how to handle exception propagation in webservice client?" Watch "how to handle exception propagation in webservice client?" New topic
Author

how to handle exception propagation in webservice client?

gopi dasaraju
Greenhorn

Joined: May 09, 2008
Posts: 6
Hi ,
Is there a way to catch an exception thrown by Webservice server handler?

We have a situation where we need to handle the exception on the client side thrown by the server handler.
We are using Webspehere webservices created thru RAD 7 and clients are generated using axis 2 code generator tool. We generate WSDL from java class rather than Java from WSDL.

We have vague idea that we can use wsld fault mechanism but does not have much implementation knowledge on it.

Any ideas on this will be great help.

Thanks in advance..
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2921
    
    5
It isn't quite clear what you are asking.

Typically both application exceptions on the server and server exceptions are automatically mapped by the SOAP stack to SOAP Faults. The only difference is that application exceptions are mapped to SOAP Faults listed in the WSDL. Any returned SOAP Fault is then converted to an exception (not necessarily the same one that exists on the server) by the Java Client SOAP stack. Some more details are discussed in this topic.
gopi dasaraju
Greenhorn

Joined: May 09, 2008
Posts: 6
Thanks for your quick reply.
Here is little more detail ::

We have our regular webservices which has some business methods. Also we have a custom handler which extends javax.xml.rpc.handler.GenericHandler to handle requests [public boolean handleRequest(MessageContext context){
.......
return true;
}] for all our application Webservices.

So, in case of any application errors, handler throws an excpetion which we expect it to be caught in the client stub. e.g. if our application throws InvalidDataException with a specific message on it, we expect it to be caught in the client code as InvalidDataException with the original message on it.

Is there a way to achieve this?

Thanks,
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2921
    
    5
Serverside JAX-RPC message handlers are only supposed to throw a javax.xml.rpc.soap.SOAPFaultException (or a subclass) from the handleRequest message mainly because the exceptions thrown by handlers are supposed to be related to the SOAP headers not the SOAP Body. SOAPFaultException features the standard parts of a SOAP Fault: detail, faultactor, faultcode (e.g. {http://schemas.xmlsoap.org/soap/envelope/}Client. {http://schemas.xmlsoap.org/soap/envelope/}Server, {http://schemas.xmlsoap.org/soap/envelope/}VersionMismatch, {http://schemas.xmlsoap.org/soap/envelope/}MustUnderstand), and faultstring.

Now some SOAP stacks like Axis 1.x will place java exception related information into the FaultString. e.g.:

You could adopt a similar tactic by providing a customized fault string when you create a javax.xml.rpc.soap.SOAPFaultException.

However an "InvalidDataException" is clearly an application exception and therefore should be part of the service contract (WSDL) - it should be thrown by the implementing web service method, not a handler. Each operation that can return an "InvalidData" fault should declare it in the WSDL. Furthermore you can then define the structure and types of the "InvalidData" fault message in the WSDL types section through XML schema. Once you have done that the WSDL-to-Java generator will generate a Java "InvalidDataFaultException" that can be used by the implementing web service method so that it can throw the exception (fault) when necessary.

Now as the service all you have control over is the (XML) SOAP fault that the client will receive. You have absolutely no control over the exception that it will be mapped to. That is up to your client, their SOAP stack and its configuration.
gopi dasaraju
Greenhorn

Joined: May 09, 2008
Posts: 6
Thank you very much for yor replays,it helps me lot and i fixed my issue.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to handle exception propagation in webservice client?
 
Similar Threads
"Using the annotations in webservice"
Calling a .net web service from java as a client
Exception Handling
Deploying Webservices in Websphere Application server 6.1
Soap over HTTP