Search code examples
javaweb-serviceswsdlwsimport

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


I have a not accurate WSDL from web-service provider. I use wsimport and would like to create proper external binding file. My current efforts are not very valuable now.

So I have wsimport as plugin in my pom-file:

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

After start I have the following warnings:

[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

At this point I then add the following binding file:

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

And now I get an error:

[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

Could someone can help me to resolve the issue? Live WSDL you can try here: https://api.casebook.ru/WebService.svc?singleWsdl


Solution

  • The proper solution I found here: https://blogs.oracle.com/geertjan/error-two-declarations-cause-a-collision-in-the-objectfactory-class

    All conflicts were solved by the the following:

    1. I received all xsd as separate files from my wsdl through SoapUI (it is fast solution, however in the future I'd found how to access them through wsdl's url)
    2. delete all xsd shemas from WSDL. In other case the classes will be duplicated.
    3. all xsd-classes I put in separate packages, also add some suffix.

    So my proper binding file is this:

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

    My plugin configuration in pom-file is this:

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