.... .... .... .... .... ....

Using jaxws plugin to generate Java classes from WSDL that will implement common interface via bindigs

158 Views Asked by At

I have wsdl file with following types:

<xs:complexType name="someName">
....
</xs:complexType>

<xs:complexType name="someOtherName">
....
</xs:complexType>

What I am trying to achieve is for this types to implement common interface

public interface Test {
//methods that already exist in the types
}

To achieve this, I created binding file:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxws:bindings
        xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
        xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
        xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
        xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
        jaxb:extensionBindingPrefixes="xjc inheritance"
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        wsdlLocation="my_wsdl.wsdl">

    <enableWrapperStyle>true</enableWrapperStyle>
    <enableAsyncMapping>false</enableAsyncMapping>
    <jaxws:bindings node="//xs:complexType[@name='someName']">
        <inheritance:implements>com.mycompany.package.Test</inheritance:implements>
    </jaxws:bindings>
</jaxws:bindings>

and also configured plugin:

                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>jaxws-maven-plugin</artifactId>
                    <version>${jaxws-maven-plugin.version}</version>
                    <dependencies>
                        <dependency>
                            <groupId>org.jvnet.jaxb2_commons</groupId>
                            <artifactId>jaxb2-basics</artifactId>
                            <version>0.6.4</version>
                        </dependency>
                    </dependencies>
                    <executions>
                        <execution>
                            <id>wsdl</id>
                            <goals>
                                <goal>wsimport</goal>
                            </goals>
                            <configuration>
                                <xjcArgs>
                                    <xjcArg>-Xinheritance</xjcArg>
                                    <xjcArg>-Xequals</xjcArg>
                                    <xjcArg>-XtoString</xjcArg>
                                </xjcArgs>
                                <genJWS>true</genJWS>
                                <bindingDirectory>${basedir}/src/main/resources/soap</bindingDirectory>
                                <bindingFiles>
                                    <bindingFile>binding.xjb</bindingFile>
                                </bindingFiles>
                                <xnocompile>true</xnocompile>
                                <xdebug>true</xdebug>
                                <verbose>true</verbose>
                                <wsdlUrls>
                                    <wsdlUrl>${project.basedir}/src/main/resources/soap/my_wsdl.wsdl</wsdlUrl>
                                </wsdlUrls>
                                <sourceDestDir>target/generated-sources/soap</sourceDestDir>
                            </configuration>
                        </execution>
                    </executions>
                    <extensions>true</extensions>
                </plugin>

The flags

<xjcArg>-Xequals</xjcArg>
<xjcArg>-XtoString</xjcArg>

are taken into account, and my generated classes have following signature:

public class SomeName implements ToString, Equals{...}

but, the -Xinheritance option, even though taken into account (before I added dependency on jaxb2-basics, it was complaining about unknown option) is not having any effect on the code generation. the XPath in bindings is correct, and binding is taken into account for example, if instead of

<inheritance:implements>com.mycompany.package.Test</inheritance:implements>

I provide:

<jaxb:class name="changedName"/>

class will be generated with changed name, but they will still not implement the interface that I want.

Do you have any ideas what is wrong? I suspect issue is with binding file, but I cannot pin-point exact location.

1

There are 1 best solutions below

6
Laurent Schoelens On

You can try to follow this wiki page about the inheritence plugin in the official repository.

From what I see the main difference is the jaxws/jaxb prefix used in bindings.

You can also try to add extra debug in your maven build using -X -e options to see debug output during classes generation.

You can follow this migration guide on how to get the latest version of the jaxb-tools which is now all merged into the same location.

If it still doesnt work, come back and I'll look deeper, and if necessary, I'll create an issue in jaxb-tools' github repo

EDIT

After debugging the wsimport, it seems that the extensionBindingPrefixes attribute you can set in jaxb:bindings is not taken into account when defined in jaxws:bindings and it seems to be by design according XSD

A binding compiler only processes this attribute when it occurs on an instance of xs:schema element. The value of this attribute is a whitespace-separated list of namespace prefixes. The namespace bound to each of the prefixes is designated as a customization declaration namespace.

If you want to use bindings to customize the output with extensionBindingPrefixes plugins, you need to externalize the XSD into is own file and then use the standard jaxb:bindings process.

The section of wsdl:types should look like the following :

    <wsdl:types>
        <xsd:schema>
            <xsd:import namespace="http://www.cleverbuilder.com/BookService/" schemaLocation="my_xsd.xsd" />
        </xsd:schema>
    </wsdl:types>

And the my_xsd.xsd file would contain the schema definition elements.

This also explains why defining it inline the WSDL makes it work (since the extensionBindingPrefixes has been defined on xs:schema)