Hi people,
I am really puzzled about Axis Code generators and the way custom exceptions
are passed. I do not even find good documentation on it. I've been on this
problem for almost a week now, and still do not find any answer. My problem: I
can invoke web services without problems, but I do not get back customized
exceptions on my Java client side.
Here is my generation procedure and source:
1) I write a class AService, in which I define one simple operation
(add(int,int,int)), it returns a result of type long, if the third argument is
0. If the 3rd int is not 0, it will throw "CustomException".
2) "CustomException" is a class defined as extending java.lang.Exception and
implements java.io.Serializable
3) I generate the service with Axis2 tools, and deploy the service.
4) I generate the wsdl. The wsdl correctly includes the fault element named
<wsdl:fault name="CustomException">
<soap:fault use="literal" name="CustomException"/>
5) I generate the java client with the axis2 codegen wizard.
6) I invoke the web service with it, without exception testing: works.
7) I invoke it to throw the exception (3rd int = 1): doesn't work. I only get
an AxisFault. But the generated client should throw a CustomException.
AxisFault.getDetail() is empty.
What is wrong ?
I include the 2 simple java files from which I started here:
package com.foo.bar;
public class AService {
public long Add(int a, int b, int exceptionThrown) throws
CustomException {
if (exceptionThrown != 0) {
System.out.println("CustomException to b
instantiated");
CustomException e = new CustomException();
e.setCustomMsg("bar");
throw e;
}
return a+b;}
}
Here the exception class:
package com.foo.bar;
import java.io.Serializable;
public class CustomException extends java.lang.Exception implements
Serializable {
private static final long serialVersionUID = 1542353156105984960L;
private String customMsg;
public String getCustomMsg() {return customMsg;}
public void setCustomMsg(String customMsg) {this.customMsg=customMsg;}
}
Here is the generated WSDL:
<wsdl:definitions xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:xsd="http://bar.foo.com/xsd" xmlns:ns="http://bar.foo.com"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
targetNamespace="http://bar.foo.com"><wsdl:types><xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="qualified"
elementFormDefault="qualified" targetNamespace="http://bar.foo.com/xsd">
<xs:element name="CustomExceptionFault">
<xs:complexType>
<xs:sequence>
<xs:element name="CustomException" nillable="true" type="xsd:CustomException" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="CustomException" type="xsd:CustomException" />
<xs:complexType name="CustomException">
<xs:complexContent>
<xs:extension base="xs:Exception">
<xs:sequence>
<xs:element name="customMsg" nillable="true" type="xs:string" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="Add">
<xs:complexType>
<xs:sequence>
<xs:element name="a" nillable="true" type="xs:int" />
<xs:element name="b" nillable="true" type="xs:int" />
<xs:element name="exceptionThrown" nillable="true" type="xs:int" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="AddResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="return" nillable="true" type="xs:long" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema></wsdl:types><wsdl:message name="AddMessage"><wsdl:part
name="part1" element="xsd:Add" /></wsdl:message><wsdl:message
name="AddResponseMessage"><wsdl:part name="part1" element="xsd:AddResponse"
/></wsdl:message><wsdl:message name="CustomException"><wsdl:part name="part1"
element="xsd:CustomException" /></wsdl:message><wsdl:portType
name="AServicePortType"><wsdl:operation name="Add"><wsdl:input
xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" wsaw:Action="urn:Add"
message="ns:AddMessage" /><wsdl:output
xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"
message="ns:AddResponseMessage" wsaw:Action="urn:Add" /><wsdl:fault
message="ns:CustomException" name="CustomException"
/></wsdl:operation></wsdl:portType><wsdl:binding name="AServiceSOAP11Binding"
type="ns:AServicePortType"><soap:binding
transport="http://schemas.xmlsoap.org/soap/http" style="document"
/><wsdl:operation name="Add"><soap:operation soapAction="urn:Add"
style="document" /><wsdl:input><soap:body use="literal"
/></wsdl:input><wsdl:output><soap:body use="literal"
/></wsdl:output><wsdl:fault name="CustomException"><soap:body use="literal"
/></wsdl:fault></wsdl:operation></wsdl:binding><wsdl:binding
name="AServiceSOAP12Binding" type="ns:AServicePortType"><soap12:binding
transport="http://schemas.xmlsoap.org/soap/http" style="document"
/><wsdl:operation name="Add"><soap12:operation soapAction="urn:Add"
style="document" /><wsdl:input><soap12:body use="literal"
/></wsdl:input><wsdl:output><soap12:body use="literal"
/></wsdl:output><wsdl:fault name="CustomException"><soap12:body use="literal"
/></wsdl:fault></wsdl:operation></wsdl:binding><wsdl:service
name="AService"><wsdl:port name="AServiceSOAP11port"
binding="ns:AServiceSOAP11Binding"><soap:address
location="http://localhost:8080/axis2/services/AService"
/></wsdl:port><wsdl:port name="AServiceSOAP12port"
binding="ns:AServiceSOAP12Binding"><soap12:address
location="http://localhost:8080/axis2/services/AService"
/></wsdl:port></wsdl:service></wsdl:definitions>
Thanks in advance for help,
Jay
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]