I am working with an external 3rd party WSDL file and trying to generate Java code from it.
The WSDL contains name conflictions between <s:element>
and <s:complexType>
. For example:
<s:element name="Foo"> <!-- name conflict -->
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="SoapMessage" type="tns:Foo" />
</s:sequence>
</s:complexType>
</s:element>
<s:complexType name="Foo"> <!-- name conflict -->
<s:complexContent mixed="false">
<s:extension base="tns:SoapMessageBase">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="Request" type="tns:FooRequest" />
<s:element minOccurs="0" maxOccurs="1" name="Response" type="tns:FooResponse" />
</s:sequence>
</s:extension>
</s:complexContent>
</s:complexType>
I know that with correct bindings.jxb
, one of them can be renamed. This is the exact problem described in named the s:element and s:complexType the same name
However,the solution from the post above does not really work. There are a LOT, like 100+, name conflictions in the WSDL.
Before I craft a bindings.xjb
to resolve every single of them. (Yes, I could write a script), is there any simpler way to address this? Like pattern matching + bulk renaming?
By far what I can find is to use <jaxb:nameXmlTransform>
per Issue with JAXB: nameXmlTransform typeName prefix not working
<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xsd="http://www.w3.org/2001/XMLSchema" jaxb:version="2.0">
<jaxb:bindings schemaLocation="schema.xsd" node="/xsd:schema">
<jaxb:schemaBindings>
<jaxb:package name="com.mycompany.hi"/>
<jaxb:nameXmlTransform>
<jaxb:typeName prefix="Hi_"/>
<jaxb:elementName prefix="Hi_"/>
</jaxb:nameXmlTransform>
</jaxb:schemaBindings>
</jaxb:bindings>
</jaxb:bindings>
But the challenge is <jaxb:bindings schemaLocation="schema.xsd" node="/xsd:schema">
- The external WSDL provider does not give any .xsd
file at all.
Is this a common scenario where only WSDL is provided? or is it just me missing something here?
Thanks!
It turns out schemaLocation="./services.wsdl#types1"
solved the problem. Now I can generate code from WSDL without XSD.
<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xsd="http://www.w3.org/2001/XMLSchema" jaxb:version="2.0">
<jaxb:bindings schemaLocation="./services.wsdl#types1">
<jaxb:schemaBindings>
<jaxb:nameXmlTransform>
<jaxb:typeName suffix="Type" />
<jaxb:elementName suffix="Element" />
</jaxb:nameXmlTransform>
</jaxb:schemaBindings>
</jaxb:bindings>
</jaxb:bindings>