Dear JBoss developers,
I spent several days to solve the problem of polymorphism in JBoss WebService, but
failed.
I googled many articles, Only
"http://forums.sun.com/thread.jspa?threadID=5225941" is usefull to me. But it
just does NOT work!!
Please help me. Great Thanks to any tips.
My envirionment:
jboss-5.1.0.GA-jdk6.
jdk1.6.0_14_Windows
Eclipse 3.2
My code:
Server:
--------------------------------------------------------------------------------------------------------------------
package com.ybxiang.ejbws;
import javax.xml.bind.annotation.XmlSeeAlso;
@XmlSeeAlso({Human.class})
public class Animal implements java.io.Serializable{
private String name;
private Long age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Long getAge() {
return age;
}
public void setAge(Long age) {
this.age = age;
}
public String toString(){
return "Animal-->name:"+this.getName()+",age:"+this.getAge();
}
}
------------------------
package com.ybxiang.ejbws;
public class Human extends Animal implements java.io.Serializable{
private String email;
public void setEmail(String email) {
this.email = email;
}
public String getEmail() {
return email;
}
public String toString(){
return
"Human-->name:"+this.getName()+",age:"+this.getAge()+","+"email:"+email;
}
}
------------------------
package com.ybxiang.ejbws;
import java.util.ArrayList;
import java.util.Iterator;
import javax.jws.WebMethod;
public interface EJBWebServiceInterface {
public void passParameter1(String s);
public void passParameter2(Animal a);
public void passParameter3(Human h);
public void passParameter4(ArrayList lst);
public ArrayList<? extends Animal> returnSomething1(int type);
}
------------------------
package com.ybxiang.ejbws;
import java.util.ArrayList;
import java.util.Iterator;
import javax.ejb.Stateless;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.jws.soap.SOAPBinding;
@Stateless
@WebService
//(a)**XmlSeeAlso({Animal.class, Human.class})
public class EJBWebServiceBean implements EJBWebServiceInterface{
@WebMethod
public void passParameter1(String s){
System.out.println("------------String is got:"+s);
}
@WebMethod
public void passParameter2(Animal a){
System.out.println("------------Animal is got:"+a);
if(a instanceof Human){
System.out.println("************* It's realy human!!! *************");
}
}
@WebMethod
public void passParameter3(Human h){
System.out.println("------------Human is got, name:"+h.getName()+",
email:"+h.getEmail());
}
@WebMethod
public void passParameter4(ArrayList lst){
System.out.println("------------ArrayList is got:");
if(lst!=null){
Iterator it = lst.iterator();
Animal a = it.next();
if(a instanceof Human){
System.out.println("One human is got:"+((Human)a));
}else{
System.out.println("One Animal is got:"+a);
}
}else{
System.out.println("------------List is null.");
}
}
@WebMethod
public ArrayList<? extends Animal> returnSomething1(int type){
if(type==1){
ArrayList aa = new ArrayList();
{
Animal animal1 = new Animal();
animal1.setName("Animal.1");
animal1.setAge(new Long(1));
aa.add(animal1);
}
{
Animal animal2 = new Animal();
animal2.setName("Animal.2");
animal2.setAge(new Long(2));
aa.add(animal2);
}
return aa;
}else{
ArrayList bb = new ArrayList();
{
Human human1 = new Human();
human1.setName("Human.1");
human1.setAge(new Long(1));
bb.add(human1);
}
{
Human human2 = new Human();
human2.setName("Human.2");
human2.setAge(new Long(2));
bb.add(human2);
}
return bb;
}
}
}
View the original post :
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4263889#...
Reply to the post :
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&a...