Question

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.

Was it helpful?

Solution

I see you are use mixed type with xs:any in your XSD. I think it usefull custimization for a mixed type following JAXB adjust:

<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings
 xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="2.0"
 xmlns:xjc= "http://java.sun.com/xml/ns/jaxb/xjc" jaxb:extensionBindingPrefixes="xjc">

  <jaxb:globalBindings generateMixedExtensions="true"/>

</jaxb:bindings> 

You can add external JAXB binding files to wsimport whith -b parameter.

I think you can adjust xs:any with following ways:

Skip shema:

<xs:any processContents="skip" maxOccurs="unbounded" minOccurs="0" />

Skip binding:

@XmlAnyElement
  public List<Element> getAny();

Strict schema:

<xs:any maxOccurs="unbounded" minOccurs="0" />

Strict binding:

@XmlAnyElement(lax=true)
  public List<Object> getAny();

and:

with processContents=lax means any XML elements can be placed here, but if their element names match those defined in the schema, they have to be valid. XJC actually handles this exactly like processContents='strict', since the strict binding allows unknown elements anyway.

You can read more about in this link.

May be help this answer to accomplish your JAX-WS / JAXB customization file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top