axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 16771] New: - cannot catch specific exception in client if it has a message
Date Tue, 04 Feb 2003 18:14:52 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=16771>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=16771

cannot catch specific exception in client if it has a message

           Summary: cannot catch specific exception in client if it has a
                    message
           Product: Axis
           Version: 1.1beta
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Serialization/Deserialization
        AssignedTo: axis-dev@xml.apache.org
        ReportedBy: herold@cotagesoft.com


A service throws a service-specific exception that extends Exception and has a 
constructor to set the exception message.  Use java2wsdl and wsdl2java to 
generate the client stub.  Bug:  when the service throws the exception, the 
client cannot catch it - instead, it can only catch AxisFault.  Additionally, 
the message is not passed intact, but is instead prepended with the class name 
of the exception.

Here is the exception class:

class MyException extends Exception {
  MyException(String s) {super(s);}
}

In my client app, I want to catch MyException, and print the message:

try {
  myService.myMethod();
} catch (MyException e) {
  System.out.println("caught MyException, msg is " + e.getMessage());
} catch (AxisFault) af) { /* FIXME this is for debugging */
  System.out.println("caught AxisFault, msg is " + af.getMessage());
}

I use java2wsdl, then wsdl2java to generate client stubs.  The generated 
client stub for the exception  class extends org.apache.axis.AxisFault instead 
of Exception, but I can live with that.  However, when I call my service's 
method and it throws MyException("HEY"), the client only can catch an 
AxisFault, and not the stub version of MyException.  Plus, the message on the 
client is the fully qualified classname of MyException plus the orginal server-
thrown message "HEY".

Changing to having the original exception extend AxisFault made the message on 
the client correct, i.e. the classname was gone from the message, But, the 
client could still only catch AxisFault.  Then, removing the string-argument 
constructor enabled the client to directly catch the specific exception.

So it seems you can't have have your cake and eat it too - either you get the 
message on the client and you can't catch the specific exception class, or you 
can catch the exception class and you have to forgo the message.

This seems like a bug - am  I missing something?

++++++++++++

I experimented with various combinations of the server-side version of the 
service-specific exception:  extends Exception, AxisFault or RemoteException, 
has constructor with String argument or doesn't, with the following results:

Extends     String Constr  Client throws  Client msg

Exception   no             AxisFault      full class name
Exception   yes            AxisFault      full class name + string
AxisFault   no             MyException    null
AxisFault   yes            AxisFault      string
RemoteExcp  no             AxisFault      full class name
RemoteExcp  yes            AxisFault      full class name + string

I have included a test case, which is a few modest source files and a shell 
script to build it.  You must first modify the shell script for your classpath 
and servlet container.  Running the script compiles everything, and generates 
a script to deploy the test app (deploy.sh) and run it after restarting your 
servlet container (run.sh).  You can tweak the exception class and the service 
class to try out the various combinations.

Mime
View raw message