Binding File type conversions in jaxws being ignored

2.6k views Asked by At

I'm trying to convert XMLGregorianCalendar to java.util.Date using an external binding file, but it's not converting, it remaind XMLGregorianCalendar instead of java.util.Date, can anyone spot what I'm doing wrong? I'm suspecting something is not right in my binding file since it is being picked up when generating the pojos.

Binding File:

<?xml version="1.0" encoding="UTF-8" ?> 
<jaxws:bindings version="2.0" 
    xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">

    <jaxws:globalBindings> 

        <jaxws:javaType name="java.util.Date" xmlType="xsd:dateTime" 
            parseMethod="javax.xml.bind.DatatypeConverter.parseDateTime" 
            printMethod="javax.xml.bind.DatatypeConverter.printDateTime"/>

        <jaxws:javaType name="java.util.Date" xmlType="xsd:time" 
            parseMethod="javax.xml.bind.DatatypeConverter.parseTime" 
            printMethod="javax.xml.bind.DatatypeConverter.printTime"/>

        <jaxws:javaType name="java.util.Date" xmlType="xsd:date" 
            parseMethod="javax.xml.bind.DatatypeConverter.parseDate" 
            printMethod="javax.xml.bind.DatatypeConverter.printDate"/> 

    </jaxws:globalBindings>

 </jaxws:bindings>  

profile in pom.xml:

 <profiles>
    <profile>
      <id>website</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <build>
        <pluginManagement>
          <plugins>
            <plugin>
              <groupId>org.jvnet.jax-ws-commons</groupId>
              <artifactId>jaxws-maven-plugin</artifactId>
              <version>2.2</version>
            </plugin>
          </plugins>
        </pluginManagement>
        <plugins>
          <plugin>
            <groupId>org.jvnet.jax-ws-commons</groupId>
            <artifactId>jaxws-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>wsimport</id>
                <phase>generate-sources</phase>
                <goals>
                  <goal>wsimport</goal>
                </goals>
                <configuration>
                  <packageName>za.co.website.application.model</packageName>
                  <sourceDestDir>src/main/java</sourceDestDir>
                  <wsdlFiles>
                    <wsdlFile>
                      ${basedir}/src/jaxws/wsdl/Application.wsdl
                    </wsdlFile>
                  </wsdlFiles>
                  <target>2.1</target>
                  <bindingFiles>
                    <bindingFile>
                        ${basedir}/src/jaxws/binding/bindings.xml
                    </bindingFile>
                  </bindingFiles>                 
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

Using -X when calling the build script shows me that it's being picked up mvn clean install -DskipTest -X

...
[DEBUG] The wsdl File is '...\website-application/src/jaxws/wsdl/Application.wsdl' from 'file:/.../website-application/src/jaxws/wsdl/Application.wsdl'
[INFO] Processing: file:/.../website-application/src/jaxws/wsdl/Application.wsdl
[DEBUG] jaxws:wsimport args: [-keep, -s, ...\website-application\src\main\java, -encoding, UTF-8, -Xnocompile, -p, za.co.website.application.model, -target, 2.1, -b, ...\website-application\src\jaxws\binding\bindings.xml]
[INFO] jaxws:wsimport args: [-keep, -s, ...\website-application\src\main\java, -encoding, UTF-8, -Xnocompile, -p, za.co.website.application.model, -target, 2.1, -b, ...\website-application\src\jaxws\binding\bindings.xml, file:/.../website-application/src/jaxws/wsdl/Application.wsdl]
parsing WSDL...
...
1

There are 1 answers

0
Jonas On BEST ANSWER

Adding node="wsdl:definitions/wsdl:types/xs:schema" and jaxws:globalBindings should do the trick, so the binding file should look like this:

<?xml version="1.0" encoding="UTF-8" ?> 
<jaxws:bindings version="2.0" 
      xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
      xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      node="wsdl:definitions/wsdl:types/xs:schema">

    <jaxws:globalBindings> 
        <jaxws:javaType name="java.util.Date" xmlType="xsd:dateTime" 
            parseMethod="javax.xml.bind.DatatypeConverter.parseDateTime" 
            printMethod="javax.xml.bind.DatatypeConverter.printDateTime"/>
        <jaxws:javaType name="java.util.Date" xmlType="xsd:time" 
            parseMethod="javax.xml.bind.DatatypeConverter.parseTime" 
            printMethod="javax.xml.bind.DatatypeConverter.printTime"/>
        <jaxws:javaType name="java.util.Date" xmlType="xsd:date" 
            parseMethod="javax.xml.bind.DatatypeConverter.parseDate" 
            printMethod="javax.xml.bind.DatatypeConverter.printDate"/> 
    </jaxws:globalBindings>
</jaxws:bindings>