There are probably many ways to get this to work.
First, you have the 2D array of objects. How do you expect the object
to be created given a piece of data from XML?
One way, I haven't tried it, but you have to find out what are the
different object types that will have instances go into that array?
Each of those object type can potentially be a problem by itself.
However, just to keep it short, for example, you have this:
Object [] [] data;
and the instances belong to these:
Class A {
int a;
//get/set
}
Class B {
int b;
//get/set
}
A a = new A();
B b = new B();
a and b are passed into that data array. So, to get Axis to be able
to deserialize the data from A and B, it needs to know it's A and B,
obviously. It's not Axis's problem here.
So, you need to tell Axis A and B are web service types.
2 ways to do that. When generate the WSDL, you can declare them, or
add them in the extra classes.
If you can't manage to do that (you need the latest, non-release
version of Axis I believe).
Another way is to create a fake function in addition to existing web
service functions.
void fakeFunction(A a, B b);
Doing that, A and B will be declared and will be serialized properly.
It's best to move away from that Object [][] in the first place.
I would wrap the 2D array into at least 1 D array of 1 D array:
Class DataList {
AList alist;
}
Class AList {
A [] alist;
}
Class A {
}
Good luck.
On Tue, Oct 5, 2010 at 4:37 AM, paul nibin <[email protected]> wrote:
> Hi all,
>
> I am trying to make a web service that uses a complex type object as return
> value. My complex object looks like
>
> public class ComplexBean
> {
> private String[] str;
> private Object[][] val;
>
> public String[] getStr()
> {
> return str;
> }
>
> public void setStr(String[] str)
> {
> this.str = str;
> }
>
> public Object[][] getVal()
> {
> return val;
> }
>
> public void setVal(Object[][] val)
> {
> this.val = val;
> }
> }
>
> I created a service with a method that returns an object of the above type.
> I deployed the service. When I access the wsdl, it shows that the service is
> deployed and the schema in the WSDL looks fine.
>
> <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified"
> targetNamespace="http://ws.apache.org/axis2/xsd">
> <xs:complexType name="ComplexBean">
> <xs:sequence>
> <xs:element maxOccurs="unbounded" minOccurs="0" name="str"
> nillable="true" type="xs:string"/>
> <xs:element maxOccurs="unbounded" minOccurs="0" name="val"
> nillable="true" type="ax21:ArrayOfObject"/>
> </xs:sequence>
> </xs:complexType>
> <xs:complexType name="ArrayOfObject">
> <xs:sequence>
> <xs:element maxOccurs="unbounded" minOccurs="0" name="array"
> nillable="true" type="xs:anyType"/>
> </xs:sequence>
> </xs:complexType>
> </xs:schema>
>
> I generated the client side for the service using WSDL2java tool. I used ADB
> binding for that. I invoked the web method from the client. I could see that
> method is executed and the SOAP response message is sent back to the client.
>
> <?xml version='1.0' encoding='UTF-8'?>
> <soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
> <soapenv:Body>
> <ns:getBeanResponse xmlns:ns="http://test">
> <ns:return xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:ax21="http://test/xsd" xsi:type="ax21:ComplexBean">
> <ax21:str>1</ax21:str>
> <ax21:str>2</ax21:str>
> <ax21:val>
> <ax21:array>1-a</ax21:array>
> <ax21:array>1-b</ax21:array>
> </ax21:val>
> <ax21:val>
> <ax21:array>2-a</ax21:array>
> <ax21:array>2-b</ax21:array>
> </ax21:val>
> </ns:return>
> </ns:getBeanResponse>
> </soapenv:Body>
> </soapenv:Envelope>
>
> But when the client parses the response, it is not able to do it. It fails
> with the following exception message.
>
> Exception in thread "main" org.apache.axis2.AxisFault:
> org.apache.axis2.databinding.ADBException: Any type element type has not
> been given
> at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
> at test.SimpleTestStub.fromOM(SimpleTestStub.java:2463)
> at test.SimpleTestStub.getBean(SimpleTestStub.java:189)
> at test.TestSimpleClient.main(TestSimpleClient.java:12)
> Caused by: java.lang.Exception: org.apache.axis2.databinding.ADBException:
> Any type element type has not been given
> at
> test.SimpleTestStub$ArrayOfObject$Factory.parse(SimpleTestStub.java:2411)
> at
> test.SimpleTestStub$ComplexBean$Factory.parse(SimpleTestStub.java:1729)
> at
> test.SimpleTestStub$GetBeanResponse$Factory.parse(SimpleTestStub.java:870)
> at test.SimpleTestStub.fromOM(SimpleTestStub.java:2457)
> ... 2 more
> Caused by: org.apache.axis2.databinding.ADBException: Any type element type
> has not been given
> at
> org.apache.axis2.databinding.utils.ConverterUtil.getAnyTypeObject(ConverterUtil.java:1617)
> at
> test.SimpleTestStub$ArrayOfObject$Factory.parse(SimpleTestStub.java:2375)
> ... 5 more
>
> I debugged the client side and found that, the code is expecting a mandatory
> "type" attribute. But in the response returned from the server, the "type"
> attribute is not present and hence the parsing fails.
>
> Is there any workaround for this problem? If you could point me in some
> direction, it will be greatly helpful. If you need any more information, I
> could provide those.
>
> Thanks in advance and hoping for a response.
>
> Thanks & Regards,
> Paul
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]