2 Replies Latest reply on May 17, 2013 4:06 PM by gmlopezdev

    Is polymorphic JAX-WS operation parameter possible to implement?

    gmlopezdev

      Hi,

      I'm developing a web service and I need it to accept a polymorphic parameter. For example, imagine an operation named processRequests(List<Request> requests) which may accept a "Request" and a "CustomRequest" type (extending from Request) and possibly some others. It is my understanding that it should be possible to achieve however no matter how I do it I allways get the paramter unmarshaled as the base class.

       

      I'm testing it with SOAP UI in the following way:

       

      <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://test.com/">

         <soapenv:Header/>

         <soapenv:Body>

            <ser:processRequests>

               <!--Zero or more repetitions of customRequest -->

               <requests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="customRequest">

                   <prop1/>

                   <prop2/>

               </requests>

            </ser:processRequests>

         </soapenv:Body>

      </soapenv:Envelope>

       

      The pojos are as the following:

       

      @XmlRootElement

      @XmlSeeAlso({CustomRequest.class})

      publc class Request {}

       

      publc class CustomRequest extends Request{}

       

      ¿Am I tryin to do something impossible?

       

      Your help is highly appreciated!

        • 1. Re: Is polymorphic JAX-WS operation parameter possible to implement?
          gmlopezdev

          Isn't there anyone out ther who has an idea why is this not working and/or if there is any workaround?

           

          I cannot even get a simple Object to work with a subtype. The generated wsdl doesn't even defines the hierarchy. I did modify the wsdl by myself but had no luck. The object is allways getting unmarshalled as the supertype and I get and unmarshalling error if a subtype's property is sent to the server.

           

          Thanks again for your help!

          • 2. Re: Is polymorphic JAX-WS operation parameter possible to implement?
            gmlopezdev

            I finally got this resolved. It is absolutely possible to implement this behavior. If I were developing a single EAR I wouldn´t have experienced a problem like this.

             

            Since I'm developing several enterprise applications (EAR modules) over JBoss AS 7 which need to communicate through their local interfaces, I need to publish them as modules (including DTOs). Even I was getting no other symptom of errors or problems but the one I described, the issue was caused because my module must declare the dependency over jaxb api. Otherwise the annotations have no effect. Once I added this dependency to the module, everything started to work normally as expected :-).

             

            Important things to remember here:

             

            Declare your sub classes as the following within your parent class:

             

                @XmlSeeAlso({Pojo1.class, Pojo2.class, ...})

             

            If your classes are published as a JBoss module, do not forget to declare the jaxb dependency.

             

            I hope this may help others like me in the future :-).