Reputation: 41
I'm trying to run wsimport against a WSDL file that I cannot modify. A portion of the WSDL looks like this:
<xsd:complexType name="Bapiitemex">
<xsd:sequence>
<xsd:element name="ItmNumber" type="n0:numeric6"/>
<xsd:element name="PoItmNo" type="n0:char6"/>
<xsd:element name="Material" type="n0:char18"/>
<xsd:element name="MatEntrd" type="n0:char18"/>
<xsd:element name="ShortText" type="n0:char40"/>
<xsd:element name="NetValue" type="n0:numeric15"/>
<xsd:element name="Currency" type="n0:cuky5"/>
<xsd:element name="Subtotal1" type="n0:numeric15"/>
<xsd:element name="Subtotal2" type="n0:numeric15"/>
<xsd:element name="Subtotal3" type="n0:numeric15"/>
<xsd:element name="Subtotal4" type="n0:numeric15"/>
<xsd:element name="Subtotal5" type="n0:numeric15"/>
<xsd:element name="Subtotal6" type="n0:numeric15"/>
<xsd:element name="SUBTOTAL1" type="n0:decimal23.4"/>
<xsd:element name="SUBTOTAL2" type="n0:decimal23.4"/>
<xsd:element name="SUBTOTAL3" type="n0:decimal23.4"/>
<xsd:element name="SUBTOTAL4" type="n0:decimal23.4"/>
<xsd:element name="SUBTOTAL5" type="n0:decimal23.4"/>
<xsd:element name="SUBTOTAL6" type="n0:decimal23.4"/>
</xsd:sequence>
</xsd:complexType>
wsimport is unhappy due to the inclusion of multiple elements which differ only in case ('Subtotal1' versus 'SUBTOTAL1', etc.). The specific error is
java.lang.IllegalArgumentException: trying to create the same field twice: subtotal1
In researching a solution to this problem, I tried running wsimport with the '-B-XautoNameResolution' option, but that had no effect. It seems the only other possible solution is to use an external binding file to explicitly tell wsimport how to name the variables. However, I'm having difficulty making that work as well. Here is the binding file I'm attempting to use just for one of the duplicate variables:
<jxb:bindings version="1.0"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<jxb:bindings node="//xsd:complexType[@name='Bapiitemex']//xsd:element[@name='Subtotal1']">
<jxb:property name="testSubtotal1"/>
</jxb:bindings>
Try as I might, wsimport doesn't seem to understand what I'm asking it to do. It's unhappy with the XPath syntax I'm using for the 'node' attribute, returning the error:
XPath evaluation of "//xsd:complexType[@name='Bapiitemex']//xsd:element[@name='Subtotal1']" results in empty target node
Suggestions as to how I can persuade wsimport to generate my Java classes for me?
Upvotes: 2
Views: 6643
Reputation: 41
After more fumbling around, I finally figured out how to write a binding file to make things work. My solution is based largely on information I found in this post.
Note that I have 6 cases of element names which differ only in case. The solution posted below only resolves one of the conflicts. The remainder can be resolved by adding more internal <jaxws:bindings> elements.
<jaxws:bindings
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="2.1"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
wsdlLocation="PricingDirectCall.wsdl">
<jaxws:bindings node="wsdl:definitions/wsdl:types/xsd:schema[@targetNamespace='urn:sap-com:document:sap:soap:functions:mc-style']/xsd:complexType[@name='Bapiitemex']/xsd:sequence/xsd:element[@name='Subtotal1']">
<jaxb:property name="testSubtotal1"/>
</jaxws:bindings>
The biggest hurdle I had to overcome was fiddling with the 'node' attribute to get the XPath correct (the conflict is acutally occuring in an internal XSD within the WSDL). After I had that resolved, I just needed to make sure I specified the correct <jaxb> element. Specifying <jaxb:class> changes the data type of the generated variable, creating an inner class with the specified name, which is not what I wanted. Specifying <jaxb:property> changes the name of the generated variable, resolving the duplicate name conflict.
Upvotes: 2