views:

80

answers:

0

I'm developing a simple web service using Eclipse, Axis1 and JBoss. The web service class looks like this:

public class MyService {
    public ComplexClass getSomeData() {
        ComplexClass complex = new ComplexClass();
        Children children[] = new Children[2];
        children[0] = new Children();
        complex.myFirstArray = children;

        MoreChildren[] moreChildren = new MoreChildren[2];
        moreChildren[0] = new MoreChildren();
        children[0].mySecondArray = moreChildren;

        return complex;
    }
}

To create the web service, I right click on the MyService class, select Create Web Service, using Axis1, document/literal (wrapped).

The definition of ComplexClass, Children and MoreChildren:

public class ComplexClass {
    public String name;
    public int age;
    public Children[] myFirstArray;

    public ComplexClass() {
        this.name = "defaultName";
        this.age = -1;
        this.myFirstArray = new Children[0];
    }
}

public class Children {
    public int attribute;
    public MoreChildren[] mySecondArray;

    public Children() {
        this.attribute = 1;
        this.mySecondArray = new MoreChildren[0];
    }
}

public class MoreChildren {
    public String someValue;

    public MoreChildren() {
        this.someValue = "defaultValue";
    }
}

The generated wsdl looks like this:

<wsdl:definitions targetNamespace="http://example" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://example" xmlns:intf="http://example" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
<!--WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)-->
<wsdl:types>
<schema elementFormDefault="qualified" targetNamespace="http://example" xmlns="http://www.w3.org/2001/XMLSchema"&gt;
<element name="getSomeData">
<complexType/>
</element>
<element name="getSomeDataResponse">
<complexType>
<sequence>
<element name="getSomeDataReturn" type="impl:ComplexClass"/>
</sequence>
</complexType>
</element>
<complexType name="MoreChildren">
<sequence>
<element name="someValue" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
<complexType name="ArrayOfMoreChildren">
<sequence>
<element maxOccurs="unbounded" minOccurs="0" name="item" type="impl:MoreChildren"/>
</sequence>
</complexType>
<complexType name="Children">
<sequence>
<element name="attribute" type="xsd:int"/>
<element name="mySecondArray" nillable="true" type="impl:ArrayOfMoreChildren"/>
</sequence>
</complexType>
<complexType name="ArrayOfChildren">
<sequence>
<element maxOccurs="unbounded" minOccurs="0" name="item" type="impl:Children"/>
</sequence>
</complexType>
<complexType name="ComplexClass">
<sequence>
<element name="name" nillable="true" type="xsd:string"/>
<element name="age" type="xsd:int"/>
<element name="myFirstArray" nillable="true" type="impl:ArrayOfChildren"/>
</sequence>
</complexType>
</schema>
</wsdl:types>
<wsdl:message name="getSomeDataResponse">
<wsdl:part element="impl:getSomeDataResponse" name="parameters"/>
</wsdl:message>
<wsdl:message name="getSomeDataRequest">
<wsdl:part element="impl:getSomeData" name="parameters"/>
</wsdl:message>
<wsdl:portType name="MyService">
<wsdl:operation name="getSomeData">
<wsdl:input message="impl:getSomeDataRequest" name="getSomeDataRequest"/>
<wsdl:output message="impl:getSomeDataResponse" name="getSomeDataResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="MyServiceSoapBinding" type="impl:MyService">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/&gt;
<wsdl:operation name="getSomeData">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="getSomeDataRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="getSomeDataResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="MyServiceService">
<wsdl:port binding="impl:MyServiceSoapBinding" name="MyService">
<wsdlsoap:address location="http://localhost:8080/NutriAdvisorWS/services/MyService"/&gt;
</wsdl:port>
</wsdl:service>
<style/>
</wsdl:definitions>

The problem is, after Igenerate a client for this web service, using the Eclipse wizard, based on axis1, I use the client code like this:

public static void main(String[] args) throws RemoteException {
        MyServiceProxy s = new MyServiceProxy();
        ComplexClass c = s.getSomeData();
        System.out.println("I got: "+ c);
    }

And I get the following Exception:

org.xml.sax.SAXException: Invalid element in example.Children - someValue
    at org.apache.axis.encoding.ser.BeanDeserializer.onStartChild(BeanDeserializer.java:258)
    at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1035)
    at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:165)
    at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:1141)
    at org.apache.axis.message.RPCElement.deserialize(RPCElement.java:236)
    at org.apache.axis.message.RPCElement.getParams(RPCElement.java:384)
    at org.apache.axis.client.Call.invoke(Call.java:2467)
    at org.apache.axis.client.Call.invoke(Call.java:2366)
    at org.apache.axis.client.Call.invoke(Call.java:1812)
    at example.MyServiceSoapBindingStub.getSomeData(MyServiceSoapBindingStub.java:187)
    at example.MyServiceProxy.getSomeData(MyServiceProxy.java:50)
    at TestMyService.main(TestMyService.java:15)

After doing some tests, I narrowed the problem and noticed that this behaviour happens when using nested arrays in a ComplexType returned object. Any idea how fix this?

The output I get when calling the web service 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"&gt;
   <soapenv:Body>
      <getSomeDataResponse xmlns="http://example"&gt;
         <getSomeDataReturn>
            <name>defaultName</name>
            <age>-1</age>
            <myFirstArray>
               <attribute>1</attribute>
               <mySecondArray>
                  <someValue>defaultValue</someValue>
               </mySecondArray>
               <mySecondArray xsi:nil="true"/>
            </myFirstArray>
            <myFirstArray xsi:nil="true"/>
         </getSomeDataReturn>
      </getSomeDataResponse>
   </soapenv:Body>
</soapenv:Envelope>