cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Glen Mazza <gma...@talend.com>
Subject Re: How the inheritance in java is supported in SOAP and RESTful services by using cxf
Date Tue, 05 Jun 2012 20:39:36 GMT
In the SOAP case the only thing going over the wire would be a Person 
XML object (even if it is a subclass of it), so when the web service 
provider receives the object it can only unmarshal it to a Person Java 
object.  (There's no Java on the wire and hence no inheritance, SOAP 
services can be implemented in many languages, not all of which have 
inheritance).

A more "SOAPy" way of designing your POJO would be to put in a 
flag/field in your Person object indicating the type of Person, then 
have your business logic implement info() depending on the type of 
Person.  (if you can't alter Person than subclass Person and alter it, 
and change your SOAP web service to use you subclass instead of Person).

On the other hand, you should be able to call the web service provider 
with a subclass of Person (even though again it will act like a Person 
when it gets to the WSP).  For example, in my SOAP client tutorial 
(http://www.jroller.com/gmazza/entry/soap_client_tutorial) you should be 
able to subclass FindPopularItemsRequestType and use that subclass when 
making calls.

Glen


On 06/05/2012 11:46 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.


-- 
Glen Mazza
Talend Community Coders
coders.talend.com
blog: www.jroller.com/gmazza


Mime
View raw message