使用JAX-WS构建存根时出错:“两个​​声明导致冲突......”

时间:2014-03-03 11:58:53

标签: xml jax-ws

我试图在第三方的WSDL文件上使用JAX-WS,但是我收到错误(详情如下)。任何人都可以帮我弄清楚出了什么问题,以及如何解决它?

编辑:我可以编译,但我不喜欢修复,我特别不喜欢我不理解修复。见下文。

[WARNING] src-resolve.4.2: Error resolving component 'q1:CorrectRequest'. It was detected that 'q1:CorrectRequest' is in namespace 'http://schemas.datacontract.org/2004/07/Satori.Infuse.Single', but components from this namespace are not referenceable from schema document 'file:/Users/itunesuser/git/listiq/iac-extension/src/main/resources/com/satorisoftware/ws/infuseiac/intladdresscorrection/intladdresscorrection.wsdl#types?schema1'. If this is the incorrect namespace, perhaps the prefix of 'q1:CorrectRequest' needs to be changed. If this is the correct namespace, then an appropriate 'import' tag should be added to 'file:/Users/itunesuser/git/listiq/iac-extension/src/main/resources/com/satorisoftware/ws/infuseiac/intladdresscorrection/intladdresscorrection.wsdl#types?schema1'.
  line 98 of file:/Users/itunesuser/git/listiq/iac-extension/src/main/resources/com/satorisoftware/ws/infuseiac/intladdresscorrection/intladdresscorrection.wsdl#types?schema1

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 356 of file:/Users/itunesuser/git/listiq/iac-extension/src/main/resources/com/satorisoftware/ws/infuseiac/intladdresscorrection/intladdresscorrection.wsdl

[ERROR] (Related to above error) This is the other declaration.   
  line 98 of file:/Users/itunesuser/git/listiq/iac-extension/src/main/resources/com/satorisoftware/ws/infuseiac/intladdresscorrection/intladdresscorrection.wsdl

这是第98行的出现

<xsd:schema xmlns:ser="http://schemas.microsoft.com/2003/10/Serialization/"
    elementFormDefault="qualified" targetNamespace="infuse.satorisoftware.com/2012/08">
    <xsd:element name="Correct">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element
                    xmlns:q1="http://schemas.datacontract.org/2004/07/Satori.Infuse.Single"
                    minOccurs="0" name="request" nillable="true" type="q1:CorrectRequest" />
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>

    (MORE xsd ELEMENTS)

</xsd:schema>

这里是第356行的出现

<xsd:schema
    xmlns:tns="http://schemas.datacontract.org/2004/07/Satori.Infuse.Single"
    elementFormDefault="qualified"
    targetNamespace="http://schemas.datacontract.org/2004/07/Satori.Infuse.Single">
    <xsd:complexType name="CorrectRequest">
        <xsd:sequence>
            <xsd:element minOccurs="0" name="Client" nillable="true"
                type="xsd:string" />
            <xsd:element xmlns:q5="infuse.satorisoftware.com/2012/08"
                minOccurs="0" name="Input" nillable="true" type="q5:RecordBlock" />
            <xsd:element minOccurs="0" name="OutputFields"
                nillable="true" type="tns:ArrayOfInfuseField" />
            <xsd:element minOccurs="0" name="ReferenceString"
                nillable="true" type="xsd:string" />
            <xsd:element xmlns:q6="infuse.satorisoftware.com/2012/08"
                minOccurs="0" name="Settings" type="q6:Settings" />
        </xsd:sequence>
    </xsd:complexType>
    <xsd:element name="CorrectRequest" nillable="true" 
        type="tns:CorrectRequest" />

    (MORE xsd ELEMENTS)

</xsd:schema>

编辑:如果我更改元素的名称,它会编译,但我想找到一个更好的修复,并了解为什么这个修复有效。

    <xsd:element name="CorrectRequestElement" nillable="true" 
        type="tns:CorrectRequest" />

1 个答案:

答案 0 :(得分:2)

所以:警告真的不那么有趣。重要的是错误。

错误试图告诉我们:

  

“嗨!我是JAXB,我无法弄清楚如何命名我的Java类   从WSDL生成而不会出现名称冲突。 HERP! DERP!“

解决方案是使用绑定文件,这基本上是一种使用与JAXB相关的指令来注释(或修补)WSDL文件的方法。

Here's a nice end-to-end example with lots of background information.

在我的特殊情况下,我需要做两件事:

  1. 制作绑定文件
  2. 对我的POM进行更改,以便在WSDL处理阶段使用绑定文件
  3. 绑定文件:

    我的目标是告诉JAXB我希望它为WSDL文件的这一部分使用不同的Java类名称:

    <xsd:element name="CorrectRequest" nillable="true" 
            type="tns:CorrectRequest" />
    

    这样可以解决问题:

    <bindings xmlns="http://java.sun.com/xml/ns/jaxb" 
        xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
        xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.1"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <bindings schemaLocation="../resources/com/satorisoftware/ws/infuseiac/intladdresscorrection/intladdresscorrection.wsdl#types?schema3" version="1.0">
            <schemaBindings>
                <package name="com.satorisoftware.ws.infuseiac-intladdresscorrection" />
            </schemaBindings>
    
            <!-- rename the value element -->
            <bindings node="//xsd:element[@name='CorrectRequest']">
                    <class name="CorrectRequestElement" />
            </bindings>
        </bindings>
    </bindings>
    

    更新POM:

    我在相关构建阶段添加了bindingsFiles条目:

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>jaxws-maven-plugin</artifactId>
        <version>1.12</version>
        <executions>
            <execution>
                <id>import-iac-wsdl</id>
                <phase>generate-sources</phase>
                <goals>
                    <goal>wsimport</goal>
                </goals>
                <inherited>false</inherited>
                <configuration>
                    <packageName>com.satorisoftware.ws.infuseiac.intladdresscorrection</packageName>
                    <wsdlLocation>com/satorisoftware/ws/infuseiac/intladdresscorrection/intladdresscorrection.wsdl</wsdlLocation>
                    <staleFile>${project.build.directory}/jaxws/stale/wsdl.intladdresscorrection.done</staleFile>
                    <sourceDestDir>${project.build.directory}/generated/jaxws-infuseiac-intladdresscorrection</sourceDestDir>
                    <wsdlDirectory>src/main/resources/com/satorisoftware/ws/infuseiac/intladdresscorrection</wsdlDirectory>
                    <bindingFiles>
                        <!-- See http://www.jroller.com/gmazza/entry/enhancing_jaxb_artifacts#BindingFile 
                        for an end-to-end-example of doing bindings files for WSDL files. -->
                        <bindingFile>${basedir}/src/main/bindings/bindings-intladdresscorrection.xjb</bindingFile>
                    </bindingFiles>
                    <!-- <wsdlUrls> <value>https://infuseiac.satorisoftware.com/wsdl/IntlAddressCorrection.2012.12.wsdl</value> 
                        </wsdlUrls> -->
    
                    <!-- Generate JAX-WS 2.0 compatible stubs -->
                    <target>2.0</target>
                </configuration>
            </execution>
        </executions>
    </plugin>