绑定jaxws中的文件类型转换被忽略

时间:2013-08-21 15:58:12

标签: java maven jax-ws jax-ws-customization

我正在尝试使用外部绑定文件将XMLGregorianCalendar转换为java.util.Date,但它没有转换,它重新映射XMLGregorianCalendar而不是java.util.Date,任何人都可以发现我做错了吗?我怀疑在我的绑定文件中有些东西是不正确的,因为它在生成pojos时被拾取。

绑定文件:

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

在调用构建脚本时使用-X向我显示它正在被拾取 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 个答案:

答案 0 :(得分:1)

添加node="wsdl:definitions/wsdl:types/xs:schema"jaxws:globalBindings应该可以解决问题,因此绑定文件应如下所示:

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