Hi,

thank you for these details.
when you write:
"props.put("jaxb.additionalContextClasses",
new Class[] {java.rmi.Remote.class, java.rmi.RemoteException.class})", does it 
mean we can do in SOAP/REST services the same things like in RMI?
Is it mandatory to declare the rmi class as a new context for jaxb to allow 
services to support java inheritance?

regards,

Diana


On 8 juin 2012, at 04:25, Freeman Fang wrote:

> Hi,
> 
> @XmlSeeAlso should also work for jaxws soap, as it's underlying jaxb thing.
> 
> Anyway, besides the @XmlSeeAlso annotation way, cxf support adding extra 
> classes to jaxb context through jaxb.additionalContextClasses property.
> Some code for server side like
> 
> ServerFactoryBean svrBean = new ServerFactoryBean();
> svrBean.setAddress("http://localhost/Hello";);
> svrBean.setServiceClass(HelloService.class);
> svrBean.setBus(getBus());
> 
> Map props = svrBean.getProperties();
> if (props == null) { props = new HashMap<String, Object>(); }
> props.put("jaxb.additionalContextClasses",
> new Class[] {java.rmi.Remote.class, java.rmi.RemoteException.class});// you 
> can add your Student class here
> svrBean.setProperties(props);
> svrBean.create();
> 
> 
> Also almost the same thing on client side
> 
> ClientFactoryBean cfBean = new ClientFactoryBean();
> cfBean.setAddress("http://localhost/Hello";);
> cfBean.setBus(getBus());
> cfBean.setServiceClass(HelloService.class);
> Map props = cfBean.getProperties();
> if (props == null) { props = new HashMap<String, Object>(); } }
> props.put("jaxb.additionalContextClasses",
> new Class[] {java.rmi.Remote.class, java.rmi.RemoteException.class});// you 
> can add your Student class here
> cfBean.setProperties(props);
> Client client = cfBean.create();
> 
> HTH
> 
> Freeman
> 
> 
> 
> On 2012-6-8, at 上午2:19, Diana ALLAM wrote:
> 
>> After testing @XmlSeeAlso, I can include Java inheritance to only RESTful 
>> services
>> but for SOAP it doesn't change anything, the generated xsd is the same and 
>> student objects
>> are treated as Person objects on the server.
>> So there is some limitations of the use of this annotation in cxf.
>> 
>> On 7 juin 2012, at 20:15, Glen Mazza wrote:
>> 
>>> Dan knows more than I on this point (as well as many others :)--sorry if 
>>> the information I had given was in error.
>>> 
>>> Glen
>>> 
>>> On 06/06/2012 06:29 PM, Diana ALLAM wrote:
>>>> Hello,
>>>> 
>>>> Thank you for your reply.
>>>> I tried to use @XmlSeeAlso annotation as you mentioned but it doesn't work 
>>>> as I would like.
>>>> I get also a response for my question from Gen Mazza who said there is not 
>>>> a way to do that and
>>>> the only thing going over the wire would be a Person XML object (even if 
>>>> it is a subclass of it).
>>>> 
>>>> 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
>>>>> [email protected] - http://dankulp.com/blog
>>>>> Talend Community Coder - http://coders.talend.com
>>>>> 
>>> 
>>> 
>>> -- 
>>> Glen Mazza
>>> Talend Community Coders
>>> coders.talend.com
>>> blog: www.jroller.com/gmazza
>>> 
>> 
> 
> ---------------------------------------------
> Freeman Fang
> 
> FuseSource
> Email:[email protected]
> Web: fusesource.com
> Twitter: freemanfang
> Blog: http://freemanfang.blogspot.com
> http://blog.sina.com.cn/u/1473905042
> weibo: http://weibo.com/u/1473905042
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 

Reply via email to