I have a WSDL file which contains the following entry:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="urn:CP_Ablakido" xmlns:s0="urn:CP_Ablakido" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<xsd:schema elementFormDefault="qualified" targetNamespace="urn:CP_Ablakido">
<xsd:element name="GetList_11" type="s0:InputMapping1"/>
<xsd:complexType name="InputMapping1">
<xsd:sequence>
<xsd:element name="Qualification" type="xsd:string"/>
<xsd:element name="startRecord" type="xsd:string"/>
<xsd:element name="maxLimit" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="GetList_11Response" type="s0:OutputMapping1"/>
<xsd:complexType name="OutputMapping1">
<xsd:sequence>
<xsd:element maxOccurs="unbounded" name="getListValues">
<xsd:complexType>....
I use the CXF Codegen plugin with the following settings:
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${basedir}/target/generated-sources/wsdl2java</sourceRoot>
<encoding>UTF-8</encoding>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
And the generated java code look like:
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "OutputMapping1", propOrder = {
"getListValues"
})
public class OutputMapping1 {
#XmlElement(required = true)
protected List<OutputMapping1 .GetListValues> getListValues;
The problem is that the #XmlRootElement is missing from here. There was another similar questions like
maven-cxf-codegen-plugin using Jaxb binding to add inheritance for all generated classes
Annotating CXF (wsdl2java) generated package
externally create jaxb annotations for class
As the other answers mentioned that I can put bindings file.
So I created a binding file with the following content:
<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"
xmlns:annox="http://annox.dev.java.net"
version="2.0">
<jaxb:bindings node="//xsd:element[#name='GetList_11Response']">
<annox:annotate target="class">
<annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="GetList_11Response"/>
</annox:annotate>
</jaxb:bindings>
</jaxb:bindings>
And I've added the following block to POM.XML:
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/wsdl/CP_Ablakido_1.wsdl</wsdl>
<bindingFiles>
<bindingFile>${basedir}/src/main/resources/wsdl/CP_Ablakido_1.xjb
</bindingFile>
</bindingFiles>
</wsdlOption>
</wsdlOptions>
After that I've got error message:
com.sun.istack.SAXParseException2; systemId: file:/Project/icp-integration/icpiCameI/src/main/resources/wsdl/CP_Ablakido_1.xjb; lineNumber: 9; columnNumber: 72; XPath evaluation of "//xs:element[#name='GetList_11Response']" results in empty target node
at com.sun.tools.xjc.reader.internalizer.Internalizer.reportError(Internalizer.java:624)
at com.sun.tools.xjc.reader.internalizer.Internalizer.reportError(Internalizer.java:618)
at com.sun.tools.xjc.reader.internalizer.Internalizer.buildTargetNodeMap(Internalizer.java:294)
at com.sun.tools.xjc.reader.internalizer.Internalizer.buildTargetNodeMap(Internalizer.java:390)
at com.sun.tools.xjc.reader.internalizer.Internalizer.transform(Internalizer.java:146)
So I don't know how exactly can I describe that when the complexType is OutputMapping1 then put #XmlRootElement in OutputMapping1.java with the name of "GetList_11Response".
I found the solution. It was trickey, because:
Have to handle that the XSD is inlined in WSDL. (The trick is schemaLocation="CP_Ablakido_1.wsdl#types1". It tells the JAXB that use node in WSDL file.)
Have to configure CXF to use XJC plugin (annox).
Have to add the following fragments to POM.XML:
<wsdlOption>
<wsdl>${basedir}/src/main/resources/wsdl/CP_Ablakido_1.wsdl</wsdl>
<bindingFiles>
<bindingFile>${basedir}/src/main/resources/wsdl/CP_Ablakido_1.xjb</bindingFile>
</bindingFiles>
<extraargs><extraarg>-xjc-Xannotate</extraarg></extraargs>
</wsdlOption>
and dependencies have to add to plugin:
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-annotate</artifactId>
<version>0.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.cxf.xjcplugins</groupId>
<artifactId>cxf-xjc-ts</artifactId>
<version>3.0.5</version>
</dependency>
The XJB file:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings version="2.0"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
jaxb:extensionBindingPrefixes="annox xjc"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:annox="http://annox.dev.java.net"
xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance">
<jaxb:bindings schemaLocation="CP_Ablakido_1.wsdl#types1" node="/xs:schema">
<jaxb:bindings node="//xs:complexType[#name='InputMapping1']">
<annox:annotate target="class">
<annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="GetList_11"/>
</annox:annotate>
</jaxb:bindings>
<jaxb:bindings node="//xs:complexType[#name='OutputMapping1']">
<annox:annotate target="class">
<annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="GetList_11Response"/>
</annox:annotate>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
#du-it As I understand, you don't want to apply XmlRootElement to all of the classes automatically.
This is the reason:
https://community.oracle.com/blogs/kohsuke/2006/03/03/why-does-jaxb-put-xmlrootelement-sometimes-not-always
Therefore, doing it for each type separately is the proper way to do it.
Related
We are attempting to generate Java classes from this wsdl file: http://ws.infotorg.no/xml/NE/EDROnline/2017-01-23/EDROnline.wsdl.
To do generate the code we use maven as a build tool, where we have specified the following build plugin:
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>3.5.3</version>
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-bindings-soap</artifactId>
<version>3.5.3</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>wsdl2java</goal>
</goals>
<configuration>
<sourceRoot>${project.build.directory}/generated-sources/src</sourceRoot>
<wsdlOptions>
<wsdlOption>
<extraargs>
<extraarg>-verbose</extraarg>
<extraarg>-autoNameResolution</extraarg>
</extraargs>
<wsdl>${basedir}/src/main/resources/wsdl/EDROnline.wsdl</wsdl>
<wsdlLocation>classpath:wsdl/EDROnline.wsdl</wsdlLocation>
<bindingFiles>
<bindingFile>${basedir}/src/main/resources/bindings.xml</bindingFile>
</bindingFiles>
</wsdlOption>
</wsdlOptions>
</configuration>
</execution>
</executions>
</plugin>
We run mvn clean package to execute the build.
We obtain the following errors:
https://ws.infotorg.no/xml/EVRY/InfotorgForetak/2015-12-01/include/ResultatregnskapOgBalanse.xsd [0,0]: Property "Aar" is already defined. Use <jaxb:property> to resolve this conflict.
https://ws.infotorg.no/xml/EurotaxGlass/Bruktbilverdi/2016-03-09/Bruktbilverdi.xsd [0,0]: Property "Error" is already defined. Use <jaxb:property> to resolve this conflict.
We see in the following stackoverflow answer: XSD "property already defined" that these errors can be fixed by simply renaming said properties to something else, and the renaming can be specified using a bindings file. We inspect the
.xsd files to figure out the XPath.
Solution for error 1: The first error was simple, in our bindings file fixed the error by specfiying:
<jaxb:bindings schemaLocation="https://ws.infotorg.no/xml/EVRY/InfotorgForetak/2015-12-01/include/ResultatregnskapOgBalanse.xsd" node="/xs:schema">
<jaxb:bindings node="//xs:element[#name='Aar']">
<jaxb:property name="ResultatregnskapOgBalanseAar" />
</jaxb:bindings>
</jaxb:bindings>
Attempted solution for error 2: In the xsd file of the second error we could not find any properties named "Error". However there were three properties with the name "error". We try to resolve those:
<jaxb:bindings schemaLocation="https://ws.infotorg.no/xml/EurotaxGlass/Bruktbilverdi/2016-03-09/Bruktbilverdi.xsd" node="/xs:schema">
<jaxb:bindings node="//xs:complexType[#name='error']">
<jaxb:property name="BruktbilverdiComplexTypeError" />
</jaxb:bindings>
<jaxb:bindings node="//xs:element[#name='error']">
<jaxb:property name="BruktbilverdiElementError" />
</jaxb:bindings>
<jaxb:bindings node="//xs:attribute[#name='error']">
<jaxb:property name="BruktbilverdiAttributeError" />
</jaxb:bindings>
</jaxb:bindings>
Thus the whole bindings file is:
<jaxb:bindings version="2.1" 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">
<jaxb:bindings schemaLocation="https://ws.infotorg.no/xml/EVRY/InfotorgForetak/2015-12-01/include/ResultatregnskapOgBalanse.xsd" node="/xs:schema">
<jaxb:bindings node="//xs:element[#name='Aar']">
<jaxb:property name="ResultatregnskapOgBalanseAar" />
</jaxb:bindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="https://ws.infotorg.no/xml/EurotaxGlass/Bruktbilverdi/2016-03-09/Bruktbilverdi.xsd" node="/xs:schema">
<jaxb:bindings node="//xs:complexType[#name='error']">
<jaxb:property name="BruktbilverdiComplexTypeError" />
</jaxb:bindings>
<jaxb:bindings node="//xs:element[#name='error']">
<jaxb:property name="BruktbilverdiElementError" />
</jaxb:bindings>
<jaxb:bindings node="//xs:attribute[#name='error']">
<jaxb:property name="BruktbilverdiAttributeError" />
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
And we still obtain the same second error. We have obtained every .xsd file that is imported and search through every one of them, and none of them as anything called "Error".
What we want
Solve error 2
I managed to fix the error. Using a program called SoapUI I managed to download all the "dependencies" of the WSDL file. In a directory with all said files I use grep -r error . to search for all files containing "error". It found two files:
Bruktbilverdi.xsd: targetNamespace=http://ws.infotorg.no/xml/EurotaxGlass/Bruktbilverdi/2012-08-27/Bruktbilverdi.xsd
Bruktbilverdi_1.xsd: targetNamespace=http://ws.infotorg.no/xml/EurotaxGlass/Bruktbilverdi/2016-03-09/Bruktbilverdi.xsd
The files has similar content, I am not sure why both are listed as dependencies (there were many nested levels of imports, it is hard to keep track)
Anyways, I added another specification to rename for the other file as well to the bindings file, resulting in:
<jaxb:bindings version="2.1" 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">
<jaxb:bindings schemaLocation="https://ws.infotorg.no/xml/EVRY/InfotorgForetak/2015-12-01/include/ResultatregnskapOgBalanse.xsd" node="/xs:schema">
<jaxb:bindings node="//xs:element[#name='Aar']">
<jaxb:property name="ResultatregnskapOgBalanseAar" />
</jaxb:bindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="https://ws.infotorg.no/xml/EurotaxGlass/Bruktbilverdi/2016-03-09/Bruktbilverdi.xsd" node="/xs:schema">
<jaxb:bindings node="//xs:element[#name='error']">
<jaxb:property name="Bruktbilverdi2016ElementError" />
</jaxb:bindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="https://ws.infotorg.no/xml/EurotaxGlass/Bruktbilverdi/2012-08-27/Bruktbilverdi.xsd" node="/xs:schema">
<jaxb:bindings node="//xs:element[#name='error']">
<jaxb:property name="Bruktbilverdi2012ElementError" />
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
which resolved the error. Altough I still find it odd that the error message states "Error" with capital E, but I could only find properties with a smal case "e"
We're using xjc to generate JAXB Java classes for XML generation. Everything works fine except we tried to adjust the generated namespace prefixes as described here. We're stuck with "solution 2", adjusting package-info.java, due to the JAXB version we're using.
The structure we have is several imports deep: root namespace imports other namespace, which in turn imports yet a third one.
MCVE xsds
root.xsd (imports other.xsd):
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="root" xmlns:other="other" targetNamespace="root" version="1.0">
<xs:import namespace="other" schemaLocation="other.xsd" />
<xs:element name="rootElem">
<xs:complexType>
<xs:choice>
<xs:element ref="rootElem1"/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="rootElem1" nillable="false">
<xs:complexType>
<xs:sequence>
<xs:element name="data">
<xs:complexType>
<xs:choice>
<xs:element ref="other:otherElem"/>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
other.xsd (imports third.xsd):
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:other="other" xmlns:third="third" targetNamespace="other" elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.0">
<xsd:import namespace="third" schemaLocation="third.xsd" />
<xsd:element name="otherElem">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="third:thirdElem" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
third.xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:third="third" targetNamespace="third" elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.0">
<xsd:element name="thirdElem">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="thirdData" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
With this
Simple test case
#Test
public void test() throws JAXBException
{
Marshaller marshaller = JAXBContext.newInstance("test.jaxb.generated").createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://www.example.com/schema.xsd");
RootElem root = new RootElem();
RootElem1 root1 = new RootElem1();
Data d = new Data();
OtherElem other = new OtherElem();
ThirdElem thirdElem = new ThirdElem();
thirdElem.setThirdData("third");
other.setThirdElem(thirdElem);
d.setOtherElem(other);
root1.setData(d);
root.setRootElem1(root1);
Path path = Paths.get("target", "outfile.xml");
Result result = new StreamResult(path.toFile());
marshaller.marshal(root, result);
}
this results in this
Generated XML
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns4:rootElem xmlns:ns2="other" xmlns:ns3="third" xmlns:ns4="root" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.com/schema.xsd">
<ns4:rootElem1>
<data>
<ns2:otherElem>
<ns3:thirdElem>
<ns3:thirdData>third</ns3:thirdData>
</ns3:thirdElem>
</ns2:otherElem>
</data>
</ns4:rootElem1>
</ns4:rootElem>
and everything is fine (except data which doesn't have any namespace associated, I'm assuming because that's an inner type).
Now this is partly the question: here's the
generated package-info.java
#javax.xml.bind.annotation.XmlSchema(namespace = "other", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package test.jaxb.generated;
Why is the namespace given referring to other? My root namespace is root. (root.xsd is the only file we're giving our Maven jaxb2-maven-plugin; we can include the others, it makes no difference).
Wrong replacement package-info.java
If we overwrite the generated one with this:
#javax.xml.bind.annotation.XmlSchema(
namespace = "root",
xmlns = {
#javax.xml.bind.annotation.XmlNs(prefix = "t", namespaceURI = "third"),
#javax.xml.bind.annotation.XmlNs(prefix = "o", namespaceURI = "other"),
#javax.xml.bind.annotation.XmlNs(prefix = "r", namespaceURI = "root")
},
elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package test.jaxb.generated;
which we initially did because we assumed we have to give the root namespace here - this is the
Wrong Generated XML
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<r:rootElem xmlns:t="third" xmlns:o="other" xmlns:r="root" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.com/schema.xsd">
<r:rootElem1>
<data>
<r:otherElem>
<t:thirdElem>
<t:thirdData>third</t:thirdData>
</t:thirdElem>
</r:otherElem>
</data>
</r:rootElem1>
</r:rootElem>
Now the namespaces are pretty, but wrong! otherElem belongs to o, not r.
Changing the namespace in the overwriting file back to other fixes the error, but again:
the question is why is the required namespace other here? Just as confusing is the fact that the third imported layer is correct either way.
The problem is fixed, but we'd like to understand the concept. What are we missing?
EDIT:
For completeness' sake, here's the build section of my pom.xml:
<build>
<plugins>
<plugin>
<!-- run xjc -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<executions>
<execution>
<id>xjc-generate_classes</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<packageName>test.jaxb.generated</packageName>
<schemaFiles>
root.xsd
</schemaFiles>
<schemaDirectory>${basedir}/src/main/resources/schemata</schemaDirectory>
<extension>true</extension>
<bindingDirectory>${basedir}/src/main/resources/bindings</bindingDirectory>
<outputDirectory>${basedir}/target/generated-sources/jaxb/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<!-- overwrite created package-info.java -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<overwrite>true</overwrite>
<outputDirectory>${basedir}/target/generated-sources/jaxb/test/jaxb/generated</outputDirectory>
<resources>
<resource>
<directory>${basedir}/src/main/resources/bindings</directory>
<include>package-info.java</include>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
The problem is that you generate all your classes in one package (configured using the packageName of the Maven plugin.
Do not do this.
JAXB is somewhat based on the concept of package-namespace correspondence. There should be one package per namespace you use. While it is technically possible to do it otherwise, you'll be facing one problem after another. So it is better to follow this concept and use or generate one package per namespace. You can still configure target packages - but using the binding files instead of plugin configuration elements.
I use Apache Camel + JAXB for Soap processing. The java glasses are generated by a maven plugin called cxf-codegen-plugin.
The Problem I am facing is that when I want to use a property which is a list. In that case I will always get a list of JAXBElement instead of objects of the correct class.
Assume this given xml snipped:
<domainObjects avqxsi:type="avqsq:AssetAllocation" id="100" name="Some Name">
<nodes>101</nodes>
<nodes>102</nodes>
</domainObjects>
Now all the "nodes" are ids of different domain objects of type AANode. So in the xsd it is defined like so:
<xsd:complexType name="AssetAllocation">
<xsd:complexContent>
<xsd:extension base="avqsq:DomainObject">
<xsd:sequence>
<xsd:element ecore:reference="avqsq:AANode" maxOccurs="unbounded" name="nodes" type="xsd:IDREF"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
And I have defined some bindings.xml:
<jaxb:bindings node="xsd:complexType[#name='AssetAllocation']//xsd:element[#name='nodes']">
<jaxb:property>
<jaxb:baseType name="my.api.xsd.AANode"/>
</jaxb:property>
</jaxb:bindings>
What I want is a POJO property like this:
#XmlElementRef(name = "nodes")
protected List<AANode> nodes;
But what I actually get at runtime is a List<JAXBElement<AANode>> which leads into a ClassCastException.
EDIT 1:
I have missed the fact that the cxf-codegen framework is generating a class where you clearly can see that the property is annotated with JAXBElement.class which i think is wrong. Interestingly changing the annotation by hand to AANode.class will fail with an IllegalAnnotationException: AANode" or any of its subclasses are not known to this context.
public class AssetAllocation
extends DomainObject
implements Serializable, Equals, HashCode, ToString
{
#XmlElementRef(name = "nodes", type = JAXBElement.class)
protected List<AANode> nodes;
apache CXF code gen plugin will always generate codes with JAXBElement until you set the generate element property flag.
Please create Jaxb binding.xml and refer that binding xml in your code gen plugin section from pom file as below
binding.xml
<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings version="2.0"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb">
<jaxb:bindings>
<jaxb:globalBindings generateElementProperty="false"/>
</jaxb:bindings>
</jaxb:bindings>
code gen plugin
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>wsdl2java</goal>
</goals>
<configuration>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/META-INF/wsdl/CxfExampleService.wsdl</wsdl>
<bindingFiles>
<bindingFile>${basedir}/src/main/resources/META-INF/wsdl/binding/bindings.xml</bindingFile>
</bindingFiles>
</wsdlOption>
</wsdlOptions>
</configuration>
</execution>
</executions>
</plugin>
This will resolve the issue
In fact the wsdl2java generates classes with wrong annotations. Instead of
#XmlElementRef(name = "nodes", type = JAXBElement.class)
protected List<AANode> nodes;
One would expect to have:
#XmlIDREF
protected List<AANode> nodes;
I was not able to manage this by bindings.xml. So my final solution is that I use a Byte-Code manipulation to fix the annotations. That way I do not have to mess around with the generated classes or with the generator itself.
I am getting below error while maven build on Linux server though on windows
machine it works fine
org.xml.sax.SAXParseException: src-resolve: Cannot resolve the name 'customer:CustomerApplication' to a(n) 'element declaration' component.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaErr(XSDHandler.java:2537)
Here is relevant snippet from pom.xml
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<configuration>
<schemaDirectory>src/main/resources/META-INF/schema</schemaDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
First XSD relevant part
<?xml version="1.0" encoding="windows-1252" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.cohbe.org/CustomerRequest"
xmlns:customer="http://www.cohbe.org/customer"
targetNamespace="http://www.cohbe.org/CustomerRequest"
elementFormDefault="qualified">
<xsd:import schemaLocation="CustomerDetails.xsd"
namespace="http://www.cohbe.org/customer"/>
<xsd:element name="CustomerNewRequest">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="customer:CustomerApplicationDetail" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
...
</xsd:schema>
CustomerDetails.xsd location is same as of First XSD. Here is relevant part
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema version="2.15"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.cohbe.org/CustDetails"
targetNamespace="http://www.cohbe.org/CustDetails"
xmlns:countries="http://www.cohbe.org/Counties"
elementFormDefault="qualified">
<!-- Version 2.15 -->
<xsd:import namespace="http://www.cohbe.org/states" schemaLocation="States.xsd"/>
<xsd:element name="CustomerApplicationDetail"
type="CustomerApplicationDetail"/>
<xsd:complexType name="CustomerApplicationDetail">
.....
</xsd:schema>
UPDATE:- second file attributes are :-
xmlns="http://www.cohbe.org/customer"
targetNamespace="http://www.cohbe.org/customer"
instead of
xmlns="http://www.cohbe.org/CustDetails"
targetNamespace="http://www.cohbe.org/CustDetails"
It was copy/paste error in this question So I am getting same error i.e org.xml.sax.SAXParseException: src-resolve: Cannot resolve the name
I'm using jaxb to generate java source code from an xsd file.
I want to be able to specify which packages the sources are generated in on a per element basis, however whenever I generate sources I get the following error:
[ERROR] ****/src/main/xjb/common.xjb[8,24]
com.sun.istack.SAXParseException2: compiler was unable to honor this schemaBinding customization. It is attached to a wrong place, or its inconsistent with other bindings.
My bindings file common.xjb is attempting to place the element with the name (attribute value) 'api' in the package 'com.myxml.common.api':
<jxb:bindings version="1.0" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jxb:bindings schemaLocation="../xsd/common/common.xsd" node="/xs:schema">
<jxb:bindings node="//xs:element[#name='api']">
<jxb:schemaBindings>
<jxb:package name="com.myxml.common.api" />
</jxb:schemaBindings>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
My xsd file common.xsd is:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.1" xml:lang="en">
<xs:element name='api'>
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string" />
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:schema>
And I'm using the following Maven plugin to get everything going:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>schema00-generate</id>
<phase>generate-sources</phase>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<schemaFiles>common/common.xsd</schemaFiles>
<bindingFiles>common.xjb</bindingFiles>
<bindingDirectory>${project.basedir}/src/main/xjb</bindingDirectory>
</configuration>
</execution>
</executions>
</plugin>
Why am I getting this error and how can I resolve it? I don't have any other bindings in use at this stage that I'm aware of.
Elements from the same namespace cannot be mapped to different packages so the package cannot be defined for anything other than the top level