简体   繁体   English

使用XMLBeans编译2 WSDL使用的共享模式

[英]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. 我正在尝试生成源代码并使用XMLBeans + CXF将它们编译到一个jar中。 CommonSchema folder has schemas that shared by Service1 and 2. CommonSchema文件夹具有Service1和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 : 当我尝试生成源代码时,似乎1和2 xsd的源有命名冲突,可以在下面看到:

First WSDL Generation 第一个WSDL生成

在此输入图像描述

Second WSDL Generation 第二个WSDL生成

在此输入图像描述

Any idea on how should I compile this common schema? 关于如何编译这个通用模式的任何想法?

Here is my Ant Script : 这是我的Ant脚本:

<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. 我的项目是位于: 这里下CXF代。

the whole schema + WSDL can be found under CXF-Generation/Generation 整个模式+ WSDL可以在CXF-Generation / Generation下找到

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: 运行XmlBeans命令时如果像2个单独的命令一样运行它:

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. 第一个命令将生成一个jar,第二个命令将使用第二个wsdl中的新代码对其进行ovverride。

I think you are running it like this and that is why you get only the code of one wsdl. 我认为你正在运行它,这就是为什么你只得到一个wsdl的代码。

You need to combine them both into one wsdl (maybe a wrapper wsdl) and then generate the code from it. 您需要将它们组合成一个wsdl(可能是包装器wsdl),然后从中生成代码。

Or you can generate 2 different jars. 或者你可以生成2个不同的罐子。

EDIT: 编辑:

A little correction, apparently only IBM support importing a wsdl from another wsdl . 稍微纠正一下,显然只有IBM支持从另一个wsdl导入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个jar。
  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. 将两个wsdls合并为一个(简单的复制粘贴) - 如果存在具有不同用途的相同名称的方法/参数,则可能有点棘手。

Use an xsdconfig solve my problem. 使用xsdconfig解决我的问题。 In the end I have duplicated package, but it suits my needs. 最后我有重复的包,但它符合我的需要。

My Maven to generate the conflicted package 我的Maven生成冲突的包

<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 : 我的xsd配置:

<?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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM