[jboss-user] [JBossWS] - Inheritance problem

pio1k do-not-reply at jboss.com
Tue Jul 21 04:04:27 EDT 2009


Hello.

I have a problem with class inheritance in web services. I want to make a web service with one method to add objects of classes (B, C and other in the future) which inheritated from my basic class (A). My source code:

Server side:
1) TestService.java
@WebService(serviceName = "TestService")
  | @Stateless
  | @XmlSeeAlso({B.class, C.class})
  | public class TestService {
  |     @EJB
  |     TestMgmtLocal             tl  = null;
  |     
  |     @WebMethod(operationName = "testAddA")  
  |     public @WebResult(name = "A")  
  |     A testAddA(@WebParam(name = "testA") A testA) {
  |         return tl.testAddA(testA);
  |     }
  | }

2) TestMgmtLocal.java
@Local
  | public interface TestMgmtLocal extends TestMgmtRemote {
  |  
  | }

3) TestMgmtRemote.java
@Remote
  | public interface TestMgmtRemote {
  |     A testAddA(A testA);
  | }

4) TestMgmt.java
@Stateless
  | public class TestMgmt implements TestMgmtLocal {
  |     @Resource
  |     private SessionContext ctx = null;
  |     
  |     public A testAddA(A testA) {
  |         if (testA instanceof A) {
  |             System.out.println("class A");
  |         }
  |         
  |         if (testA instanceof B) {
  |             System.out.println("class B");
  |         }
  |         
  |         if (testA instanceof C) {
  |             System.out.println("class C");
  |         }
  |         
  |         return testA;
  |     }
  | }

5) A.java
public class A implements Serializable {
  |  
  |     private static final long serialVersionUID = 110181269433550832L;
  |  
  |     private int a = -1;
  |  
  |     public int getA() {
  |         return a;
  |     }
  |  
  |     public void setA(int a) {
  |         this.a = a;
  |     }
  | }

6) B.java
public class B extends A implements Serializable {
  |  
  |     private static final long serialVersionUID = 6921792702940813727L;
  |  
  |     private int b = -1;
  |  
  |     public int getB() {
  |         return b;
  |     }
  |  
  |     public void setB(int b) {
  |         this.b = b;
  |     }
  | }

7) C.java
public class C extends A implements Serializable {
  |  
  |     private static final long serialVersionUID = 7823155353151239133L;
  |  
  |     private int c = -1;
  |  
  |     public int getC() {
  |         return c;
  |     }
  |  
  |     public void setC(int c) {
  |         this.c = c;
  |     }
  | }

Client side:
1) TestClient.java
public class TestClient {
  |  
  | 	public static void main(String[] args) {
  | 		TestServiceProxy proxy = new TestServiceProxy();
  | 		TestService_PortType port = proxy.getTestService_PortType();
  | 		try {
  | 			C c = new C();
  | 			c.setA(2);
  | 			c.setC(3);
  | 			port.testAddA(c);
  | 		} catch(RemoteException e) {
  | 			System.out.println(e);
  | 		}
  | 	}
  | }


I found this page:
http://blog.vinodsingh.com/2008/09/anytype-object-over-webservice-and.html
but it doesn't work in my web service. In testAddA method I always get an object of A class (when I send from client object of B or C class). I've also tried to add @XmlSeeAlso annotation to A class but it doesn't help. Maybe I did something wrong? Any ideas? Any other solutions of this problem?

I'm using:
1) JBoss 4.2.3GA (I tired also on JBoss 5.1.GA)
2) Java 1.5 update 15 

View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4244837#4244837

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4244837



More information about the jboss-user mailing list