Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WSDL with duplicate names -- how to force Java Class names

Background: We are developing an application that communicates with several 3rd party webservices. Sadly, one of them has defined a WSDL file using poor naming conventions. The same names are often re-used for a response element, and the complexType that it employs. The code snipped below shows one such occurrence as an example:

  <s:element name="Reset_PasswordResponse">
    <s:complexType>
      <s:sequence>
        <s:element minOccurs="0" maxOccurs="1" name="Reset_PasswordResult" type="tns:ResetPasswordResponse" />
      </s:sequence>
    </s:complexType>
  </s:element>
  <s:complexType name="ResetPasswordResponse">
    <s:complexContent mixed="false">
      <s:extension base="tns:BaseResponse" />
    </s:complexContent>
  </s:complexType>

We use Maven cxf codegen plugin (jaxb/jax-ws) to compile this to Java classes. To avoid the name clashes, we have formerly used the option -AutoNameResolution. However, we have found that this leads to unexpected results, where on some machines one class gets renamed to ResetPasswordResponse2.java, while on other machines the other class is renamed. This makes collaborative development very difficult, and also gives us worries for the future (what if it won't compile correctly on Jenkins at some point?)

Question: I am looking for a way to manually determine how the translation/renaming should take place.

  • I am told that simply changing the names in the WSDL will not work, because the xml naming annotations in the Java files are of importance.
  • I have also looked into binding files or inline binding statements, but cannot get it to work. The documentation at http://wiki.netbeans.org/WsdlCustomizer#Class_Customization seems to imply that name changes are only possible for "wsdl:portType, wsdl:fault, soap:headerfault, and wsdl:server", which indicates I might be trying to do something that is simply impossible.

Are jaxb/jax-ws bindings a possible solution? Are there other options?

like image 378
Michael Avatar asked Mar 18 '23 01:03

Michael


1 Answers

Check this question and answer:

JAXB Binding for XSD outside WSDL

In short, you can use so-called binding files to customize names.

<jxb:bindings version="2.1" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <jxb:bindings schemaLocation="xsdschema.xsd" node="/xs:schema">
        <jxb:bindings node="xs:complexType[@name='ResetPasswordResponse']">
            <jxb:class name="ResetPasswordResponseType"/>
        </jxb:bindings>
    </jxb:bindings>
</jxb:bindings>

You may be interested in jaxb:nameXmlTransform:

Issue with JAXB: nameXmlTransform typeName prefix not working

This would allow you to customize type or element naming rules globally:

<?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:nameXmlTransform>
            <jaxb:typeName suffix="Type"/>
            <jaxb:elementName suffix="Element"/>
         </jaxb:nameXmlTransform>
      </jaxb:schemaBindings>
   </jaxb:bindings>
</jaxb:bindings>

Credits go to Blaise Doughan.

like image 111
lexicore Avatar answered Mar 26 '23 02:03

lexicore