CXF: How to change package of WSDL imported XML Schema using JAXB external binding file?
I have a WSDL file which imports several XML Schemas, each of them having the same namespace (let's call it A). I'm trying to use a JAXB external binding file to change the generated package name (to let's say B) for those schemas. Here is an example:
I have a POM file containing the configuration for code generation from WSDL (using the cxf-codegen-plugin).
My WSDL:
<definitions ...>
<types>
<xsd:schema开发者_StackOverflow中文版 elementFormDefault="qualified" targetNamespace="C">
<xsd:import namespace="A" schemaLocation="SCHEMA_REF"/>
<xsd:import namespace="A" schemaLocation="SCHEMA_REF"/>
...
</xsd:schema>
</types>
...
</definitions>
Here is my actual binding file which does not work at all, it seems it is not applied at all (no error message...).
<jaxws:bindings wsdlLocation="WSDL_LOCATION" xmlns:jaxws="http://java.sun.com/xml/ns/jaxws" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" jaxb:version="2.0">
<jaxws:bindings node="wsdl:definitions/wsdl:types/xs:schema[@targetNamespace='C']/xs:import[@namespace='A']">.
<jaxb:schemaBindings>
<jaxb:package name="B" />
</jaxb:schemaBindings>
</jaxws:bindings>
</jaxws:bindings>
As I don't have any error message in the generation maybe it is because the XPath expression used to access to the imported schema is not good...
Do you guys have any clue? I am kind of stuck here...
Thanks in advance for your inputs!
Try writing your bindings as-if the schema-import were merged into the WSDL document, by referencing its namespace directly:
<jaxws:bindings wsdlLocation="WSDL_LOCATION"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
jaxb:version="2.0">
<jaxws:bindings
node="wsdl:definitions/wsdl:types/xs:schema[@targetNamespace='A']">
<jaxb:schemaBindings>
<jaxb:package name="B" />
</jaxb:schemaBindings>
</jaxws:bindings>
</jaxws:bindings>
This worked for me. Kudos to this post which demonstrates working with an imported schema.
Interestingly, you've got no answers :) Unfortunately it is not possible to archive what you want. The only way is to define separate binding files for each schema file you have, that will work fine.
精彩评论