Search code examples
javaxsdcxfxmlbeans

Compiling shared schema used by 2 WSDL using XMLBeans


I have this following directory structure

Root
   CommonSchema
      1.xsd
      2.xsd

   Service1
      XSD
        3.xsd ( importing 1 and 2 xsd )
      WSDL
        A.wsdl ( importing 3.xsd )

   Service2
      XSD
        4.xsd ( importing 1 and 2 xsd )
      WSDL
        B.wsdl ( importing 4.xsd )

I'm trying to generate the source and compiling them into a single jar using XMLBeans+CXF. CommonSchema folder has schemas that shared by Service1 and 2.

When I try to generate the source source, it seems that the source of 1 and 2 xsd has a naming conflict, that can be seen below :

First WSDL Generation

enter image description here

Second WSDL Generation

enter image description here

Any idea on how should I compile this common schema?

Here is my Ant Script :

<target name="cxfWSDLToJava">
  <java classname="org.apache.cxf.tools.wsdlto.WSDLToJava" fork="true">
    <arg value="-databinding"/>
    <arg value="xmlbeans"/>
    <arg value="-client"/>
    <arg value="-d"/>
    <arg value="cxfsrc"/>
    <arg value="D:\Generation\Services\CBS-CustAccountInfo-I\WSDL\CBS-CustAccountInfo-I-Concrete.wsdl"/>
    <classpath>
      <path refid="cxf.classpath"/>
    </classpath>
  </java>
</target>

<target name="cxfWSDLTXNToJava">
  <java classname="org.apache.cxf.tools.wsdlto.WSDLToJava" fork="true">
    <arg value="-databinding"/>
    <arg value="xmlbeans"/>
    <arg value="-client"/>
    <arg value="-d"/>
    <arg value="cxfsrc"/>
    <arg value="D:\Generation\Services\CBS-DirectDebCredTransfer-C\WSDL\CBS-DirectDebCredTransfer-C-Concrete.wsdl"/>
    <classpath>
      <path refid="cxf.classpath"/>
    </classpath>
  </java>
</target>

my project is located at : here under CXF-Generation.

the whole schema + WSDL can be found under CXF-Generation/Generation


Solution

  • Use an xsdconfig solve my problem. In the end I have duplicated package, but it suits my needs.

    My Maven to generate the conflicted package

    <executions>
    <execution>
        <id>generate-sources</id>
        <phase>generate-sources</phase>
        <configuration>
            <wsdlOptions>
                <wsdlOption>
                    <wsdl>${basedir}\..\Generation\Services\CBS-DirectDebCredTransfer-C\WSDL\CBS-DirectDebCredTransfer-C-Concrete.wsdl</wsdl>
                    <extraargs>
                        <extraarg>-db</extraarg>
                        <extraarg>xmlbeans</extraarg>
                        <extraarg>-p</extraarg>
                        <extraarg>com.xxx.txnpos.ws</extraarg>
                    </extraargs>
                    <bindingFiles>
                        <bindingFile>${basedir}/txnpos.xsdconfig</bindingFile>
                    </bindingFiles>
                </wsdlOption>
            </wsdlOptions>
        </configuration>
        <goals>
            <goal>wsdl2java</goal>
        </goals>
    </execution>
    </executions>
    

    My xsd config :

    <?xml version="1.0"?>
    <xb:config xmlns:xb="http://xml.apache.org/xmlbeans/2004/02/xbean/config">
    <xb:namespace uri="http://schemas.xxx.com/soa/emf/common/aggregates/">
    <xb:package>com.xxx.schemas.soa.emf.txnpost.aggregates</xb:package>
    </xb:namespace>
    <xb:namespace uri="http://schemas.xxx.com/soa/emf/common/body/">
    <xb:package>com.xxx.schemas.soa.emf.txnpost.body</xb:package>
    </xb:namespace>
    <xb:namespace uri="http://schemas.xxx.com/soa/emf/common/elements/">
    <xb:package>com.xxx.schemas.soa.emf.txnpost.elements</xb:package>
    </xb:namespace>
    <xb:namespace uri="http://schemas.xxx.com/soa/emf/common/envelope/">
    <xb:package>com.xxx.schemas.soa.emf.txnpost.envelope</xb:package>
    </xb:namespace>
    <xb:namespace uri="http://schemas.xxx.com/soa/emf/common/header/">
    <xb:package>com.xxx.schemas.soa.emf.txnpost.header</xb:package>
    </xb:namespace>
    <xb:namespace uri="http://schemas.xxx.com/soa/emf/common/monetaryErrorReponse/">
    <xb:package>com.xxx.schemas.soa.emf.txnpost.monetaryErrorReponse</xb:package>
    </xb:namespace>
    </xb:config>