I'm using maven-jaxb2-plugin for generating java files from wsdl one. After running "generate-sources" goal I get the following error
[ERROR] Error while parsing schema(s).Location[
file:/home/*/src/main/resources/soap/binding.xjb{8,30} ].
com.sun.istack.SAXParseException2; systemId: file:/home/*/src/main/resources/soap/binding.xjb; lineNumber: 8; columnNumber: 30;
Multiple <schemaBindings> are defined for the target namespace "http://schemas.***"
There are several wsdl files and for each of them I need different target package, so I tried using binding file, but for only 1 wsdl for now.
Here is my plugin configuraiton
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<schemaDirectory>
${basedir}/src/main/resources/soap
</schemaDirectory>
<schemaIncludes>
<include>manager/*.wsdl</include>
</schemaIncludes>
<bindingDirectory>
${basedir}/src/main/resources/soap
</bindingDirectory>
</configuration>
Here is binding.xjb file
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings
version="2.1"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jaxb:bindings schemaLocation="manager/service.wsdl" multiple="true" node="//xs:schema">
<jaxb:schemaBindings>
<jaxb:package name="com.test.manager"/>
</jaxb:schemaBindings>
</jaxb:bindings>
</jaxb:bindings>
Beginning of service.wsdl file
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:sch0="http://schemas.***"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://schemas.***"
targetNamespace="http://schemas.***">
<wsdl:types>
<xs:schema xmlns="http://schemas.***"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
attributeFormDefault="unqualified"
elementFormDefault="qualified"
targetNamespace="http://schemas.***">
<xs:simpleType name="NumericReference">
***
</xs:simpleType>
<xs:simpleType name="EntityNumber">
***
</xs:simpleType>
</xs:schema>
<xs:schema xmlns="http://schemas.***"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
attributeFormDefault="unqualified"
elementFormDefault="qualified"
targetNamespace="http://schemas.***">
<xs:complexType name="DisplayGroup">
Looks like the problem is connected with multiple xs:schema elements with same targetNamespace, but I can't find how to fix it without modifying wsdl.
JAXB typically maps one target namespace onto one package, so you can't specify different schemaBindings for the same target namespace.
Related
I have got the JAXB bindings config file like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="2.1">
<jaxb:globalBindings generateElementProperty="false">
<jaxb:javaType name="java.util.Date" xmlType="xs:dateTime"
parseMethod="com.utils.EmptyDateTimeAdapter.parseDateTime"
printMethod="com.utils.EmptyDateTimeAdapter.printDateTimeWithZone"/>
<xjc:serializable uid="-1"/>
</jaxb:globalBindings>
</jaxb:bindings>
In xml above I declared that every wsdl dateTime element will be parsed by these methods.
My question is:
How can I change this JAXB config file to specify multiple parse methods for element type per package name or per wsdl?
<jaxws:bindings wsdlLocation="SampleService.wsdl"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<jaxws:bindings node="wsdl:definitions/wsdl:types/xs:schema[#targetNamespace='http://example.com/service/SampleService/']">
<jxb:globalBindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jxb:javaType name="java.util.Date" xmlType="xs:date"
parseMethod="org.apache.cxf.tools.common.DataTypeAdapter.parseDateTime"
printMethod="org.apache.cxf.tools.common.DataTypeAdapter.printDateTime"/>
</jxb:globalBindings>
</jaxws:bindings>
</jaxws:bindings>
references :
JBoss Community Archive (Read Only)
JAXB bindings and xs:date to java.util.Date
Custom Jax-b bindings for xs:date to JAVA 8 java.time.LocalDate using Adapter
I'm trying to generate the java files from XSD with use of jaxb2-maven-plugin. This works without any issues and I can see generated classes in target directory.
Now I decided to let all generated classes implement some interface. So I set up bindings.xjb file where I'm defining the interface. The issue is the plugin can not recognize correct namespace which defines inheritance.
Unsupported binding namespace "http://jaxb2-commons.dev.java.net/basic/inheritance". Perhaps you meant "http://jaxb.dev.java.net/plugin/code-injector"?
I think code-injector is not what I'm looking for, since this allow to define custom pieces of code to add to generated file.
I'm trying to use latest maven plugin:
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>3.1.0</version>
The bindings.xjb file contains following content:
<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings xmlns:jaxb="https://jakarta.ee/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
jaxb:extensionBindingPrefixes="inheritance"
version="3.0">
<jaxb:bindings schemaLocation="application.xsd" node="/xs:schema">
<jaxb:bindings node="//xs:complexType[#name='applicationType']">
<inheritance:implements>com.example.SomeInterface</inheritance:implements>
<jaxb:property name="inheritance"/>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
And the application.xsd file:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="application" type="applicationType"/>
<xs:complexType name="applicationType">
<xs:sequence>
<xs:element type="xs:string" name="language"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
I have found this namespace xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance" on the internet.
Also notice plugin requires version 3.0 of bindings.xjb file.
What is the correct definition of namespace to let plugin generate classes with interface?
In my project, classes are generated by wsdl. One of these classes is User class. This class must be Serializable. How can I change my pom.xml file for making User Serializable?
I can find example but can't apply it to my project
https://pragmaticintegrator.wordpress.com/2009/03/14/make-serializable-jax-ws-clients-with-maven2/
Finally I could find answer for my question. In our project we use org.apache.cxf plugin to generate classes. I created binding.xml file in resources folder.
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
elementFormDefault="qualified" attributeFormDefault="unqualified"
jaxb:extensionBindingPrefixes="xjc" jaxb:version="2.1">
<xs:annotation>
<xs:appinfo>
<jaxb:globalBindings>
<xjc:serializable uid="1337" />
</jaxb:globalBindings>
</xs:appinfo>
</xs:annotation>
</xs:schema>
Then I referenced to this xml file from my pom.xml, for this I added
<bindingFiles>
<bindingFile>${basedir}/src/main/resources/binding.xml</bindingFile>
</bindingFiles>
under wsdlOptions/wsdlOption tag. That's all
I'm generating java classes from xsd with cxf-xjc-plugin.
<?xml version="1.0" encoding="utf-16"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="result">
...
</xsd>
I'm trying to rename the root element using a jaxb-binding.xml file:
<jaxb:bindings
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jaxb:extensionBindingPrefixes="xjc"
jaxb:version="2.1">
<jaxb:bindings schemaLocation="xsd/myxsd.xsd" node="//xsd:element[#name='result']">
<jaxb:class name="MyNewName" />
</jaxb:bindings>
</jaxb:bindings>
But it does not work. The generated java class is named Result. What might be wrong here?
I am using wsimport
I need to rename a xs:complextype name=Address to prevent some build conflicts.
Here is a snippet of the 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>
I am using an external binding file:
<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>
When I execute the build I get the following message:
[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
I have looked at the following postings here, here and a couple of references as well reference 1 and reference 2
But do not understand as to why this is not working.
After taking a breather I was able to solve the issue my taking a second look at this.
So my resulting binding is:
<?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>