【问题标题】:how to Use JAXWS/JAXB rename the parameter如何使用 JAXWS/JAXB 重命名参数
【发布时间】:2009-09-25 13:57:09
【问题描述】:

我使用 CXF(2.2.3) 编译 Amazon Web Service WSDL (http://s3.amazonaws.com/ec2-downloads/2009-07-15.ec2.wsdl)

但出现如下错误。

参数:snapshotSet 已经存在 对于方法 describeSnapshots 但 类型 com.amazonaws.ec2.doc._2009_07_15.DescribeSnapshotsSetType 代替 com.amazonaws.ec2.doc._2009_07_15.DescribeSnapshotsSetResponseType。 使用 JAXWS/JAXB 绑定定制 重命名参数。

冲突是由于数据类型如下所示:

<xs:complexType name="DescribeSnapshotsType">
                <xs:sequence>
                    <xs:element name="snapshotSet" type="tns:DescribeSnapshotsSetType"/>
                </xs:sequence>
            </xs:complexType>

<xs:complexType name="DescribeSnapshotsResponseType">
                <xs:sequence>
                    <xs:element name="requestId" type="xs:string"/>
                    <xs:element name="snapshotSet" type="tns:DescribeSnapshotsSetResponseType"/>
                </xs:sequence>
            </xs:complexType>

我创建了一个绑定文件试图解决这个问题......但它没有完成这项工作

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

    <enableWrapperStyle>false</enableWrapperStyle>
    <jaxws:bindings node="wsdl:definitions/wsdl:types/xs:schema[@targetNamespace='http://ec2.amazonaws.com/doc/2009-07-15/']">
     <jxb:bindings node="xs:complexType[@name='tns:DescribeSnapshotsType']//xs:element[@name='snapshotSet']">
         <jxb:property name="snapshotRequestSet"/>
     </jxb:bindings>
     <jxb:bindings node="xs:complexType[@name='DescribeSnapshotsResponseType']//xs:element[@name='snapshotSet']">
         <jxb:property name="snapshotResponseSet"/>
     </jxb:bindings>     
    </jaxws:bindings>
</jaxws:bindings>

我使用的命令如下所示

<wsdlOptions>
     <wsdlOption>
          <wsdl>${basedir}/src/main/resources/wsdl/EC2_2009-07-15.wsdl</wsdl>
          <extraargs>
            <extraarg>-b</extraarg>
            <extraarg>${basedir}/src/main/resources/wsdl/Bindings_EC2_2009-07-15.xml</extraarg>
          </extraargs>
    </wsdlOption>
</wsdlOptions>

我的代码有什么问题????

您可以使用 svn.... 查看我的项目。 svn cohttp://shrimpysprojects.googlecode.com/svn/trunk/smartcrc/AWSAgent/

【问题讨论】:

  • 奇怪,wsdl2java 标志-autoNameResolution 应该自动解决冲突...顺便说一句,您的自定义绑定有什么问题?你有同样的错误吗?

标签: java jaxb jax-ws


【解决方案1】:

正如@PascalThivent 提到的,CXF 有一个参数 -autoNameResolution,您应该尝试使用它。 CXF遇到这个时给的消息,可惜没有提及。

【讨论】:

    【解决方案2】:

    在您的绑定文件中,您使用xs:.....,但命名空间http://www.w3.org/2001/XMLSchema 的引用是xds,因此如果它不起作用,请尝试将引用xsd 重命名为xs (顺便感谢您的解决方案,它有效)

    【讨论】:

      【解决方案3】:

      这部分

      &lt;enableWrapperStyle&gt;false&lt;/enableWrapperStyle&gt;

      应该是

      &lt;jaxws:enableWrapperStyle&gt;false&lt;/jaxws:enableWrapperStyle&gt;

      【讨论】:

        【解决方案4】:

        对于任何尝试这个的人:我总结了所有的更正:

        <jaxws:bindings
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
        wsdlLocation="EC2_2009-07-15.wsdl"
        xmlns="http://java.sun.com/xml/ns/jaxws"
        xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
        xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
        
        <jaxws:enableWrapperStyle>false</jaxws:enableWrapperStyle>
        <jaxws:bindings node="wsdl:definitions/wsdl:types/xs:schema[@targetNamespace='http://ec2.amazonaws.com/doc/2009-07-15/']">
         <jxb:bindings node="xs:complexType[@name='tns:DescribeSnapshotsType']//xs:element[@name='snapshotSet']">
             <jxb:property name="snapshotRequestSet"/>
         </jxb:bindings>
         <jxb:bindings node="xs:complexType[@name='DescribeSnapshotsResponseType']//xs:element[@name='snapshotSet']">
             <jxb:property name="snapshotResponseSet"/>
         </jxb:bindings>     
        </jaxws:bindings>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2012-12-07
          • 1970-01-01
          • 2013-02-12
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-04-06
          相关资源
          最近更新 更多