[jboss-user] [EJB 3.0 Users] - Problem of polymorphism Web Service in EJB
xiangyingbing
do-not-reply at jboss.com
Thu Nov 5 20:27:29 EST 2009
Dear friends,
I can use pure polymorphism Web Service in Glassfish and JBoss correctly.
But, after annotated with @Stateless, my codes does NOT work.
Namely, i can not make my code work in EJB3 environment.
My environment:
JDK, lates.
jboss-5.1.0.GA-jdk6
Windows XP.
My java files:
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<Animal> 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
| //@**XmlSeeAlso({Animal.class, Human.class})// Here i tried too!
| 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<Animal> lst){
| System.out.println("------------ArrayList<Animal> is got:");
| if(lst!=null){
| Iterator<Animal> 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<Animal> aa = new ArrayList<Animal>();
| {
| 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<Human> bb = new ArrayList<Human>();
| {
| 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=4264248#4264248
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4264248
More information about the jboss-user
mailing list