Hi,
I have a webservice that includes "abstract" schema elements and its
extensions.
Whenever I use JAXWS as a client for the webservice, the "inheritance" is
supported using xsi:type attribute like the following:
<S:Envelope xmlns:S="
http://schemas.xmlsoap.org/soap/envelope/">
<S:Header/>
<S:Body>
<ns2:getSomething xmlns:ns2="
http://www.blah.com/services/commons/web"
xmlns:ns3="
http://www.blah.com/services/commons">
<searchCriteria>
<criterions xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xsi:type="ns3:someExpression">
<propertyName>name</propertyName>
<matchMode>START</matchMode>
<criterionType>SomeExpression</criterionType>
</criterions>
<numberOrItemsPerRequest>50</numberOrItemsPerRequest>
<requestNumber>0</requestNumber>
</searchCriteria>
</ns2:getSomething>
</S:Body>
</S:Envelope>
On the server side this is being unmarshalled with no problem to class
"LikeExpression" and execution continues.
Another webservices client that I've been using is Adobe Flex. For some
reason it does not support the xsi:type and send the message as following:
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="
http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="
http://www.w3.org/2001/XMLSchema"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<ns0:getInformation
xmlns:ns0="
http://www.blah.com/services/commons/web">
<searchCriteria>
<criterions>
<criterionType>SomeExpression</criterionType>
<matchMode>START</matchMode>
<propertyName>name</propertyName>
<value/>
</criterions>
<numberOrItemsPerRequest>0</numberOrItemsPerRequest>
<requestNumber>0</requestNumber>
<subCriterias xsi:nil="true"/>
</searchCriteria>
</ns0:getInformation>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
In this case JAXWS server side fails with exception:
Caused by: javax.xml.bind.UnmarshalException: Unable to create an instance
of com.blah.Criterion
Because it is an abstract class.
What I tried is plugging in SOAPMessage handler that would change the
incoming SOAP message and add "xsi:type" attribute to <criterions> element.
So I end up with the following message:
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="
http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<ns1:getInformation xmlns:ns1="
http://www.blah.com/services/commons/web"
xmlns:ns2="
http://www.blah.com/services/commons">
<searchCriteria>
<criterions xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xsi:type="ns2:likeExpression">
<criterionType>SomeExpression</criterionType>
<matchMode>START</matchMode>
<propertyName>name</propertyName>
<value/>
</criterions>
<numberOrItemsPerRequest>0</numberOrItemsPerRequest>
<requestNumber>0</requestNumber>
<subCriterias xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xsi:nil="true"/>
</searchCriteria>
</ns1:getInformation>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Which has xsi:type attribute and looks very decent to me :-).
The problem is that it still fail with the same exception !!!!!
The question is what am I doing wrong ?????
Thanks in advance.
Regards,
Dima Gutzeit.