0

Request Schema -

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://www.G9.Request.com" xmlns:tns="http://www.G9.Request.com">
<xsd:complexType abstract="false" block="#all" final="#all" mixed="false" name="ProgramInterface">

Response Schema -

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://www.G9.Response.com" xmlns:tns="http://www.G9.Response.com">
<xsd:complexType abstract="false" block="#all" final="#all" mixed="false" name="ProgramInterface">

I am using maven-jaxb2-plugin plugin to generate jaxb classes. I am looking to generate ProgramInterfaceInput as my request class and ProgramInterfaceReponse as my response class in com.wsdl package in Target directory.

Below is my POM and bindings.xjb contents -

<plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <version>0.13.1</version>
                <executions>
                    <execution>
                        <id>G9-schema-generate</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <schemaLanguage>WSDL</schemaLanguage>
                              <schemas>
                                 <schema>
                                     <url>http://abc.xyzcorp.com:10000/ABC/G9?wsdl</url>
                                 </schema>
                             </schemas>
                            <bindingFiles>
                                <bindingFile>${basedir}/src/main/resources/bindings.xjb</bindingFile>
                            </bindingFiles>
                           <generateDirectory>${project.build.directory}/generated-sources/xjc2</generateDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>

bindings.xjb

<jxb:bindings
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
        xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
        version="2.1">

    <jaxws:bindings wsdlLocation="http://abc.xyzcorp.com:10000/ABC/G9?wsdl">
        <jaxws:bindings
                node="//xsd:schema[@targetNamespace='http://www.G9.Request.com']/xsd:complexType[@name='ProgramInterface']">
            <jxb:schemaBindings>
                <jxb:package name="com.wsdl"/>
                <jxb:nameXmlTransform>
                    <jxb:typeName suffix="Request"/>
                </jxb:nameXmlTransform>
            </jxb:schemaBindings>
        </jaxws:bindings>
        <jaxws:bindings
                node="//xsd:schema[@targetNamespace='http://www.G9.Response.com']/xsd:complexType[@name='ProgramInterface']">
            <jxb:schemaBindings>
                <jxb:package name="com.wsdl"/>
                <jxb:nameXmlTransform>
                    <jxb:typeName suffix="Response"/>
                </jxb:nameXmlTransform>
            </jxb:schemaBindings>
        </jaxws:bindings>
    </jaxws:bindings>

This is not giving me desired result. It ends up created two packages as -

com.request.g9 - ProgramInterface.java
com.response.g9 - ProgramInterface.java

What I want is -

com.wsdl - ProgramInterfaceRequest.java & ProgramInterfaceResponse.java

Please advice.

Khuzi
  • 2,792
  • 3
  • 15
  • 26
  • Try to attach `schemaBindings` to the `xsd:schema` element, not `xsd:complexType`. And only once. – lexicore Mar 08 '18 at 16:49
  • Tried, does not work. It is still creating in default package with default class names. I am suspicious of my binding.xjb file, if it is even referred. Have I correctly referred it in pom file? I do get compilattion errors if I mess up with the file. But not sure if its getting referred during classes generation. If I change bindings file path in pom, it is not complaining to me. Its still going and creating classes. – Khuzi Mar 08 '18 at 17:04
  • No, `bindingFiles` is not correct. It's `bindingIncludes` or `bindings`, see https://github.com/highsource/maven-jaxb2-plugin/wiki/Configuration-Cheat-Sheet. But `**/*.xjb` is used by default so your bindings file should have been considered. – lexicore Mar 08 '18 at 17:11
  • I'd rather tip on `jaxws:bindings` vs. `jxb:bindings`, something like this. But I don't have much experience compiling WSDLs. – lexicore Mar 08 '18 at 17:12
  • `jxb:bindings` is not able to evaluate xpath expression on wsdl file. `jaxws` is able to do so. – Khuzi Mar 08 '18 at 18:58

0 Answers0