具有重复名称的WSDL - 如何强制Java类名称 [英] WSDL with duplicate names -- how to force Java Class names

查看:141
本文介绍了具有重复名称的WSDL - 如何强制Java类名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

后台:
我们正在开发一个与多个第三方Web服务进行通信的应用程序。
可悲的是,其中一个人使用不良的命名约定定义了一个WSDL文件。
相同的名称通常被重用于响应元素,以及它使用的complexType。下面剪切的代码显示了一个这样的例子:

Background: We are developing an application that communicates with several 3rd party webservices. Sadly, one of them has defined a WSDL file using poor naming conventions. The same names are often re-used for a response element, and the complexType that it employs. The code snipped below shows one such occurrence as an example:

  <s:element name="Reset_PasswordResponse">
    <s:complexType>
      <s:sequence>
        <s:element minOccurs="0" maxOccurs="1" name="Reset_PasswordResult" type="tns:ResetPasswordResponse" />
      </s:sequence>
    </s:complexType>
  </s:element>
  <s:complexType name="ResetPasswordResponse">
    <s:complexContent mixed="false">
      <s:extension base="tns:BaseResponse" />
    </s:complexContent>
  </s:complexType>

我们使用Maven cxf codegen插件(jaxb / jax-ws)将其编译为Java类。为了避免名称冲突,我们以前使用了 -AutoNameResolution 选项。
但是,我们发现这会导致意想不到的结果,在某些机器上,一个
类被重命名为ResetPasswordResponse2.java,而在其他机器上,其他类被重命名。
这使得协作开发变得非常困难,并且让我们对未来感到担忧(如果它在某些时候无法在Jenkins上正确编译会怎么样?)

We use Maven cxf codegen plugin (jaxb/jax-ws) to compile this to Java classes. To avoid the name clashes, we have formerly used the option -AutoNameResolution. However, we have found that this leads to unexpected results, where on some machines one class gets renamed to ResetPasswordResponse2.java, while on other machines the other class is renamed. This makes collaborative development very difficult, and also gives us worries for the future (what if it won't compile correctly on Jenkins at some point?)

问题:
我正在寻找一种方法来手动确定翻译/重命名的方式。

Question: I am looking for a way to manually determine how the translation/renaming should take place.


  • 我被告知只是更改WSDL中的名称是行不通的,因为Java文件中的xml命名注释很重要。

  • 我也研究了绑定文件或者内联绑定语句,但无法使其工作。 http://wiki.netbeans.org/WsdlCustomizer#Class_Customization 上的文档似乎暗示了这个名字更改只适用于wsdl:portType,wsdl:fault,soap:headerfault和wsdl:server,这表明我可能正在尝试做一些根本不可能的事情。

  • I am told that simply changing the names in the WSDL will not work, because the xml naming annotations in the Java files are of importance.
  • I have also looked into binding files or inline binding statements, but cannot get it to work. The documentation at http://wiki.netbeans.org/WsdlCustomizer#Class_Customization seems to imply that name changes are only possible for "wsdl:portType, wsdl:fault, soap:headerfault, and wsdl:server", which indicates I might be trying to do something that is simply impossible.

jaxb / jax-ws是否可以绑定一个可能的解决方案?还有其他选择吗?

Are jaxb/jax-ws bindings a possible solution? Are there other options?

推荐答案

检查此问题和答案:


WSDL之外的XSD的JAXB绑定

简而言之,您可以使用所谓的绑定文件来自定义名称。

In short, you can use so-called binding files to customize names.

<jxb:bindings version="2.1" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <jxb:bindings schemaLocation="xsdschema.xsd" node="/xs:schema">
        <jxb:bindings node="xs:complexType[@name='ResetPasswordResponse']">
            <jxb:class name="ResetPasswordResponseType"/>
        </jxb:bindings>
    </jxb:bindings>
</jxb:bindings>

您可能对 jaxb:nameXmlTransform


nameXmlTransform typeName前缀不起作用

这将允许您自定义类型或元素命名规则全球:

This would allow you to customize type or element naming rules globally:

<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xsd="http://www.w3.org/2001/XMLSchema" jaxb:version="2.0">
   <jaxb:bindings schemaLocation="schema.xsd" node="/xsd:schema">
      <jaxb:schemaBindings>
         <jaxb:nameXmlTransform>
            <jaxb:typeName suffix="Type"/>
            <jaxb:elementName suffix="Element"/>
         </jaxb:nameXmlTransform>
      </jaxb:schemaBindings>
   </jaxb:bindings>
</jaxb:bindings>

积分转到 Blaise Doughan

这篇关于具有重复名称的WSDL - 如何强制Java类名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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