【问题标题】:jaxb binding customization without having xsd没有 xsd 的 jaxb 绑定自定义
【发布时间】:2013-04-03 16:43:16
【问题描述】:

我有一个 wsdl(我没有 .xsd 文件),我想从中生成类。 使用 wsimport 我得到一个类树,它是 Web 服务模式本身及其依赖项的标准映射。 我得到了 com->(microsoft,mycompany), org->(apache) 之类的东西。

但是我需要将包 com.mycompany 和里面的所有类重新映射到 com.mycompany.test 中。

所以我尝试使用 ws import 的 -b 选项创建一个 docbinding.xml,它是模式自定义 XML。内容是:

<jxb:bindings version="2.1"  xmlns:jxb="http://java.sun.com/xml/ns/jaxb"     xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jxb:bindings node="wsdl:definitions/wsdl:types/xsd:schema[@targetNamespace='http://mycompany.com/test/']">
 <jaxb:package name="com.mycompany.test"/>
</jxb:bindings>
</jxb:bindings>

使用这种语法启动 wsimport:

wsimport -p com.mycompany -b docbinding.xml https://mycompany.com/nicews/test.svc?wsdl

我收到一个停止生成类的初始错误:

[ERROR] XPath error: null
...

如何修复绑定 XML?

【问题讨论】:

    标签: xsd jaxb wsdl wsimport


    【解决方案1】:

    如果类型位于单独的 XSD 文件中。这就是这样做的方法。

    创建两个配置文件。

    wsdl.jxb

    <?xml version="1.0" encoding="UTF-8"?>
    <jaxws:bindings
      xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
      wsdlLocation="https://mycompany.com/nicews/test.svc?wsdl"
      xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
        <jaxws:package name="com.mycompany.wsdl"/> <!-- namespace what you want here -->
    </jaxws:bindings>
    

    xsds.jxb

    <?xml version="1.0" encoding="UTF-8"?>
    <jaxb:bindings version="2.1"
               xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
               xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
               xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
               xmlns:xs="http://www.w3.org/2001/XMLSchema" >
    
        <!-- This is used becuase we don't need to differentiate between absent and nil elements, you may want to differentiate.  If so, remove this binding -->
        <jaxb:globalBindings generateElementProperty="false">
          <xjc:simple />
        </jaxb:globalBindings>  
    
        <!-- REPEAT THIS SECTION FOR EACH XSD, replacing schemaLocation and package with whatever you want -->
        <jaxb:bindings
               schemaLocation="http://mycompany.com/someWsdlIncludeLocation?xsd=xsd0"
               node="/xs:schema">
              <jaxb:schemaBindings>
            <jaxb:package name="com.mycompany.dto.saml" />
              </jaxb:schemaBindings>
        </jaxb:bindings>
        <!-- END SECTION -->
    </jaxb:bindings>
    

    在同一目录下创建批处理文件

    rmdir /S /Q build
    rmdir /S /Q dist
    rmdir /S /Q src
    mkdir build
    mkdir dist
    mkdir src
    "%JAVA_HOME%\bin\wsimport.exe" -b wsdl.jxb -b xsds.jxb -s src -d build -keep http://mycompany.com/someWSDLlocation?wsdl
    "%java_home%\bin\jar" cf dist/mycompanyClient.jar -C build/ .
    "%java_home%\bin\jar" cf dist/mycompanyClient-src.jar -C src/ .
    

    看看这是否适合你。确保为您的 wsdl/xsd 位置和所需的包适当地编辑 JXB 文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-10
      相关资源
      最近更新 更多