• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

how to handle exception propagation in webservice client?

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
 
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much for yor replays,it helps me lot and i fixed my issue.
 
You can thank my dental hygienist for my untimely aliveness. So tiny:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic