繁体   English   中英

编写WSDL绑定

[英]Write a WSDL binding

我正在使用WSDL生成Java类,以访问Zuora SOAP API。

不幸的是,此WSDL有冲突:Maven CXF插件引发错误,消息为“两个声明在ObjectFactory类中引起冲突”。

冲突发生在Invoice.PaymentAmount和Payment.Amount之间

<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" 
    xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:zns="http://api.zuora.com/" 
    xmlns:ons="http://object.api.zuora.com/"
    xmlns:fns="http://fault.api.zuora.com/"
    targetNamespace="http://api.zuora.com/">
    <types>
        <schema attributeFormDefault="qualified" elementFormDefault="qualified" xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://object.api.zuora.com/">
            <import namespace="http://api.zuora.com/" />
            <complexType name="zObject">
                <sequence>
                    <element minOccurs="0" maxOccurs="unbounded" name="fieldsToNull" nillable="true" type="string" />
                    <element minOccurs="0" maxOccurs="1" name="Id" nillable="true" type="zns:ID" />
                </sequence>
            </complexType>

            <complexType name="Invoice" >
                <complexContent>
                    <extension base="ons:zObject">
                        <sequence>
                            <element minOccurs="0" name="AccountId" nillable="true" type="zns:ID" />
                            <element minOccurs="0" name="AdjustmentAmount" nillable="true" type="decimal" />
                            <element minOccurs="0" name="PaymentAmount" nillable="true" type="decimal" />
                            <!--more elements-->
                        </sequence>
                    </extension>
                </complexContent>
            </complexType>

            <complexType name="Payment" >
                <complexContent>
                    <extension base="ons:zObject">
                        <sequence>
                            <element minOccurs="0" name="AccountId" nillable="true" type="zns:ID" />
                            <element minOccurs="0" name="AccountingCode" nillable="true" type="string"  />
                            <element minOccurs="0" name="Amount" nillable="true" type="decimal" />
                            <!--more elements-->
                        </sequence>
                    </extension>
                </complexContent>
            </complexType>

            <!--more types-->

技巧似乎是此帖子建议的外部绑定文件。https://community.zuora.com/t5/API/quot-Two-declarations-cause-a-collision-in-the-ObjectFactory/td- p / 11265

但是没有代码示例。 而且我不知道如何编写这样的绑定文件。

我试过了 :

<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
           xmlns:xs="http://www.w3.org/2001/XMLSchema"
           version="1.0">
    <jaxb:bindings schemaLocation="zuora.a.77.0.wsdl">
        <jaxb:bindings node="//xs:element[@name='PaymentAmount']/xs:complexType">
            <jaxb:factoryMethod name="PaymentAmout2"/>
        </jaxb:bindings>
    </jaxb:bindings>
</jaxb:bindings>

但这似乎太简单了,并且抛出

"file:/home/kemkem/Work/repo/asap/tooling-zuora/src/main/resources
/wsdl/zuora.a.77.0.wsdl" is not a part of this compilation. 
Is this a mistake for "file:/home/kemkem/Work/repo/asap/tooling-zuora/
src/main/resources/wsdl/zuora.a.77.0.wsdl#types1"

有谁有更好的方法吗?

似乎可以使用以下设置

src / resources / wsdl / zuora.a.77.0.wsdl中的wsdl文件

src / resources / binding.xml:

<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
               xmlns:xs="http://www.w3.org/2001/XMLSchema"
               version="1.0">
    <jaxb:bindings schemaLocation="wsdl/zuora.a.77.0.wsdl#types1">
        <jaxb:bindings node="//xs:element[@name='PaymentAmount']">
            <jaxb:factoryMethod name="PaymentAmout2"/>
        </jaxb:bindings>
    </jaxb:bindings>
</jaxb:bindings>

Maven CXF插件:

<plugin>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-codegen-plugin</artifactId>
    <version>3.2.5</version>
    <executions>
        <execution>
            <id>generate-sources</id>
            <phase>generate-sources</phase>
            <configuration>
                <sourceRoot>${project.build.directory}/generated-sources</sourceRoot>
                <wsdlOptions>
                    <wsdlOption>
                        <wsdl>${project.basedir}/src/main/resources/wsdl/zuora.a.77.0.wsdl</wsdl>\
                        <wsdlLocation>classpath:wsdl/zuora.a.77.0.wsdl</wsdlLocation>
                        <frontEnd>jaxws21</frontEnd>
                        <bindingFiles>
                            <bindingFile>src/main/resources/binding.xml</bindingFile>
                        </bindingFiles>
                    </wsdlOption>
                </wsdlOptions>
                <defaultOptions>
                    <autoNameResolution>true</autoNameResolution>
                    <markGenerated>true</markGenerated>
                    <asyncMethods />
                    <bareMethods />
                    <frontEnd>jaxws21</frontEnd>
                    <packagenames>
                        <packagename>com.zuora</packagename>
                    </packagenames>
                </defaultOptions>
            </configuration>
            <goals>
                <goal>wsdl2java</goal>
            </goals>
        </execution>
    </executions>
</plugin>

暂无
暂无

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

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