如何解决wsdl2java上ObjectFactory的冲突? [英] How to resolve collision in the ObjectFactory on wsdl2java?

查看:649
本文介绍了如何解决wsdl2java上ObjectFactory的冲突?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 CXF wsdl2java 来自动生成webservice类。

I'm using CXF and wsdl2java to autogenerate webservice classes.

问题:我想连接的web服务在某种程度上具有一些元素的重复名称:

Problem: somehow the webservice I want to connect to has duplicate names for some elements:

两个声明会导致冲突ObjectFactory类

xsd类似于:

<xs:schema targetNamespace="http://thenamespace">
    <xs:complexType name="ViolatingName">
     ...
    </xs:complexType>
    <xs:element name="ViolatingName" nillable="true" type="tns:ViolatingName"/>
</xs:schema>

xsd本身是在wsdl中导入的,用于自动生成jaxb类,如下所示:

The xsd itself is imported inside the wsdl that is used to autogenerate the jaxb classes like this:

<wsdl:types>
    <xsd:schema targetNamespace="http://imports">
        <xsd:import schemaLocation="https://path.to.xsd" namespace="http://thenamespace" />

我试图用 jaxb-bindings.xml覆盖这个

<jaxb:bindings    
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
    jaxb:extensionBindingPrefixes="xjc"   
    jaxb:version="2.1">

    <jaxb:bindings schemalocation="https://path.to.xsd" node="//xs:schema">
    <jaxb:bindings node=".//xs:element[@name='ViolatingName']">
            <jaxb:property name="ViolatingNameBinding" />
        </jaxb:bindings>
    </jaxb:bindings>
</jaxb:bindings>

结果:

[错误] XPath评估// xs:schema导致空目标节点(org.apache.cxf:cxf-codegen-plugin:3.0.1:wsdl2java:generate-sources:generate-sources)

为什么节点在这里错了? xsd有一个 xs:schema 标签,为什么会失败?

Why is the node wrong here? The xsd has a xs:schema tag, so why is this failing?

有趣的事实:当我使用任何xpath工具,下载XSD到我的本地机器检查路径,然后 // xs:schema / xs:element [@ name ='ViolatingName'] 评估到正确的标签。

Interesting fact: when I use any xpath tool, download the XSD to my local machine an check the path, then //xs:schema/xs:element[@name='ViolatingName'] evaluates to the proper tag.

推荐答案

事实证明我必须对所有 xs:complexType <应用重命名/后缀/ code>这样的元素:

It turned out I have to apply a renaming/suffix on all xs:complexType elements like this:

<jaxb:bindings schemaLocation="https://path.to.xsd" node="/xs:schema">
    <jaxb:schemaBindings>
        <jaxb:nameXmlTransform>
            <jaxb:typeName suffix="Type" />
        </jaxb:nameXmlTransform>
    </jaxb:schemaBindings>
</jaxb:bindings>

这篇关于如何解决wsdl2java上ObjectFactory的冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆