You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Sathija Pavuluri <sp...@EmprisaNetworks.com> on 2007/01/24 23:56:55 UTC

[Axis2] Serialization of super class elements

Hello,

I was surprised by what I found recently while trying to serialize an object along with its super class' fields.

TheParent {
    a;
    b;
}

TheChild {
    c;
    d;
}

My service class returns an object of TheChild. The generated wsdl defined the complex type TheChild with elements
a,b,c,d.
Now, when I invoked the web service and inspected the response, a and b (which are from the parent) are totally
missing in the response.
Looks like the super class fields are not being serialized.
I thought (wishfully expected) axis would handle class hierarchy. Its not to be so.
If the serializer didnt handle this, the generated wsdl probably should not generate a single complex type because it
is misleading.

Is there a different approach to this or am I off track?
I would hate for the client to have to invoke multiple service calls for each object and put them together to achieve
the desired result.

Thanks,
Sathija.




---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: [Axis2] Serialization of super class elements

Posted by Sathija Pavuluri <sp...@EmprisaNetworks.com>.
Amila,

In response to my own post below that I sent earlier today, I'd like to update with some more findings I've made
during the day.
As stated in my prev. email our architecture was using code first approach. So I have my service and the hierarchical
data classes already defined. From these I generate the wsdl which compresses the fields from the parent and child
classes together into the child classes.
>From the wsdl below, see this

>         <xs:element name="PremierCustomerDTO" type="ns0:PremierCustomerDTO"/>
>             <xs:complexType name="PremierCustomerDTO">
>                 <xs:sequence>
>                     <xs:element name="address" nillable="true" type="xs:string"/>
>                     <xs:element name="name" nillable="true" type="xs:string"/>
>                     <xs:element name="phone" nillable="true" type="xs:string"/>
>                     <xs:element name="clubName" nillable="true" type="xs:string"/>
>                     <xs:element name="vipNumber" nillable="true" type="xs:string"/>
>                 </xs:sequence>
>             </xs:complexType>
>         </xs:schema>

But when the service call is made from the client, since PremierCustomerDTO bean has only clubName, vipNumber fields,
only these are returned in the response.

I ran further tests, by instead generating the server code using the (already generated) wsdl, sort of reverse
engineering it.
What I then saw was the generated PremierCustomerDTO bean defined clubName, vipNumber and also address,name,phone from
its super class. that makes sense because the wsdl makes no such distinction.
When I create the aar out of these generated server classes, everything actually worked, except my hierarchy is now
flattened out.

So the problem now narrows down to class hierarchy not being preserved when the wsdl is generated from service class.
The java 2 wsdl generator is incorrectly flattening my beans.

I am eager to hear your comments and suggestions. Is this something that can be fixed?

Thanks!
Sathija.






> Amila,
>
> Posted below are the service implementation classes, the soap response and wsdl.
>
> I have taken the code first approach so I coded the service classes first,
> and generated the wsdl from the service class.
>
> As you will see in the generated wsdl, the child class is described along with the parent's fields as well,
> but strangely the response is missing those.
> The data objects are well formed java bean with public getters/setters.
> Is the serializer using reflection on the child where it is somehow skipping the parent's fields?
> Could this be a serializer bug?
>
> **************************************************************************
> public class CustomerService {
>     public PremierCustomerDTO[] getPremierCustomers() throws AxisFault {
>         PremierCustomerDTO pc = new PremierCustomerDTO();
>         pc.setName("nametest");
>         pc.setAddress("addrtest");
>         pc.setPhone("545-454-5434");
>         pc.setVipNumber("xyz");
>         pc.setClubName("ToastMasters");
>         PremierCustomerDTO[] pcs = new PremierCustomerDTO[]{pc};
>         return pcs;
>     }
> }
>
> public class CustomerDTO {
>     private String name;
>     private String phone;
>     private String address;
> // public getters and setters .
> }
>
> public class PremierCustomerDTO extends CustomerDTO {
>     private String clubName;
>     private String vipNumber;
> // public getters and setters .
> }
> **************************************************************************
>
> <?xml version='1.0' encoding='UTF-8'?>
> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
> <soapenv:Header />
> <soapenv:Body>
> <ns:getPremierCustomersResponse xmlns:ns="http://service.ws.xyz.abc.com/xsd">
> <ns:return>
> <clubName xmlns="http://service.ws.ena.emprisa.com/xsd">ToastMasters</clubName>
> <vipNumber xmlns="http://service.ws.ena.emprisa.com/xsd">xyz</vipNumber>
> </ns:return>
> </ns:getPremierCustomersResponse>
> </soapenv:Body>
> </soapenv:Envelope>
>
> **************************************************************************
> <wsdl:definitions targetNamespace="http://service.ws.xyz.abc.com">
>     <wsdl:documentation>
>         Service class used to retrieve and update device component.
>     </wsdl:documentation>
>     <wsdl:types>
>         <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified"
> targetNamespace="http://service.ws.xyz.abc.com/xsd">
>             <xs:element name="getPremierCustomersFault">
>             <xs:complexType>
>                 <xs:sequence>
>                      <xs:element name="getPremierCustomersFault" type="xs:anyType"/>
>                 </xs:sequence>
>             </xs:complexType>
>         </xs:element>
>         <xs:element name="getPremierCustomersResponse">
>             <xs:complexType>
>                 <xs:sequence>
>                     <xs:element maxOccurs="unbounded" name="return" nillable="true" type="ns0:PremierCustomerDTO"/>
>                 </xs:sequence>
>             </xs:complexType>
>         </xs:element>
>         <xs:element name="PremierCustomerDTO" type="ns0:PremierCustomerDTO"/>
>             <xs:complexType name="PremierCustomerDTO">
>                 <xs:sequence>
>                     <xs:element name="address" nillable="true" type="xs:string"/>
>                     <xs:element name="name" nillable="true" type="xs:string"/>
>                     <xs:element name="phone" nillable="true" type="xs:string"/>
>                     <xs:element name="clubName" nillable="true" type="xs:string"/>
>                     <xs:element name="vipNumber" nillable="true" type="xs:string"/>
>                 </xs:sequence>
>             </xs:complexType>
>         </xs:schema>
>     </wsdl:types>
> <wsdl:message name="getPremierCustomersMessage"/>
>     <wsdl:message name="getPremierCustomersResponse">
>     <wsdl:part name="part1" element="ns0:getPremierCustomersResponse"/>
> </wsdl:message>
> <wsdl:message name="getPremierCustomersFault">
>     <wsdl:part name="part1" element="ns0:getPremierCustomersFault"/>
> </wsdl:message>
> <wsdl:portType name="CustomerServicePortType">
> <wsdl:operation name="getPremierCustomers">
>     <wsdl:input message="axis2:getPremierCustomersMessage" wsaw:Action="urn:getPremierCustomers"/>
>     <wsdl:output message="axis2:getPremierCustomersResponse"/>
> <wsdl:fault message="axis2:getPremierCustomersFault" name="getPremierCustomersFault"/>
> </wsdl:operation>
> </wsdl:portType>
> <wsdl:binding name="CustomerServiceSOAP11Binding" type="axis2:CustomerServicePortType">
> <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
> <wsdl:operation name="getPremierCustomers">
>     <soap:operation soapAction="urn:getPremierCustomers" style="document"/>
>     <wsdl:input>
>         <soap:body use="literal"/>
>     </wsdl:input>
>     <wsdl:output>
>         <soap:body use="literal"/>
>     </wsdl:output>
>     <wsdl:fault name="getPremierCustomersFault">
>         <soap:body use="literal"/>
>     </wsdl:fault>
> </wsdl:operation>
> </wsdl:binding>
> <wsdl:binding name="CustomerServiceSOAP12Binding" type="axis2:CustomerServicePortType">
> <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
> <wsdl:operation name="getPremierCustomers">
>     <soap12:operation soapAction="urn:getPremierCustomers" style="document"/>
>     <wsdl:input>
>         <soap12:body use="literal"/>
>     </wsdl:input>
>     <wsdl:output>
>         <soap12:body use="literal"/>
>     </wsdl:output>
>     <wsdl:fault name="getPremierCustomersFault">
>         <soap12:fault use="literal" name="getPremierCustomersFault"/>
>     </wsdl:fault>
> </wsdl:operation>
> </wsdl:binding>
> <wsdl:binding name="CustomerServiceHttpBinding" type="axis2:CustomerServicePortType">
> <http:binding verb="POST"/>
> <wsdl:operation name="getPremierCustomers">
>     <http:operation location="getPremierCustomers"/>
>     <wsdl:input>
>         <mime:content type="text/xml"/>
>     </wsdl:input>
>     <wsdl:output>
>         <mime:content type="text/xml"/>
>     </wsdl:output>
> </wsdl:operation>
> </wsdl:binding>
> <wsdl:service name="CustomerService">
>     <wsdl:port name="CustomerServiceSOAP11port_http" binding="axis2:CustomerServiceSOAP11Binding">
>         <soap:address location="http://s-pavuluri-02:8080/enetaware/services/CustomerService"/>
>     </wsdl:port>
>     <wsdl:port name="CustomerServiceSOAP12port_http" binding="axis2:CustomerServiceSOAP12Binding">
>         <soap12:address location="http://s-pavuluri-02:8080/enetaware/services/CustomerService"/>
>     </wsdl:port>
> </wsdl:service>
> </wsdl:definitions>
>
> **************************************************************************
>
> Thanks!
>
>
>
>
>> On 1/25/07, Sathija Pavuluri <sp...@emprisanetworks.com> wrote:
>>>
>>> Sanjiva,
>>>
>>> The code has been generated from wsdl. I think the problem is not with
>>> generated code.
>>
>>
>> Sometimes it may not  serialize the child object correctly. Can you send you
>> wsdl?
>>
>> The soap response itself does not look right.
>>> It is missing some elements which are defined in the wsdl. Specifically,
>>> these are the elements from the super class
>>> of the object that the service is returning.
>>>
>>> I am not sure if this is a bug or my approach is incorrect.
>>> Is there anything different I need to do so that the super class elements
>>> are serialized when its child class element
>>> is being sent in the response?
>>>
>>> Thanks,
>>> Sathija.
>>>
>>>
>>>
>>
>>
>> --
>> Amila Suriarachchi,
>> WSO2 Inc.
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: [Axis2] Serialization of super class elements

Posted by Sathija Pavuluri <sp...@EmprisaNetworks.com>.
Amila,

Posted below are the service implementation classes, the soap response and wsdl.

I have taken the code first approach so I coded the service classes first,
and generated the wsdl from the service class.

As you will see in the generated wsdl, the child class is described along with the parent's fields as well,
but strangely the response is missing those.
The data objects are well formed java bean with public getters/setters.
Is the serializer using reflection on the child where it is somehow skipping the parent's fields?
Could this be a serializer bug?

**************************************************************************
public class CustomerService {
    public PremierCustomerDTO[] getPremierCustomers() throws AxisFault {
        PremierCustomerDTO pc = new PremierCustomerDTO();
        pc.setName("nametest");
        pc.setAddress("addrtest");
        pc.setPhone("545-454-5434");
        pc.setVipNumber("xyz");
        pc.setClubName("ToastMasters");
        PremierCustomerDTO[] pcs = new PremierCustomerDTO[]{pc};
        return pcs;
    }
}

public class CustomerDTO {
    private String name;
    private String phone;
    private String address;
// public getters and setters .
}

public class PremierCustomerDTO extends CustomerDTO {
    private String clubName;
    private String vipNumber;
// public getters and setters .
}
**************************************************************************

<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header />
<soapenv:Body>
<ns:getPremierCustomersResponse xmlns:ns="http://service.ws.xyz.abc.com/xsd">
<ns:return>
<clubName xmlns="http://service.ws.ena.emprisa.com/xsd">ToastMasters</clubName>
<vipNumber xmlns="http://service.ws.ena.emprisa.com/xsd">xyz</vipNumber>
</ns:return>
</ns:getPremierCustomersResponse>
</soapenv:Body>
</soapenv:Envelope>

**************************************************************************
<wsdl:definitions targetNamespace="http://service.ws.xyz.abc.com">
    <wsdl:documentation>
        Service class used to retrieve and update device component.
    </wsdl:documentation>
    <wsdl:types>
        <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified"
targetNamespace="http://service.ws.xyz.abc.com/xsd">
            <xs:element name="getPremierCustomersFault">
            <xs:complexType>
                <xs:sequence>
                     <xs:element name="getPremierCustomersFault" type="xs:anyType"/>
                </xs:sequence>
            </xs:complexType>
        </xs:element>
        <xs:element name="getPremierCustomersResponse">
            <xs:complexType>
                <xs:sequence>
                    <xs:element maxOccurs="unbounded" name="return" nillable="true" type="ns0:PremierCustomerDTO"/>
                </xs:sequence>
            </xs:complexType>
        </xs:element>
        <xs:element name="PremierCustomerDTO" type="ns0:PremierCustomerDTO"/>
            <xs:complexType name="PremierCustomerDTO">
                <xs:sequence>
                    <xs:element name="address" nillable="true" type="xs:string"/>
                    <xs:element name="name" nillable="true" type="xs:string"/>
                    <xs:element name="phone" nillable="true" type="xs:string"/>
                    <xs:element name="clubName" nillable="true" type="xs:string"/>
                    <xs:element name="vipNumber" nillable="true" type="xs:string"/>
                </xs:sequence>
            </xs:complexType>
        </xs:schema>
    </wsdl:types>
<wsdl:message name="getPremierCustomersMessage"/>
    <wsdl:message name="getPremierCustomersResponse">
    <wsdl:part name="part1" element="ns0:getPremierCustomersResponse"/>
</wsdl:message>
<wsdl:message name="getPremierCustomersFault">
    <wsdl:part name="part1" element="ns0:getPremierCustomersFault"/>
</wsdl:message>
<wsdl:portType name="CustomerServicePortType">
<wsdl:operation name="getPremierCustomers">
    <wsdl:input message="axis2:getPremierCustomersMessage" wsaw:Action="urn:getPremierCustomers"/>
    <wsdl:output message="axis2:getPremierCustomersResponse"/>
<wsdl:fault message="axis2:getPremierCustomersFault" name="getPremierCustomersFault"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="CustomerServiceSOAP11Binding" type="axis2:CustomerServicePortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="getPremierCustomers">
    <soap:operation soapAction="urn:getPremierCustomers" style="document"/>
    <wsdl:input>
        <soap:body use="literal"/>
    </wsdl:input>
    <wsdl:output>
        <soap:body use="literal"/>
    </wsdl:output>
    <wsdl:fault name="getPremierCustomersFault">
        <soap:body use="literal"/>
    </wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="CustomerServiceSOAP12Binding" type="axis2:CustomerServicePortType">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="getPremierCustomers">
    <soap12:operation soapAction="urn:getPremierCustomers" style="document"/>
    <wsdl:input>
        <soap12:body use="literal"/>
    </wsdl:input>
    <wsdl:output>
        <soap12:body use="literal"/>
    </wsdl:output>
    <wsdl:fault name="getPremierCustomersFault">
        <soap12:fault use="literal" name="getPremierCustomersFault"/>
    </wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="CustomerServiceHttpBinding" type="axis2:CustomerServicePortType">
<http:binding verb="POST"/>
<wsdl:operation name="getPremierCustomers">
    <http:operation location="getPremierCustomers"/>
    <wsdl:input>
        <mime:content type="text/xml"/>
    </wsdl:input>
    <wsdl:output>
        <mime:content type="text/xml"/>
    </wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="CustomerService">
    <wsdl:port name="CustomerServiceSOAP11port_http" binding="axis2:CustomerServiceSOAP11Binding">
        <soap:address location="http://s-pavuluri-02:8080/enetaware/services/CustomerService"/>
    </wsdl:port>
    <wsdl:port name="CustomerServiceSOAP12port_http" binding="axis2:CustomerServiceSOAP12Binding">
        <soap12:address location="http://s-pavuluri-02:8080/enetaware/services/CustomerService"/>
    </wsdl:port>
</wsdl:service>
</wsdl:definitions>

**************************************************************************

Thanks!




> On 1/25/07, Sathija Pavuluri <sp...@emprisanetworks.com> wrote:
>>
>> Sanjiva,
>>
>> The code has been generated from wsdl. I think the problem is not with
>> generated code.
>
>
> Sometimes it may not  serialize the child object correctly. Can you send you
> wsdl?
>
> The soap response itself does not look right.
>> It is missing some elements which are defined in the wsdl. Specifically,
>> these are the elements from the super class
>> of the object that the service is returning.
>>
>> I am not sure if this is a bug or my approach is incorrect.
>> Is there anything different I need to do so that the super class elements
>> are serialized when its child class element
>> is being sent in the response?
>>
>> Thanks,
>> Sathija.
>>
>>
>>
>
>
> --
> Amila Suriarachchi,
> WSO2 Inc.
>



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: [Axis2] Serialization of super class elements

Posted by Amila Suriarachchi <am...@gmail.com>.
On 1/25/07, Sathija Pavuluri <sp...@emprisanetworks.com> wrote:
>
> Sanjiva,
>
> The code has been generated from wsdl. I think the problem is not with
> generated code.


Sometimes it may not  serialize the child object correctly. Can you send you
wsdl?

The soap response itself does not look right.
> It is missing some elements which are defined in the wsdl. Specifically,
> these are the elements from the super class
> of the object that the service is returning.
>
> I am not sure if this is a bug or my approach is incorrect.
> Is there anything different I need to do so that the super class elements
> are serialized when its child class element
> is being sent in the response?
>
> Thanks,
> Sathija.
>
>
>


-- 
Amila Suriarachchi,
WSO2 Inc.

Re: [Axis2] Serialization of super class elements

Posted by Sathija Pavuluri <sp...@EmprisaNetworks.com>.
Sanjiva,

The code has been generated from wsdl. I think the problem is not with generated code.
The soap response itself does not look right.
It is missing some elements which are defined in the wsdl. Specifically, these are the elements from the super class
of the object that the service is returning.

I am not sure if this is a bug or my approach is incorrect.
Is there anything different I need to do so that the super class elements are serialized when its child class element
is being sent in the response?

Thanks,
Sathija.




> This seems like a bug .. did you generate code from a WSDL and is the
> generated code not working? Or is it for a POJO service?
>
> Please give more info and file a bug so this can be fixed for the next
> release.
>
> Thanks,
>
> Sanjiva.
>
> On Wed, 2007-01-24 at 17:56 -0500, Sathija Pavuluri wrote:
>> Hello,
>>
>> I was surprised by what I found recently while trying to serialize an object along with its super class' fields.
>>
>> TheParent {
>>     a;
>>     b;
>> }
>>
>> TheChild {
>>     c;
>>     d;
>> }
>>
>> My service class returns an object of TheChild. The generated wsdl defined the complex type TheChild with elements
>> a,b,c,d.
>> Now, when I invoked the web service and inspected the response, a and b (which are from the parent) are totally
>> missing in the response.
>> Looks like the super class fields are not being serialized.
>> I thought (wishfully expected) axis would handle class hierarchy. Its not to be so.
>> If the serializer didnt handle this, the generated wsdl probably should not generate a single complex type because
>> it
>> is misleading.
>>
>> Is there a different approach to this or am I off track?
>> I would hate for the client to have to invoke multiple service calls for each object and put them together to
>> achieve
>> the desired result.
>>
>> Thanks,
>> Sathija.
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
>> For additional commands, e-mail: axis-user-help@ws.apache.org
>>
> --
> Sanjiva Weerawarana, Ph.D.
> Founder & Director; Lanka Software Foundation; http://www.opensource.lk/
> Founder, Chairman & CEO; WSO2, Inc.; http://www.wso2.com/
> Director; Open Source Initiative; http://www.opensource.org/
> Member; Apache Software Foundation; http://www.apache.org/
> Visiting Lecturer; University of Moratuwa; http://www.cse.mrt.ac.lk/
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: [Axis2] Serialization of super class elements

Posted by Sanjiva Weerawarana <sa...@opensource.lk>.
This seems like a bug .. did you generate code from a WSDL and is the
generated code not working? Or is it for a POJO service?

Please give more info and file a bug so this can be fixed for the next
release.

Thanks,

Sanjiva.

On Wed, 2007-01-24 at 17:56 -0500, Sathija Pavuluri wrote:
> Hello,
> 
> I was surprised by what I found recently while trying to serialize an object along with its super class' fields.
> 
> TheParent {
>     a;
>     b;
> }
> 
> TheChild {
>     c;
>     d;
> }
> 
> My service class returns an object of TheChild. The generated wsdl defined the complex type TheChild with elements
> a,b,c,d.
> Now, when I invoked the web service and inspected the response, a and b (which are from the parent) are totally
> missing in the response.
> Looks like the super class fields are not being serialized.
> I thought (wishfully expected) axis would handle class hierarchy. Its not to be so.
> If the serializer didnt handle this, the generated wsdl probably should not generate a single complex type because it
> is misleading.
> 
> Is there a different approach to this or am I off track?
> I would hate for the client to have to invoke multiple service calls for each object and put them together to achieve
> the desired result.
> 
> Thanks,
> Sathija.
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
> 
-- 
Sanjiva Weerawarana, Ph.D.
Founder & Director; Lanka Software Foundation; http://www.opensource.lk/
Founder, Chairman & CEO; WSO2, Inc.; http://www.wso2.com/
Director; Open Source Initiative; http://www.opensource.org/
Member; Apache Software Foundation; http://www.apache.org/
Visiting Lecturer; University of Moratuwa; http://www.cse.mrt.ac.lk/


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org