如何在存根生成期间重命名WSDL中的复杂类型

时间:2013-08-22 21:01:41

标签: java binding jaxb wsdl wsimport

我正在使用wsimport

我需要重命名xs:complextype name = Address以防止一些构建冲突。

以下是WSDL的片段:

<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:ns="http://fedex.com/ws/rate/v13" xmlns:s1="http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace="http://fedex.com/ws/rate/v13" name="RateServiceDefinitions">
  <types>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://fedex.com/ws/rate/v13">
      <xs:complexType name="Address">…</xs:complexType>
    ....
   </types>
   ....
</definitions>

我正在使用外部绑定文件:

<jxb:bindings 
    xmlns="http://schemas.xmlsoap.org/wsdl/"
    xmlns:ns="http://fedex.com/ws/rate/v13"
    xmlns:s1="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
    xmlns:jxb="http://java.sun.com/xml/ns/jaxb" jxb:version="2.1"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    >

    <jxb:globalBindings>
        <jxb:javaType name="java.util.Calendar" xmlType="xs:dateTime" parseMethod="javax.xml.bind.DatatypeConverter.parseDateTime" printMethod="javax.xml.bind.DatatypeConverter.printDateTime" />
    </jxb:globalBindings>
   <jxb:bindings node="definitions/types/xs:schema/xs:complexType[@name='Address']/xs:complexType">
        <!-- change java method name from addNumbers() to add() -->
        <jxb:class name="FedExAddress"/>
    </jxb:bindings>
</jxb:bindings>

当我执行构建时,我收到以下消息:

[wsimport] [ERROR] XPath evaluation of "definitions/types/xs:schema/xs:complexType[@name='Address']/xs:complexType" results in empty target node
 [wsimport]   line 14 of file:/Users/davidboyd/projects/heritage/hybris/bin/custom/cpdeliveryservice/fedex_binding.xml

我查看了以下帖子herehere以及一些参考资料reference 1reference 2

但是不明白为什么这不起作用。

1 个答案:

答案 0 :(得分:1)

在休息之后,我能够解决这个问题,然后我再看this

所以我的结果是:

<?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:jxb="http://java.sun.com/xml/ns/jaxb" jxb:version="2.1"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    wsdlLocation="/RateService_v13.wsdl"
    >

    <enableWrapperStyle>true</enableWrapperStyle>
    <enableAsyncMapping>false</enableAsyncMapping>

    <!-- convert all xs:dateTime to java type of Calendar -->
    <jaxws:globalBindings>
        <jxb:javaType name="java.util.Calendar" xmlType="xs:dateTime" parseMethod="javax.xml.bind.DatatypeConverter.parseDateTime" printMethod="javax.xml.bind.DatatypeConverter.printDateTime" />
    </jaxws:globalBindings>

    <!-- Rename Address to FedExAddress -->
    <jaxws:bindings node="//xs:complexType[@name='Address']">
        <jxb:class name="FedExAddress"/>
    </jaxws:bindings>

</jaxws:bindings>