Discussion:
[jboss-user] [JBoss Web Services] - Is polymorphic JAX-WS operation parameter possible to implement?
Guillermo L
2013-05-15 21:44:20 UTC
Permalink
Guillermo L [https://community.jboss.org/people/gmlopezdev] created the discussion

"Is polymorphic JAX-WS operation parameter possible to implement?"

To view the discussion, visit: https://community.jboss.org/message/817907#817907

--------------------------------------------------------------
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/ http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser=" http://test.com/ 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 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!
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/817907#817907]

Start a new discussion in JBoss Web Services at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2044]
Guillermo L
2013-05-16 23:15:46 UTC
Permalink
Guillermo L [https://community.jboss.org/people/gmlopezdev] created the discussion

"Re: Is polymorphic JAX-WS operation parameter possible to implement?"

To view the discussion, visit: https://community.jboss.org/message/818074#818074

--------------------------------------------------------------
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!
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/818074#818074]

Start a new discussion in JBoss Web Services at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2044]
Guillermo L
2013-05-17 20:06:37 UTC
Permalink
Guillermo L [https://community.jboss.org/people/gmlopezdev] created the discussion

"Re: Is polymorphic JAX-WS operation parameter possible to implement?"

To view the discussion, visit: https://community.jboss.org/message/818299#818299

--------------------------------------------------------------
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 :-).
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/818299#818299]

Start a new discussion in JBoss Web Services at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2044]
Loading...