jax-ws ri 2.2.1 没有为亚马逊 ecs wsdl 文件生成枚举 [英] No enums generated by jax-ws ri 2.2.1 for amazon ecs wsdl file

查看:32
本文介绍了jax-ws ri 2.2.1 没有为亚马逊 ecs wsdl 文件生成枚举的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为以下 amazon wsdl 生成工件:
http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl

I'm attempting to generate artifacts for the following amazon wsdl:
http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl

使用以下蚂蚁任务:

<taskdef name="wsimport" classname="com.sun.tools.ws.ant.WsImport">
    <classpath>
        <pathelement location="${BUILD_LIBS}/jaxws-ri/lib/jaxws-tools.jar"/>
    </classpath>
</taskdef>

<target name="wsimport" depends="init">
    <delete dir="${generated.src}" />
    <mkdir dir="${generated.src}"/>
    <wsimport
        debug="true"
    keep="true"
    verbose="true"
    destdir="${generated.src}"
    package="com.amazon.webservices.ecs"
    wsdl="wsdl/AWSECommerceService.wsdl"/>
</target>

但没有为以下元素生成 Java 工件,如下所示:

but no java artifacts are generated for the following element which look like this:

<xs:element name="Condition">
    <xs:simpleType>
        <xs:restriction base="xs:string">
            <xs:enumeration value="All"/>
            <xs:enumeration value="New"/>
            <xs:enumeration value="Used"/>
            <xs:enumeration value="Collectible"/>
            <xs:enumeration value="Refurbished"/>
       </xs:restriction>
   </xs:simpleType>
</xs:element>

即使生成了所有其他元素,基本上也不会生成枚举.有没有人见过这个问题?我正在使用 jax-ws ri 2.2.1 http://jax-ws.java.net/2.2.1/
谢谢

Basically no enums are generated even though all other elements are generated. Has anyone seen this problem before? I'm using jax-ws ri 2.2.1 http://jax-ws.java.net/2.2.1/
Thanks

推荐答案

正如 Puspendu 所引用的,JAXB 客户端定制的绑定完全/非常接近您的需求——您需要使用 JAX-WS 客户端定制来实现你的例子.JAXB 和 JAX-WS 定制本质上允许您扩充您无法控制的 WSDL/模式的模式元素定义.您可以完成许多不同的事情,例如将 xml 元素名称映射到自定义 java 元素、更改生成的 API 以及回答您的问题、为受枚举限制的元素生成类型安全的枚举类.

as referenced by Puspendu, JAXB client customization of the binding is exactly/pretty close to what you need -- you need to use a JAX-WS client customization for your example. JAXB and JAX-WS customizations essentially allows you to augment the definition of schema elements for WSDL/schema's that you do not control. there are MANY different things you can accomplish such as mapping xml element names to custom java elements, altering the generated API, and to answer your question, generating type-safe enum classes for elements that are restricted with an enum.

有两种方法/部分可以为 JAX-WS 进行客户端定制.

There are two ways/parts to doing a client customization for JAX-WS.

1) 如果 WSDL 导入外部模式文件2) 如果 WSDL 包含没有任何导入的整个模式定义

1) if the WSDL imports an external schema file 2) if the WSDL contains the entire schema definition without any imports

如果 wsdl 导入一个外部模式文件,

if the wsdl imports an external schema file then,

基本上,您需要创建一个新文件(通常带有 jxb 扩展名,但实际上并不重要),您将与正在为其生成客户端存根/api 的 wsdl 一起维护.通常我将这些文件命名为 schema-file-name_clientcustomization.jxb

basically you need to create a new file (typically with a jxb extension, but it really doesn't matter) that you will maintain along side the wsdl you are generating the client stub/api for. typically I name these files schema-file-name_clientcustomization.jxb

每次获得更新的 wsdl 时,您都应该验证您的 JXB 文件对于该 wsdl 仍然有效.我发现要寻找的最重要的事情,尤其是枚举限制,是限制值更改、命名空间更改、类型名称更改等.

every time you get an updated wsdl, you should validate that your JXB file is still valid for that wsdl. The biggest things I've found to look for, especially with enum restrictions, is restricted value changes, namespace changes, type name changes, etc..

这个新文件的内容类似于:

the content of this new file will look something similar to this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<jxb:bindings 
  xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
  xmlns:jxb="http://java.sun.com/xml/ns/jaxb"     
  targetNamespace="http://java.sun.com/xml/ns/jaxb" 
   version="1.0">

    <jxb:bindings schemaLocation="NameOfYourSchemaFile.xsd" 
         node="/xsd:schema[@targetNamespace='SCHEMANAMESPACE']">
        <jxb:schemaBindings>
            <jxb:package name="com.amazon.webservices.ecs" />
        </jxb:schemaBindings>

        <jxb:bindings node="xsd:element[@name='Condition']/xsd:simpleType">
            <jxb:typesafeEnumClass name="ConditionEnum" >
                <jxb:typesafeEnumMember value="All" name="ALL" />
                <jxb:typesafeEnumMember value="New" name="NEW" />
                <jxb:typesafeEnumMember value="Used" name="USED" />
                <jxb:typesafeEnumMember value="Collectible" name="COLLECTIBLE" />
                <jxb:typesafeEnumMember value="Refurbished" name="REFURBISHED" />
            </jxb:typesafeEnumClass>
        </jxb:bindings>
         </jxb:bindings>
</jxb:bindings>

本质上,这个文件定义了应该对引用的 xsd 文件进行的扩充.此文件中的所有 bindings 元素都有一个 node 属性,它是一个 XPATH 表达式,用于选择您要扩充的架构项.在示例中,我没有任何命名空间或其他信息,因此我指定了 XPATH 以仅选择元素的简单类型声明.在该绑定中,我们定义了 typesafeenum 类,这会导致 jaxb/wsimport 生成一个枚举类来表示引用的简单类型.因为它是一个匿名的简单类型,所以它有效地为引用的元素定义了一个类.生成的类将是一个 ENUM,其成员由 typesafeEnumMember 元素的name"属性定义.

Essentially this file defines augmentation that should be done to the referenced xsd file. all bindings elements in this file have a node attribute which is an XPATH expression that selects the schema item that you want to augment. in the example, I don't have any namespace or other information so I specified the XPATH to select just the element's simple type declaration. within that binding, we define the typesafeenumclass, this causes the jaxb/wsimport to generate an enum class to represent the referenced simple type. since it's an anonymous simple type, this effectively defines a class just for the referenced element. The generated class will be an ENUM who's memebers are defined by the "name" attribute of the typesafeEnumMember element.

要使用这个 JXB 文件,你需要在你的 ant 任务中引用它,就像这样:

to use this JXB file, you need to reference it in your ant task, like so:

<wsimport
        debug="true"
    keep="true"
    verbose="true"
    destdir="${generated.src}"
    package="com.amazon.webservices.ecs"
    wsdl="wsdl/AWSECommerceService.wsdl">

    <binding dir="wsdl" includes="*.jxb"/>

</wsimport>

如果 WSDL 在内部定义了整个模式,那么您需要使用 JAX-WS 定制文件.这个案例与您的问题相符.

if the WSDL defines the entire schema internally, then you need to use a JAX-WS customization file. This case is what matches your question.

http://jax-ws.java.net/nonav/2.1.7/docs/customizations.html

JAX-WS 客户端定制与 JAXB 定制非常相似.这个想法是相同的,在大多数情况下,定制文件的 JAX-WS 部分将更改与 WSDL 特定相关的生成工件,而嵌入式 JAXB 定制执行与外部定制文件相同的功能:它更改基于生成的对象在架构上.

JAX-WS client customization is very similar to the JAXB customization. The idea is identical, for the most part the JAX-WS portion of the customization file will alter generated artifacts that are specifically related to WSDL, whereas the embedded JAXB customization performs the same function as an external customization file: it alters the generated objects based on the schema.

最大的不同在于,不是告诉 JAXB 解析器模式文件在哪里,而是提供一个绑定部分,用于选择要应用自定义的模式定义(使用 XPATH).

The big difference is that rather than tell the JAXB parser where the schema file is, you provide a binding section that selects the schema definition (using XPATH) that you want to apply customization to.

我实际测试并验证了这个示例,为您提出问题的元素生成一个 Enum 类,因此您可以逐字复制这个 JAX-WS 自定义示例.

This example I actually tested and verified to generate an Enum class for the element you are asking questions about, so you can copy this JAX-WS customization example verbatim.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<jaxws:bindings
        wsdlLocation="AWSECommerceService.wsdl" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    >

    <jaxws:bindings node="wsdl:definitions/wsdl:types/xsd:schema[@targetNamespace='http://webservices.amazon.com/AWSECommerceService/2010-11-01']">
        <jaxb:schemaBindings>
            <jaxb:package name="com.amazon.webservices.ecs"/>
        </jaxb:schemaBindings>


        <jaxb:bindings node="xsd:element[@name='Condition']/xsd:simpleType">
            <jaxb:typesafeEnumClass name="ConditionEnum" >
                <jaxb:typesafeEnumMember value="All" name="ALL" />
                <jaxb:typesafeEnumMember value="New" name="NEW" />
                <jaxb:typesafeEnumMember value="Used" name="USED" />
                <jaxb:typesafeEnumMember value="Collectible" name="COLLECTIBLE" />
                <jaxb:typesafeEnumMember value="Refurbished" name="REFURBISHED" />
            </jaxb:typesafeEnumClass>
        </jaxb:bindings>

    </jaxws:bindings>

</jaxws:bindings>

然后您可以像引用 JXB 文件一样引用此 JAX-WS 定制文件.

you would then reference this JAX-WS customization file the same way you would reference the JXB file.

我没有验证独立的 JAXB 定制示例,因为我实际上只是将它作为示例和 JAX-WS 定制示例的前导解释包含在内.

I did not validate the standalone JAXB customization example, since I really only included it as an example and as a precursor explanation for the JAX-WS customization example.

我确实针对您链接的 WSDL 进行了实际测试/验证的 JAX-WS 定制示例,因此您应该能够将其用作起点.我注意到定义的 WSDL 中有许多枚举限制,因此我假设您希望为大多数/全部生成枚举.

The JAX-WS customization example I did actually test/validate against the WSDL you have linked, so you should be able to use it as a starting point. I noticed that there are numerous enumerated restrictions in the defined WSDL, so I would assume you'll want to generate enums for most/all of them.

我希望这会有所帮助.

这篇关于jax-ws ri 2.2.1 没有为亚马逊 ecs wsdl 文件生成枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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