cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Diana ALLAM <allamdi...@gmail.com>
Subject Re: How the inheritance in java is supported in SOAP and RESTful services by using cxf
Date Fri, 08 Jun 2012 10:28:41 GMT
Hi,

I am using Eclipse J2EE which generate automatically the following wsdl and xsd files (by
using the annotation @XmlSeeAlso):

Here is my XSD  file:
<?xml version="1.0" encoding="utf-8"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://server/" elementFormDefault="unqualified" targetNamespace="http://server/"
version="1.0">
<xs:element name="print" type="tns:print"/>
<xs:element name="printResponse" type="tns:printResponse"/>
<xs:complexType name="print">
    <xs:sequence>
      <xs:element minOccurs="0" name="arg0" type="tns:personne"/>
    </xs:sequence>
  </xs:complexType>
<xs:complexType name="personne">
    <xs:sequence>
      <xs:element minOccurs="0" name="name" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
<xs:complexType name="printResponse">
    <xs:sequence>
      <xs:element minOccurs="0" name="return" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
</xs:schema>


and here is my WSDL file

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="ServiceService" targetNamespace="http://server/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="http://server/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
  <wsdl:types>
    <schema xmlns="http://www.w3.org/2001/XMLSchema">
<import namespace="http://server/" schemaLocation="service_schema1.xsd"/>
</schema>
  </wsdl:types>
  <wsdl:message name="print">
    <wsdl:part name="parameters" element="tns:print">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="printResponse">
    <wsdl:part name="parameters" element="tns:printResponse">
    </wsdl:part>
  </wsdl:message>
  <wsdl:portType name="printEndPoint">
    <wsdl:operation name="print">
      <wsdl:input name="print" message="tns:print">
    </wsdl:input>
      <wsdl:output name="printResponse" message="tns:printResponse">
    </wsdl:output>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="ServiceServiceSoapBinding" type="tns:printEndPoint">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="print">
      <soap:operation soapAction="" style="document"/>
      <wsdl:input name="print">
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output name="printResponse">
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="ServiceService">
    <wsdl:port name="ServicePort" binding="tns:ServiceServiceSoapBinding">
      <soap:address location="http://localhost:8081/zw/services/ServicePort"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>



On 8 juin 2012, at 11:17, Oliver Wulff wrote:

> Hi there
> 
> I've developed services which make use of polymorphism for WSLD/SOAP services and this
works fine.
> 
> Can you attach the generated WSDL?
> 
> You should see that the parameter p is of the abstract schema type Person. The service
consumer must create an object of type Person and pass it to the print operation. On the wire,
the xsi:type attribute is added thus the service provider knows to instantiate an object of
type Student (Person is abstract).
> 
> Thanks
> 
> 
> 
> ------
> 
> Oliver Wulff
> 
> Blog: http://owulff.blogspot.com
> Solution Architect
> http://coders.talend.com
> 
> Talend Application Integration Division http://www.talend.com
> 
> ________________________________________
> From: Diana ALLAM [allamdiana@gmail.com]
> Sent: 07 June 2012 10:59
> To: Daniel Kulp
> Cc: users@cxf.apache.org
> Subject: Re: How the inheritance in java is supported in SOAP and RESTful services by
using cxf
> 
> Hello,
> 
> Using @XmlSeeAlso annotation works only for my Restful example but not for the SOAP one.
> Can I conclude that it is impossible to include Java inheritance in SOAP
> but it is possible for REST?
> 
> 
> Diana
> 
> 
> On 6 juin 2012, at 18:39, Daniel Kulp wrote:
> 
>> 
>> If you add an @XmlSeeAlso annotation that points to the Student class, then
>> JAXB (and thus CXF) can pick up the Student class and it will appear the
>> schema and would properly be transfered on the wire with the appropriate
>> xsi:type attribute.
>> 
>> You can add it to the Person class (so the Person knows about it's
>> subclasses) or you can add it to the Service class
>> 
>> @XmlSeeAlso({Student.class})
>> public class Service  {
>>      public String print(Person p){
>>              return p.info();
>>      }
>> }
>> 
>> And CXF will pick it up.
>> 
>> Dan
>> 
>> 
>> 
>> 
>> On Tuesday, June 05, 2012 08:46:39 AM dallam wrote:
>>> Hello,
>>> 
>>> I have the following simple java Class which I would like to publish as a
>>> web service:
>>> 
>>> --------------------------------------------------------------------------
>>> ------------ public class Service  {
>>> 
>>>     public String print(Person p){
>>>             return p.info();
>>>     }
>>> 
>>> }
>>> --------------------------------------------------------------------------
>>> ------------ I have also two classes, "Person" and its subclass "Student"
>>> which define differently the "info()" method:
>>> --------------------------------------------------------------------------
>>> ---------- public class Person {
>>> 
>>>     private String name;
>>> 
>>>     public Person() {
>>>             this.name = "diana";
>>>     }
>>> 
>>>     public String info(){
>>>             return "this is a person, his name is " + this.name;
>>>     }
>>> 
>>>     public String getName(){
>>>             return this.name;
>>>     }
>>> 
>>>     public void setName(String name){
>>>             this.name = name;
>>>     }
>>> }
>>> --------------------------------------------------------------------------
>>> ---------- public class Student extends Person{
>>> 
>>> private String school;
>>> 
>>>     public Student() {
>>>               super();
>>>             this.school="emn";
>>>     }
>>> 
>>>     public String info(){
>>>             return "this is a student, his name is " + this.getName() + " from
>> the
>>> school of " + this.school;
>>>     }
>>> 
>>>     public String getSchool(){
>>>             return this.school;
>>>     }
>>> 
>>>     public void setSchool(String school){
>>>             this.school = school;
>>>     }
>>> 
>>> }
>>> --------------------------------------------------------------------------
>>> -------------------------------------------
>>> 
>>> The problem is by using jaxws, I didn't find the way to build a client
>>> which would like to call the print service with a student object. Only
>>> "person" objects are accepted.
>>> Is there a way to do that in cxf?
>>> 
>>> The same is for JaxRS by using annotations.
>>> For example, if I have the following post method:
>>> ---------------------------------------------------------
>>> @POST
>>>   @Path("/persons/")
>>>   public Response addPerson(Person p) {  ... }
>>> ---------------------------------------------------------
>>> and I annotated the person class with:
>>> @XmlRootElement(name = "Person")
>>> 
>>> and the Student class which extends Person is annotated with:
>>> @XmlRootElement(name = "Student")
>>> 
>>> 
>>> I can't send to the post method an XML with a "Student" root element
>>> because only "Person" root element is accepted.
>>> 
>>> Is there an inheritance annotation in cxf to solve this problem? if not,
>>> why this issue is not considered
>>> in the implementation of the cxf framework?
>>> 
>>> 
>>> Best regards,
>>> 
>>> Diana
>>> 
>>> 
>>> 
>>> --
>>> View this message in context:
>>> http://cxf.547215.n5.nabble.com/How-the-inheritance-in-java-is-supported-
>>> in-SOAP-and-RESTful-services-by-using-cxf-tp5709127.html Sent from the
>>> cxf-user mailing list archive at Nabble.com.
>> --
>> Daniel Kulp
>> dkulp@apache.org - http://dankulp.com/blog
>> Talend Community Coder - http://coders.talend.com
>> 


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message