Hi Lorenzo,
Let me give the configuration of what I am using.
Axis 1.1 running under Tomcat 5.0.27
I think you have to subclass your Exception from AxisFault and then try to
catch exception on the client side.
Here's how my exception hierarchy looks
java.lang.Object
|
+--java.lang.Throwable
|
+--java.lang.Exception
|
+--java.io.IOException
|
+--java.rmi.RemoteException
|
+--org.apache.axis.AxisFault
|
+--MyException
Here's how my WSDD looks:
service name="Bank" provider="java:RPC" style="wrapped" use="literal">
<operation name="withdraw" qname="ns4:withdraw" returnQName="ns4:accepted"
returnType="xsd:boolean" xmlns:ns4="http://example"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<parameter qname="ns4:account" type="xsd:string"/>
<parameter qname="ns4:amount" type="xsd:int"/>
<fault class="example.MyExceptionType" qname="ns4:MyException"
type="ns4:InsufficientFundFaultType"/>
</operation>
<requestFlow>
<handler type="soapmonitor"/>
</requestFlow>
<responseFlow>
<handler type="soapmonitor"/>
</responseFlow>
<parameter name="sendMultiRefs" value="false"/>
<parameter name="wsdlServicePort" value="Bank"/>
<parameter name="className" value="example.BankSoapBindingImpl"/>
<parameter name="allowedMethods" value="withdraw"/>
<parameter name="wsdlServiceElement" value="BankService"/>
<parameter name="wsdlTargetNamespace" value="http://example"/>
<parameter name="wsdlPortType" value="Bank"/>
<parameter name="sendXsiTypes" value="false"/>
<parameter name="scope" value="Session"/>
<typeMapping
deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
encodingStyle="" qname="ns3:MyException"
serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
type="java:example.MyException" xmlns:ns3="http://example"/>
</service>
Note that the exception class fields come under details element. And here's
how its sent to the client:
?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<soapenv:Fault>
<faultcode>soapenv:Server.generalException</faultcode>
<faultstring></faultstring>
<detail>
<ns1:fault href="#id0" xmlns:ns1="urn:banktest"/>
<ns2:exceptionName
xmlns:ns2="http://xml.apache.org/axis/">example.MyException</ns2:exceptionNa
me>
</detail>
</soapenv:Fault>
<multiRef id="id0" soapenc:root="0"
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xsi:type="ns3:MyException"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:ns3="urn:banktest">
<errorDesc xsi:type="xsd:string">Invalid date format</errorDesc>
<errorCode xsi:type="xsd:int">1220</errorCode>
</multiRef>
</soapenv:Body>
</soapenv:Envelope>
A very good reference on exception handling is here:
Web services programming tips and tricks: Exception Handling with JAX-RPC
URL: http://www-106.ibm.com/developerworks/xml/library/ws-tip-jaxrpc.html
I hope that helps.
Sunil Kothari
----- Original Message -----
From: "Lorenzo Dalla Vecchia" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, January 22, 2005 5:53 PM
Subject: AxisFault with custom exception
> Hello everyone.
>
> I'm new to Axis and to this mailing list and I'm having a hard time trying
> to throw custom exceptions from my Axis web service.
>
> I'm working with a simple test project. Here's my exception class:
>
> public class MyException
> extends Exception
> {
> private String nome1;
> private String nome2;
>
> public MyException(String nome1, String nome2)
> {
> this.nome1 = nome1;
> this.nome2 = nome2;
> }
> public void setNome1(String nome1) {
> this.nome1 = nome1;
> }
> public String getNome1() {
> return nome1;
> }
> public void setNome2(String nome2) {
> this.nome2 = nome2;
> }
> public String getNome2() {
> return nome2;
> }
> }
>
> I followed the "bean" pattern to have Axis serialize it automatically.
> Java2WSDL produces the following description for the exception, which I
> think is correct.
>
> <complexType name="MyException">
> <sequence>
> <element name="nome1" nillable="true" type="xsd:string"/>
> <element name="nome2" nillable="true" type="xsd:string"/>
> </sequence>
> </complexType>
>
> I then execute WSDL2Java to generate proxy client classes and WSDD
> descriptors. Here is the type binding in deply.wsdd:
>
> <typeMapping
> xmlns:ns=http://test
> qname="ns:MyException"
> type="java:text.proxy.MyException"
> serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
>
deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
> encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
> />
>
> Now, the part where the problem arises. I build a simple client that calls
a
> method throwing MyException and here's the result:
>
> AxisFault
> faultCode:
{http://schemas.xmlsoap.org/soap/envelope/}Server.userException
> faultSubcode:
> faultString: test.MyException
> faultActor:
> faultNode:
> faultDetail:
> {http://xml.apache.org/axis/}hostname:atlantis
>
> test.MyException
> at
>
org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:2
21)
> at
>
org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:12
8)
> at
>
org.apache.axis.encoding.DeserializationContext.endElement(DeserializationCo
ntext.java:1083)
> at org.apache.crimson.parser.Parser2.maybeElement(Unknown Source)
> at org.apache.crimson.parser.Parser2.content(Unknown Source)
> at org.apache.crimson.parser.Parser2.maybeElement(Unknown Source)
> at org.apache.crimson.parser.Parser2.content(Unknown Source)
> at org.apache.crimson.parser.Parser2.maybeElement(Unknown Source)
> at org.apache.crimson.parser.Parser2.parseInternal(Unknown Source)
> at org.apache.crimson.parser.Parser2.parse(Unknown Source)
> at org.apache.crimson.parser.XMLReaderImpl.parse(Unknown Source)
> at javax.xml.parsers.SAXParser.parse(Unknown Source)
> at
>
org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext
.java:226)
> at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:645)
> at org.apache.axis.Message.getSOAPEnvelope(Message.java:424)
> at
>
org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChe
cker.java:62)
> at org.apache.axis.client.AxisClient.invoke(AxisClient.java:173)
> at org.apache.axis.client.Call.invokeEngine(Call.java:2719)
> at org.apache.axis.client.Call.invoke(Call.java:2702)
> at org.apache.axis.client.Call.invoke(Call.java:2378)
> at org.apache.axis.client.Call.invoke(Call.java:2301)
> at org.apache.axis.client.Call.invoke(Call.java:1758)
> at test.proxy.HelloStub.sayHello(HelloStub.java:147)
> at test.Client.main(Client.java:23)
> Exception in thread "main"
>
> "atlantis" is my computer netbios name.
> What is this AxisFault? I suspect it may be a problem with deserialization
> since the returned SOAP reply (captured with TCPMonitor) is:
>
> <soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> <soapenv:Body>
> <soapenv:Fault>
> <faultcode>soapenv:Server.userException</faultcode>
> <faultstring>test.MyException</faultstring>
> <detail>
> <ns1:hostname
> xmlns:ns1="http://xml.apache.org/axis/">atlantis</ns1:hostname>
> </detail>
> </soapenv:Fault>
> </soapenv:Body>
> </soapenv:Envelope>
>
> Since MyException carries two Strings (say "string1" and "string2"),
> shouldn't it look like <faultstring>test.MyException: string1,
> string2</faultstring> or something like that?
>
> When I throws Exception instances (not subclasses) they got serialized
with
> <faultstring>java.lang.Exception: message</faultstring> and work. Also
> there's no problem with throwing RemoteException.
>
> I'm using the latest Axis 1.2RC2 since Axis 1.1 refused to serialize
> Exception subclasses due to the "cause" field of type Throwable that was
> added in JVM 1.4 (wich I'm using).
>
> Please help me: I'm completely lost.
> Thanks in advance.
>
> --
> Lorenzo
>
>