java 如何使用 JAXWS/JAXB 重命名参数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1477436/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 16:41:21  来源:igfitidea点击:

how to Use JAXWS/JAXB rename the parameter

javajaxbjax-ws

提问by jojo

I use CXF(2.2.3) to compile the Amazon Web Service WSDL (http://s3.amazonaws.com/ec2-downloads/2009-07-15.ec2.wsdl)

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

But got error as below.

但得到如下错误。

Parameter: snapshotSet already exists for method describeSnapshots but of type com.amazonaws.ec2.doc._2009_07_15.DescribeSnapshotsSetType instead of com.amazonaws.ec2.doc._2009_07_15.DescribeSnapshotsSetResponseType. Use a JAXWS/JAXB binding customization to rename the parameter.

参数:snapshotSet 已存在于方法 describeSnapshots 但类型为 com.amazonaws.ec2.doc._2009_07_15.DescribeSnapshotsSetType 而不是 com.amazonaws.ec2.doc._2009_07_15.DescribeSnapshotsSetResponseType。使用 JAXWS/JAXB 绑定定制来重命名参数。

The conflict was due to the data type show below:

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

<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>

I create a binding file try to address the issue...but it didn`t do the job

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

   <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>

And the command i used, was like below

我使用的命令如下所示

<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>

What is wrong with my code????

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

And you can check out my project by using svn.... svn co http://shrimpysprojects.googlecode.com/svn/trunk/smartcrc/AWSAgent/

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

采纳答案by MJB

This part

这部分

<enableWrapperStyle>false</enableWrapperStyle>

<enableWrapperStyle>false</enableWrapperStyle>

should be

应该

<jaxws:enableWrapperStyle>false</jaxws:enableWrapperStyle>

<jaxws:enableWrapperStyle>false</jaxws:enableWrapperStyle>

回答by Ricahard van den den berg

In your binding file, you use xs:.....but the reference of namespace http://www.w3.org/2001/XMLSchemais xdsso if it is not working try to rename the reference xsdto xs(by the way thanks for the solution, it works)

在你的绑定文件,可以使用xs:.....,但命名空间的参考http://www.w3.org/2001/XMLSchemaxds如此,如果它不能正常工作尝试重命名参考xsd,以xs(感谢解决方案的方式通过,它的工作原理)

回答by Chris

As @PascalThivent mentioned, CXF has a parameter, -autoNameResolution, that you should try using. The message given by CXF when it encounters this, unfortunately does not mention it.

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

回答by albfan

For anyone trying this: I summarize all the corrections:

对于尝试此操作的任何人:我总结了所有更正:

<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>