5 Replies Latest reply on Mar 27, 2009 3:01 PM by asoldano

    Problem with inheritance - JbossWS

    fghj5678

      I have problem to get inheritance in a WS to work.
      I've tried a small example on these env:
      Windows XP SP2
      Jboss AS 4.2.2 GA , 4.2.3 (and also JBoss eap 4.3)

      I'm trying to do a request to server with a parameter that contains a inherited class. Class testEnv contains class testAAA, and class testBBB inherits testAAA. So when I put testBBB in testEnv and sends it to the WS I'm supposed to get testBBB from testEnv on the server - but I only get a testAAA!

      Classes used in my example:

      @WebService
      public interface TestWS {
      
       public String test(TestEnv testEnv);
      }
      
      
      @Stateless
      @WebService(name = "TestWSService", serviceName = "TestWSService")
      @Remote(TestWS.class)
      public class TestWSImpl implements TestWS {
      
       public String test(TestEnv testEnv) {
       if (testEnv.getTestAAA() instanceof TestAAA) {
       return "WRONG, should not end up here";
       } else if (testEnv.getTestAAA() instanceof TestBBB) {
       return "CORRECT";
       }
       return "ERROR..";
       }
      
      
      public class TestEnv implements Serializable {
      
       private static final long serialVersionUID = 1L;
      
       TestAAA testAAA;
      
       public TestAAA getTestAAA() {
       return testAAA;
       }
      
       public void setTestAAA(TestAAA testAAA) {
       this.testAAA = testAAA;
       }
      }
      
      @XmlSeeAlso({TestBBB.class})
      public class TestAAA implements Serializable {
      
       private static final long serialVersionUID = 1L;
      
       int a = 1;
      }
      
      public class TestBBB extends TestAAA implements Serializable {
      
       private static final long serialVersionUID = 1L;
      
       int b = 2;
      }
      
      


      Then I've tried both with SoupUI and a generated ws-client - but I always get a testAAA instead of testBBB. example from ws-client:
      ...
      TestWSService testWS = ts.getTestWSServicePort();
      TestBBB testBBB = new TestBBB();
      TestEnv testEnv = new TestEnv();
      testEnv.setTestAAA(testBBB);
      String s = testWS.test(testEnv);
      ...
      


      I also have logged the http soap request and it looks ok (with xsi:type for the inherited class), here is the parameter:
      <testAAA xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:testBBB"/>
      


      This is from the generated wsdl: (which have a correct "extension base=..")
      <xs:complexType name="test">
      <xs:sequence>
      <xs:element minOccurs="0" name="arg0" type="tns:testEnv"/>
      </xs:sequence>
      </xs:complexType>
      <xs:complexType name="testEnv">
      <xs:sequence>
      <xs:element minOccurs="0" name="testAAA" type="tns:testAAA"/>
      </xs:sequence>
      </xs:complexType>
      <xs:complexType name="testAAA">
      <xs:sequence/>
      </xs:complexType>
      <xs:complexType name="testBBB">
      <xs:complexContent>
      <xs:extension base="tns:testAAA">
      <xs:sequence/>
      </xs:extension>
      </xs:complexContent>
      </xs:complexType>
      


      Any help would be appreciated!

      Mats.