Tuesday, 17 September 2013

Provide schema for xsd:any element while importing WSDL using wsimport

Provide schema for xsd:any element while importing WSDL using wsimport

I have a WSDL that uses an xsd:any element in a return type for one of the
methods, like this:
<xs:element name="Method_XMLResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="Method_XMLResult">
<xs:complexType mixed="true">
<xs:sequence>
<xs:any/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
When I run the WSDL through the wsimport tool, I get a generated class
that has this xs:any field mapped as a list of objects:
public static class MethodXMLResult {
@XmlMixed
@XmlAnyElement(lax = true)
protected List<Object> content;
}
When invoking the service using the generated code, I get instances of
org.w3c.dom.Node in the content list
(com.sun.org.apache.xerces.internal.dom.ElementNSImpl to be precise) that
I would need to parse myself. I was, however, provided with a separate,
external schema document for the objects actually returned - and I'm
trying to somehow feed it to wsimport so it generates the classes for them
as well.
I'm trying to accomplish that through JAX-WS / JAXB customization file
like this:
<jaxws:bindings xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
xmlns:a="http://www.w3.org/2001/XMLSchema"
wsdlLocation="wsdlLocation.wsdl">
<jaxws:bindings node="wsdl:definitions">
<jaxws:bindings node="wsdl:types"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb">
<jaxws:bindings
node="//s:schema[@targetNamespace='wsNamespace']">
<jaxb:bindings
node="//s:element[@name='Method_XMLResponse']//s:any">
...
</jaxb:bindings>
</jaxws:bindings>
</jaxws:bindings>
</jaxws:bindings>
</jaxws:bindings>
Looks like wsimport picks the right location to customize (gave me
numerous error meesages with properly designated line number in the WSDL),
but I can't figure out how to fill the <jaxb:bindings> element to make
wsimport generate classes from the external schema. Is it even possible?
Any help would be much appreciated.

No comments:

Post a Comment