Java wsimport。不准确的WSDL。如何创建适当的外部绑定文件?

时间:2018-01-24 13:56:03

标签: java web-services wsdl wsimport

我有来自网络服务提供商的不准确的WSDL。我使用 wsimport 并希望创建适当的外部绑定文件。我目前的努力现在不是很有价值。

所以我在我的pom文件中将wsimport作为插件:

      <plugin>
            <groupId>org.jvnet.jax-ws-commons</groupId>
            <artifactId>jaxws-maven-plugin</artifactId>
            <version>2.3</version>
            <executions>
                <execution>
                    <id>wsimport-from-jdk</id>
                    <goals>
                        <goal>wsimport</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>

                <!--<wsdlUrls>-->
                <!--<wsdlUrl>-->
                <!--https://api.casebook.ru/WebService.svc?singleWsdl-->
                <!--</wsdlUrl>-->
                <!--</wsdlUrls>-->

                <wsdlDirectory>src/main/resources/wsdl</wsdlDirectory>

                <wsdlFiles>
                    <wsdlFile>WebServiceSVC.wsdl</wsdlFile>
                </wsdlFiles>
                <vmArgs>
                    <vmArg>-Djavax.xml.accessExternalSchema=all</vmArg>
                </vmArgs>

                <keep>true</keep>
                <verbose>true</verbose>

                <packageName>com.kirillch.objs</packageName>

                <sourceDestDir>target/generatedclasses</sourceDestDir>

                <bindingDirectory>
                    ${basedir}/src/main/resources/bindings
                </bindingDirectory>

                <bindingFiles>
                    <bindingFile>bindings.xjb</bindingFile>
                </bindingFiles>

            </configuration>

        </plugin>

开始后,我有以下警告:

  

[警告] src-resolve:无法解析名称   &#39; CheckShortBankruptInfoRequest&#39;到(n)&#39;类型定义&#39;组件。
  第53行   文件:/ d:/dev/test-prj/iRule/PravoRu/src/main/resources/wsdl/WebServiceSVC.wsdl#types schema1

此时我添加以下绑定文件:

<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings version="2.1"
               xmlns:jaxb="http://java.sun.com/xml/ns/jaxb">

    <jaxb:bindings schemaLocation="file:../wsdl/WebServiceSVC.wsdl#types?schema1">
        <jaxb:bindings node="//xsd:element[@name='CheckShortBankruptInfoRequest']">
            <jaxb:class name="CheckShortBankruptInfoRequestEl"/>
        </jaxb:bindings>
    </jaxb:bindings>

</jaxb:bindings>

现在我收到一个错误:

  

[ERROR] XPath错误:   com.sun.org.apache.xpath.internal.domapi.XPathStylesheetDOM3Exception:   前缀必须解析为命名空间:xsd第6行   文件:/ d:/dev/test-prj/iRule/PravoRu/src/main/resources/bindings/bindings.xjb

有人可以帮我解决这个问题吗? 您可以在此处尝试实时WSDL:https://api.casebook.ru/WebService.svc?singleWsdl

1 个答案:

答案 0 :(得分:0)

我在这里找到了正确的解决方案:https://blogs.oracle.com/geertjan/error-two-declarations-cause-a-collision-in-the-objectfactory-class

所有冲突都通过以下方式解决:

  1. 我通过SoapUI从wsdl收到所有xsd作为单独的文件(这是快速解决方案,但是将来我发现如何通过wsdl&#39; url找到它们)
  2. 从WSDL中删除所有xsd shemas。在其他情况下,类将被复制。
  3. 我把所有xsd-classes放在单独的包中,也添加了一些后缀。
  4. 所以我的正确绑定文件是这样的:

    <?xml version="1.0" encoding="UTF-8"  standalone="yes"?>
    <jaxb:bindings version="2.1"
                   xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    
        <jaxb:bindings
                schemaLocation="../xsd/egrul.xsd">
            <jaxb:schemaBindings>
                <jaxb:package name="ru.spi2.javaee.custom.pravoru.classes.egrul"/>
                <jaxb:nameXmlTransform>
                    <jaxb:typeName suffix="Type"/>
                    <jaxb:elementName suffix="Element"/>
                </jaxb:nameXmlTransform>
            </jaxb:schemaBindings>
        </jaxb:bindings>
    
        <jaxb:bindings
                schemaLocation="../xsd/egrip.xsd">
            <jaxb:schemaBindings>
                <jaxb:package name="ru.spi2.javaee.custom.pravoru.classes.egrip"/>
                <jaxb:nameXmlTransform>
                    <jaxb:typeName suffix="Type"/>
                    <jaxb:elementName suffix="Element"/>
                </jaxb:nameXmlTransform>
            </jaxb:schemaBindings>
        </jaxb:bindings>
         ...
    
    </jaxb:bindings>
    

    我在pom文件中的插件配置如下:

         <plugin>
                <groupId>org.jvnet.jax-ws-commons</groupId>
                <artifactId>jaxws-maven-plugin</artifactId>
                <version>2.3</version>
                <configuration>
    
                    <!--<wsdlUrls>-->
                    <!--<wsdlUrl>-->
                    <!--https://api.casebook.ru/WebService.svc?singleWsdl-->
                    <!--</wsdlUrl>-->
                    <!--</wsdlUrls>-->
    
                    <wsdlDirectory>src/main/resources/wsdl</wsdlDirectory>
    
                    <wsdlFiles>
                        <wsdlFile>WebServiceSVC.wsdl</wsdlFile>
                    </wsdlFiles>
                    <vmArgs>
                        <vmArg>-Djavax.xml.accessExternalSchema=all</vmArg>
                    </vmArgs>
                    <args>
                        <arg>-B-XautoNameResolution</arg>
                        <arg>-XadditionalHeaders</arg>
                    </args>
                    <extension>true</extension>
    
                    <keep>true</keep>
                    <verbose>true</verbose>
    
                    <!--<packageName>ru.spi2.javaee.custom.pravoru.ws</packageName>-->
    
                    <sourceDestDir>target/generatedclasses</sourceDestDir>
    
                    <bindingDirectory>
                        src/main/resources/binding
                    </bindingDirectory>
    
                    <bindingFiles>
                        <bindingFile>bindings.xjb</bindingFile>
                        <bindingFile>../xsd/egrul.xsd</bindingFile>
                        <bindingFile>../xsd/arrays.xsd</bindingFile>
                        <bindingFile>../xsd/BankruptMessages.xsd</bindingFile>
                        <bindingFile>../xsd/CommonData.xsd</bindingFile>
                        <bindingFile>../xsd/CommonModels.xsd</bindingFile>
                        <bindingFile>../xsd/CommonSqlData.xsd</bindingFile>
                        <bindingFile>../xsd/egrip.xsd</bindingFile>
                        <bindingFile>../xsd/enums.xsd</bindingFile>
                        <bindingFile>../xsd/FNSModel.xsd</bindingFile>
                        <bindingFile>../xsd/message.xsd</bindingFile>
                        <bindingFile>../xsd/organizations.xsd</bindingFile>
                        <bindingFile>../xsd/serialization.xsd</bindingFile>
                        <bindingFile>../xsd/ServiceModels.xsd</bindingFile>
                        <bindingFile>../xsd/system.xsd</bindingFile>
                        <bindingFile>../xsd/tempuri.xsd</bindingFile>
                        <bindingFile>../xsd/UIFounders.xsd</bindingFile>
                        <bindingFile>../xsd/ULFounders.xsd</bindingFile>
                        <bindingFile>../xsd/WSModels.xsd</bindingFile>
                        <bindingFile>../xsd/Types.xsd</bindingFile>
                    </bindingFiles>
    
                </configuration>
                <executions>
                    <execution>
                        <id>wsimport-from-jdk</id>
                        <goals>
                            <goal>wsimport</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>