Provide schema for xsd: any item when importing WSDL using wsimport

I have a WSDL that uses the xsd:any element in the return type for one of the methods, for example:

 <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 WSDL using the wsimport tool, I get a generated class that has this xs:any field, displayed as a list of objects:

 public static class MethodXMLResult { @XmlMixed @XmlAnyElement(lax = true) protected List<Object> content; } 

When I call 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 will need to parse. However, I was provided with a separate external schema document for the returned objects - and I'm trying to somehow pass it to wsimport so that it also generates classes for them.

I am trying to accomplish this through a JAX-WS / JAXB configuration file as follows:

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

It seems that wsimport is choosing the right place to configure (it gave me a lot of errors with the correct line number in the WSDL), but I can’t figure out how to populate the <jaxb:bindings> element to make wsimport generate classes from an external schema. Is it possible? Any help would be greatly appreciated.

+4
source share
1 answer

I see that you are using a mixed type with xs: any in your XSD. I think this is useful for custimization for a mixed type following configuring JAXB:

 <?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 the wsimport whith - b parameter .

I think you can configure xs: any with the following ways:

Skip shema:

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

Skip binding:

 @XmlAnyElement public List<Element> getAny(); 

Strict scheme:

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

Strict binding:

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

and

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

You can learn more about in this link.

This answer may help to execute your JAX-WS / JAXB configuration file.

+2
source

Source: https://habr.com/ru/post/1502705/


All Articles