Pregunta

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

¿Fue útil?

Solución 2

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>

Otros consejos

I'm not an ant expert so i'm not sure i'm right, but I think the problem is that one target ovverides the other.

When running XmlBeans command if you run it like 2 seperate commands:

wsdl2java -uri my_service1.wsdl
wsdl2java -uri my_service2.wsdl

The first command will generate a jar and the second one will ovverride it with the a new code from the second wsdl.

I think you are running it like this and that is why you get only the code of one wsdl.

You need to combine them both into one wsdl (maybe a wrapper wsdl) and then generate the code from it.

Or you can generate 2 different jars.

EDIT:

A little correction, apparently only IBM support importing a wsdl from another wsdl.

So the wrapper option is off the table. IMHO, these are your options:

  1. Change the target namespace of the common schema so there won't be a conflict and generate 2 jars.
  2. Combine both wsdls into one (simple copy paste) - might be a bit tricky if there are methods/parameters with same name that have different purpose.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top