首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >编写WSDL绑定

编写WSDL绑定
EN

Stack Overflow用户
提问于 2018-09-06 15:35:31
回答 1查看 802关注 0票数 0

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

不幸的是,这个WSDL有冲突: Maven CXF插件抛出一个错误,并显示“两个声明导致ObjectFactory类中的冲突”的消息。

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

代码语言:javascript
复制
<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

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

我试过了:

代码语言:javascript
复制
<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>

但它似乎过于简单,并抛出了一个

代码语言:javascript
复制
"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"

有没有更好的方法来解决这个问题?

EN

回答 1

Stack Overflow用户

发布于 2018-09-06 16:10:56

似乎可以与以下设置一起工作

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

src/resources/binding.xml:

代码语言:javascript
复制
<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插件:

代码语言:javascript
复制
<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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52198809

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档