简体   繁体   中英

jaxb binding customization without having xsd

I've a wsdl (I dont have the .xsd file) and I want to generate the classes from it. Using wsimport I get a tree of classes that is the standard mapping of the webservice schemas itself and of its dependencies. I obtain something like com->(microsoft,mycompany), org->(apache).

However I need to remap the package com.mycompany and all the classes inside into com.mycompany.test.

So I've tried to use the option of -b of ws import creating aa docbinding.xml that is Schema Customization XML. The content is :

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

launching wsimport with this syntax :

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

I obtain a initial error that stops the generation of the classes:

[ERROR] XPath error: null
...

How can I fix the binding XML ?

If the types are in seperate XSD files. This is the way to do it.

Create two configuration files.

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>

Create a batch file in the same directory

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/ .

See if that works for you. Make sure to edit the JXB files appropriately for your wsdl/xsd locations, and packages you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM