Hi,

I've had the same problem as Bill and have seen a number of other posts
asking similar questions about service-specific exceptions. I have tried the
"samples.faults" example, which works fine but is a little confusing because
the service specific exception extends RemoteException and implements
Serializable, whereas Bill was asking about an exception that only extends
java.lang.Exception. Also, the deployment descriptor for this example is
quite difficult to understand because of the <operation>, <parameter>,
<fault> and <typeMapping> elements, and nasty namespaces such as
"http://localhost:8080/ch09/services/Employee";

As far as I can tell, Axis 1.2 Alpha will not handle service specific
exceptions automatically. If you were to write a class called MyService with
a method that raised an exception, MyException, then to use a simple
deployment descriptor (shown below) the auto-generated WSDL will show
MyException, but unfortunately this exception will never reach the client.
If you invoke a web service operation that will raise a MyException on the
service implementation, Axis will instead throw an AxisFault back to the
client, and the best you will be able to do is retrieve the exception class
name from buried within the AxisFault.

  <deployment 
    xmlns="http://xml.apache.org/axis/wsdd/";
    xmlns:java="http://xml.apache.org/axis/wsdd/providers/java";>
    <service name="MyService" provider="java:RPC">
      <parameter name="className" value="my.package.MyService"/>
      <parameter name="allowedMethods" value="*"/>
    </service>
  </deployment>

In order to get service specific exceptions to work, I had to add additional
elements to the deployment descriptor in a similar manner to the
samples.faults example. These elements describe the operation and exception,
and provide type-mapping details used for serialization and deserialization.
For example:

  <deployment 
    xmlns="http://xml.apache.org/axis/wsdd/";
    xmlns:java="http://xml.apache.org/axis/wsdd/providers/java";
    xmlns:ns="http://my.package";
    xmlns:xsd="http://www.w3.org/2001/XMLSchema";>
    <service name="MyService" provider="java:RPC">
      <operation name="myOperation" 
                 qname="ns:myOperation" 
                 returnQName="myOperationResponse"
                 returnType="xsd:string">
        <fault name="MyException"
               qname="ns:MyException" 
               type="ns:MyException" 
               class="my.package.MyException"/>
      </operation>
      <typeMapping
        qname="ns:MyException"
        type="java:my.package.MyException"
        serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
        deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
        encodingStyle="http://schemas.xmlsoap.org/soap/encoding/";
      />
      <namespace>http://my.package</namespace>
      <parameter name="className" value="my.package.MyService"/>
      <parameter name="allowedMethods" value="myOperation"/>
    </service>
  </deployment>

I think it would be very nice if Axis could handle service specific
exceptions automatically, so that an exception raised by the service
implementation class can be caught by a client. If an exception provides
getter and setter methods, then Axis should be able to serialize and
deserialize it without any difficulty. It would be easier to use Axis if it
wasn't necessary to specify the <operation>, <fault> and <typeMapping>
elements in the "deploy.wsdd" file for simple service-specific exceptions.

Cheers,
Tom Sugden


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] 
Sent: Thursday, September 16, 2004 6:49 AM
To: [EMAIL PROTECTED]
Subject: Re: Axis and user defined Exceptions

Yep (axis 1.1) - have you tried the samples.faults package in the axis /
samples ?

/t

> Has anyone written user defined Exceptions, extending the 
> java.lang.Exception class and successfully thrown them from the server 
> side and caught them at the client side?  Currently, whenever I try to 
> throw a user defined exception, I get this message on the client side, 
> wrapped in a SOAPFaultException....Note, the rest of the web service 
> works fine, just the exception throwing and catching part.



Reply via email to