【问题标题】:wsimport Two declarations cause a collisionwsimport 两个声明导致冲突
【发布时间】:2017-03-21 13:16:08
【问题描述】:

我正在尝试在 https://api.sendwordnow.com/webservices/v3/users.svc?wsdl 上使用 wsimport。这是我正在使用的 wsimport。

wsimport -B-XautoNameResolution -d C:\temp -extension -J-Djavax.xml.accessExternalSchema=all -J-Djavax.xml.accessExternalDTD=all -keep -verbose -XadditionalHeaders -Xnocompile https://api.sendwordnow.com/webservices/v3/users.svc?wsdl

这是错误。

正在解析 WSDL...

    [WARNING] unknown extensibility element or attribute "EndpointReference" 
    (in namespace "http://www.w3.org/2005/08/addressing") line 1 of 
    https://api.sendwordnow.com/webservices/v3/users.svc?wsdl
    [ERROR] Two declarations cause a collision in the ObjectFactory class. 
    line 1 of https://api.sendwordnow.com/webservices/v3/Users.svc?xsd=xsd3
    [ERROR] (Related to above error) This is the other declaration. 
    line 1 of https://api.sendwordnow.com/webservices/v3/Users.svc?xsd=xsd3
    [ERROR] Two declarations cause a collision in the ObjectFactory class. 
    line 1 of https://api.sendwordnow.com/webservices/v3/Users.svc?xsd=xsd2
    [ERROR] (Related to above error) This is the other declaration. 
    line 1 of https://api.sendwordnow.com/webservices/v3/Users.svc?xsd=xsd2
    Exception in thread "main" com.sun.tools.internal.ws.wscompile.AbortException 
    at com.sun.tools.internal.ws.processor.modeler.wsdl.JAXBModelBuilder.bind(JAXBModelBuilder.java:129)at
    com.sun.tools.internal.ws.processor.modeler.wsdl.WSDLModeler.buildJAXBModel(WSDLModeler.java:2283)
    at com.sun.tools.internal.ws.processor.modeler.wsdl.WSDLModeler.internalBuildModel(WSDLModeler.java:183)
    at com.sun.tools.internal.ws.processor.modeler.wsdl.WSDLModeler.buildModel(WSDLModeler.java:126)
    at com.sun.tools.internal.ws.wscompile.WsimportTool.buildWsdlModel(WsimportTool.java:429)
    at com.sun.tools.internal.ws.wscompile.WsimportTool.run(WsimportTool.java:190)
    at com.sun.tools.internal.ws.wscompile.WsimportTool.run(WsimportTool.java:168) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:498) at 
    com.sun.tools.internal.ws.Invoker.invoke(Invoker.java:159) at 
    com.sun.tools.internal.ws.WsImport.main(WsImport.java:42)

我在 StackOverflow 上四处搜索,发现 wsimport - Two declarations cause a collision, same line given 但这是 4 年前的,我不知道该分辨率是否仍然适用。建议是删除我所做的 -p 但我仍然收到上述错误。关于我做错了什么的任何想法?我可以将 wsdl 插入 SoapUI 并生成测试存根,但我似乎无法克服 wsimport 驼峰。

更新 1 我也尝试过使用模式绑定。

<?xml version="1.0" encoding="UTF-8"?>
<jxb:bindings version="1.0"
              xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
              xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <jxb:bindings schemaLocation="https://api.sendwordnow.com/webservices/v3/Users.svc?xsd=xsd0">
        <jxb:schemaBindings>
            <jxb:package name="com.users" />
        </jxb:schemaBindings>
    </jxb:bindings>
    <jxb:bindings schemaLocation="https://api.sendwordnow.com/webservices/v3/Users.svc?xsd=xsd1">
        <jxb:schemaBindings>
            <jxb:package name="com.serialization"/>
        </jxb:schemaBindings>
    </jxb:bindings>
    <jxb:bindings schemaLocation="https://api.sendwordnow.com/webservices/v3/Users.svc?xsd=xsd2">
        <jxb:schemaBindings>
            <jxb:package name="com.datacontractsv2"/>
        </jxb:schemaBindings>
    </jxb:bindings>    
    <jxb:bindings schemaLocation="https://api.sendwordnow.com/webservices/v3/Users.svc?xsd=xsd3">
        <jxb:schemaBindings>
            <jxb:package name="com.datacontractsv1"/>
        </jxb:schemaBindings>
    </jxb:bindings>
    <jxb:bindings schemaLocation="https://api.sendwordnow.com/webservices/v3/Users.svc?xsd=xsd4">
        <jxb:schemaBindings>
            <jxb:package name="com.arrays"/>
        </jxb:schemaBindings>
    </jxb:bindings>
    <jxb:bindings schemaLocation="https://api.sendwordnow.com/webservices/v3/Users.svc?xsd=xsd5">
        <jxb:schemaBindings>
            <jxb:package name="com.location"/>
        </jxb:schemaBindings>
    </jxb:bindings>
    <jxb:bindings schemaLocation="https://api.sendwordnow.com/webservices/v3/Users.svc?xsd=xsd6">
        <jxb:schemaBindings>
            <jxb:package name="com.datacontractsv3"/>
        </jxb:schemaBindings>
    </jxb:bindings>
</jxb:bindings>

这是更新后的 wsimport。

wsimport -b "C:\temp\Customization.xml" -B-XautoNameResolution -d C:\temp -extension -J-Djavax.xml.accessExternalSchema=all -J-Djavax.xml.accessExternalDTD=all -keep -verbose -XadditionalHeaders -Xnocompile https://api.sendwordnow.com/webservices/v3/users.svc?wsdl

我仍然收到与上述相同的错误消息。

更新 2 终于通过以下更新解决了。

<jxb:bindings schemaLocation="https://api.sendwordnow.com/webservices/v3/Users.svc?xsd=xsd2">
    <jxb:schemaBindings>
        <jxb:package name="com.datacontractsv2"/>
        <jxb:nameXmlTransform>
            <jxb:typeName suffix="Type" /> 
            <jxb:elementName suffix="Element"/> 
        </jxb:nameXmlTransform>
    </jxb:schemaBindings>
</jxb:bindings>    
<jxb:bindings schemaLocation="https://api.sendwordnow.com/webservices/v3/Users.svc?xsd=xsd3">
    <jxb:schemaBindings>
        <jxb:package name="com.datacontractsv1"/>
        <jxb:nameXmlTransform>
            <jxb:typeName suffix="Type" /> 
            <jxb:elementName suffix="Element"/> 
        </jxb:nameXmlTransform>
    </jxb:schemaBindings>
</jxb:bindings>

我不能 100% 确定这是最好的甚至是正确的解决方案,但是错误已经消失并生成了代码。

【问题讨论】:

    标签: java xml web-services soap xsd


    【解决方案1】:

    这是我使用的最后一个 wsimport。

    wsimport -b "C:\temp\Customization.xml" -B-XautoNameResolution -d C:\temp -extension -J-Djavax.xml.accessExternalSchema=all -J-Djavax.xml.accessExternalDTD=all -keep -verbose -XadditionalHeaders -Xnocompile https://api.sendwordnow.com/webservices/v3/users.svc?wsdl
    

    这是自定义绑定 xml。我希望这对其他人有帮助。解决这个问题真的很痛苦!

    <?xml version="1.0" encoding="UTF-8"?>
    <jxb:bindings version="1.0"
                  xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
                  xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <jxb:bindings schemaLocation="https://api.sendwordnow.com/webservices/v3/Users.svc?xsd=xsd0">
            <jxb:schemaBindings>
                <jxb:package name="com.users" />
            </jxb:schemaBindings>
        </jxb:bindings>
        <jxb:bindings schemaLocation="https://api.sendwordnow.com/webservices/v3/Users.svc?xsd=xsd1">
            <jxb:schemaBindings>
                <jxb:package name="com.serialization"/>
            </jxb:schemaBindings>
        </jxb:bindings>
        <jxb:bindings schemaLocation="https://api.sendwordnow.com/webservices/v3/Users.svc?xsd=xsd2">
            <jxb:schemaBindings>
                <jxb:package name="com.datacontractsv2"/>
                <jxb:nameXmlTransform>
                    <jxb:typeName suffix="Type" /> 
                    <jxb:elementName suffix="Element"/> 
                </jxb:nameXmlTransform>
            </jxb:schemaBindings>
        </jxb:bindings>    
        <jxb:bindings schemaLocation="https://api.sendwordnow.com/webservices/v3/Users.svc?xsd=xsd3">
            <jxb:schemaBindings>
                <jxb:package name="com.datacontractsv1"/>
                <jxb:nameXmlTransform>
                    <jxb:typeName suffix="Type" /> 
                    <jxb:elementName suffix="Element"/> 
                </jxb:nameXmlTransform>
            </jxb:schemaBindings>
        </jxb:bindings>
        <jxb:bindings schemaLocation="https://api.sendwordnow.com/webservices/v3/Users.svc?xsd=xsd4">
            <jxb:schemaBindings>
                <jxb:package name="com.arrays"/>
            </jxb:schemaBindings>
        </jxb:bindings>
        <jxb:bindings schemaLocation="https://api.sendwordnow.com/webservices/v3/Users.svc?xsd=xsd5">
            <jxb:schemaBindings>
                <jxb:package name="com.location"/>
            </jxb:schemaBindings>
        </jxb:bindings>
        <jxb:bindings schemaLocation="https://api.sendwordnow.com/webservices/v3/Users.svc?xsd=xsd6">
            <jxb:schemaBindings>
                <jxb:package name="com.datacontractsv3"/>
            </jxb:schemaBindings>
        </jxb:bindings>
    </jxb:bindings>
    

    【讨论】:

    • 我有类似的问题,但我不知道你是怎么解决的?你能给我一些解决方案的描述吗?
    • 我试图重现您的解决方案,以使 wsimport 在另一个我遇到问题的 wsdl 上工作。我收到了这个错误:[ERROR] file:/C:/temp/.xml.accessExternalSchema=all is unreachable wsimport 版本是 2.2.9
    • 找出我收到该错误的原因。它在 PowerShell 中不起作用。
    猜你喜欢
    • 2012-08-06
    • 2019-06-23
    • 2012-11-05
    • 1970-01-01
    • 1970-01-01
    • 2016-01-06
    • 2011-11-21
    • 2013-04-04
    • 2011-06-27
    相关资源
    最近更新 更多