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:221)
at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:128)
at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.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(MustUnderstandChecker.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