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

Java wsimport. Not accurate WSDL. How to create proper external binding file?

我从网络服务提供商那里得到了一个不准确的 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>

启动后出现以下警告:

[WARNING] src-resolve: Cannot resolve the name 'CheckShortBankruptInfoRequest' to a(n) 'type definition' component.
line 53 of file:/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 error: com.sun.org.apache.xpath.internal.domapi.XPathStylesheetDOM3Exception: Prefix must resolve to a namespace: xsd line 6 of file:/D:/dev/test-prj/iRule/PravoRu/src/main/resources/bindings/bindings.xjb

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

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

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

  1. 我通过 SoapUI 从我的 wsdl 中收到了所有 xsd 作为单独的文件(这是快速的解决方案,但是在未来我找到了如何通过 wsdl 的 url 访问它们)
  2. 从 WSDL 中删除所有 xsd shemas。在其他情况下,类 将被复制。
  3. 全部xsd-类我是分开打包的,也加了一些后缀。

所以我正确的绑定文件是这样的:

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