4

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

Rudy
  • 7,008
  • 12
  • 50
  • 85
  • Can you post your build script – Niroshan Abayakoon Jun 27 '12 at 08:08
  • Hi, I'm using ant script of wsdl2java. I have updated my question. – Rudy Jun 27 '12 at 11:53
  • I can't try it right now, but can you or someone else interested in the bounty ;)... try to create another WSDL that sits on top of the two you've listed (use wsdl:import to link those two), and use just that one WSDL in your ant task? It seems that you target the same source folder and classpath, so it should work... – Petru Gardea Jun 30 '12 at 15:00

2 Answers2

1

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.
Tomer
  • 17,787
  • 15
  • 78
  • 137
  • Hi ftom2, Initially I created 2 jars, however this cause conflict in classpath ( the common schema class generated with different implementation ) if you use it together. Now I wonder if i can generate the 2nd wsdl with different package name on the common schema. For your other suggestion to create wrapper wsdl, may I know how to do that? – Rudy Jul 01 '12 at 17:23
  • If you can change the target namespace in the wsdl that will generate it with a different package. – Tomer Jul 01 '12 at 18:48
  • 2nd option resulted in error : Non-unique body parts! In a port, operations must have unique operation signatures on the wire for successful dispatching. In port {http://tempuri.og/myEndPoint.wsdl}Port, operations "{http://tempuri.og/myEndPoint.wsdl}CBS-CustAccountInfo-I" and "{http://tempuri.og/myEndPoint.wsdl}CBS-DirectDebCredTransfer-C" have the same request body block {http://schemas.ocbc.com/soa/emf/common/envelope/}ServiceEnvelope ( This is my initial problem ) – Rudy Jul 02 '12 at 02:44
  • For the first option, the wsdl is actually belong to other party, so the real implementation can't be changed. Do you think this is okay? – Rudy Jul 02 '12 at 02:52
  • No, the service has to change as well :(, Can you contact the service provider? if changes are to be made to the wsdl, it is best they do it. – Tomer Jul 02 '12 at 07:48
0

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>
Rudy
  • 7,008
  • 12
  • 50
  • 85