I am trying to generate proxy classes from wsdl2java using cxf, but whenever I try I keep on getting below error:
WSDLToJava Error: http://webservices.sabre.com/wsdl/sabreXML1.0.00/shopping/Grou
pedItineraryResponse_v1-0-2.xsd [0,0]: Property "ValidatingCarrier" is already d
efined. Use <jaxb:property> to resolve this conflict.
http://webservices.sabre.com/wsdl/sabreXML1.0.00/shopping/GroupedItineraryRespon
se_v1-0-2.xsd [0,0]: The following location is relevant to the above error
I tried to add binding file to wsdl2java.bat as I got info from one of the url like this:
<jaxws:bindings wsdlLocation="http://webservices.sabre.com/wsdl/sabreXML1.0.00/shopping/BargainFinderMaxRQ_v1-8-2.wsdl"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
jaxb:extensionBindingPrefixes="xjc"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc">
<jaxws:bindings node="wsdl:definitions/wsdl:types/xsd:schema">
<jaxb:globalBindings
jaxb:version="2.0">
<xjc:simple />
</jaxb:globalBindings>
</jaxws:bindings>
I am using third party wsdl url, so I don't have any control to change on the server side, I need to make changes only on command to successfuly generate proxy classes. Can someone kindly help me in this issue?
The problem is that FareType has both child element named ValidatingCarrier and attribute with the same name.
To work around this you should add field binding as suggested by error message. Example binding:
<jaxb:bindings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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"
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
jaxb:version="2.1"
schemaLocation="http://webservices.sabre.com/wsdl/sabreXML1.0.00/shopping/GroupedItineraryResponse_v1-0-2.xsd">
<jaxb:bindings node="//xs:complexType[#name='FareType']/xs:sequence/xs:element[#name='ValidatingCarrier']">
<jaxb:property name="validatingCarrierInfo"></jaxb:property>
</jaxb:bindings>
</jaxb:bindings>
With this binding I renamed ValidatingCarrier to ValidatingCarrierInfo.
Related
In my maven based project,
import jakarta.xml.bind.JAXBContext;
...
private String contextPath = "com.abc.core:com.bcd.model:com.efg.xyz";
...
JAXBContext jc = JAXBContext.newInstance(contextPath);
When i try to call JAXBContext.newInstance(contextPath), i get the below runtime exception,
org.glassfish.jaxb.runtime.v2.runtime.IllegalAnnotationsException: 3 counts of IllegalAnnotationExceptions
Two classes have the same XML type name "objectFactory". Use #XmlType.name and #XmlType.namespace to assign different names to them.
this problem is related to the following location:
at com.abc.core.ObjectFactory
this problem is related to the following location:
at com.bcd.model.ObjectFactory
Two classes have the same XML type name "objectFactory". Use #XmlType.name and #XmlType.namespace to assign different names to them.
this problem is related to the following location:
at com.bcd.model.ObjectFactory
this problem is related to the following location:
at com.efg.xyz.ObjectFactory
In the pom.xml of the current package where i am getting this error, i have added
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>3.0.1</version>
<scope>runtime</scope>
</dependency>
However, i haven't added this glassfish jaxb explicitly in the packages com.abc.core,com.bcd.model,com.efg.xyz.
I tried checking if apart from my declaration, someone else also creating an objectFactory due to which i get this exception, but no clue yet. Can you please help here?
.xjb bindings in package : com.abc.core
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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"
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd" jaxb:version="2.1">
<jaxb:globalBindings>
<jaxb:javaType name="java.util.Calendar" xmlType="xs:dateTime" parseMethod="jakarta.xml.bind.DatatypeConverter.parseDateTime" printMethod="jakarta.xml.bind.DatatypeConverter.printDateTime" />
<xjc:simple />
</jaxb:globalBindings>
</jaxb:bindings>
and in com.bcd.model
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<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:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
version="2.1">
<jaxb:globalBindings>
<jaxb:javaType name="java.util.Calendar" xmlType="xs:dateTime" parseMethod="jakarta.xml.bind.DatatypeConverter.parseDateTime" printMethod="jakarta.xml.bind.DatatypeConverter.printDateTime" />
<xjc:simple />
</jaxb:globalBindings>
</jaxb:bindings>
For a certain xsd file, I have created a corresponding binding file that does some actions. In my case, annotating ComplexTypes with annotations. Finding the type is done with an XPath expression. The following example demonstrates this:
<jaxb:bindings
xmlns:xsd="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"
version="2.1"
xmlns:annox="http://annox.dev.java.net" jaxb:extensionBindingPrefixes="annox">
<jaxb:bindings schemaLocation="FirstSchema.xsd" node="/xsd:schema">
<jaxb:bindings node="//xsd:complexType//xsd:element[contains(#type, 'SomeType')]" required="false">
<annox:annotate target="field">#com.example.Type(type = "SomeType")</annox:annotate>
</jaxb:bindings>
//About 100 lines of bindings
</jaxb:bindings>
</jaxb:bindings>
There are more bindings defined than just the single I've shown, but my problem is that the bindings are now executed on the FirstSchema.xsd. I have a lot of other xsd files that require the exact same bindings. If I have over 10 more xsd files, I'd have to copy-paste these bindings every time for every schema.
Is it possible to "extract" the bindings and re-use them for every other xsd file like an import? It's kind of related to this comment/question. The advised solution there is using jaxb:schemaBindings/jaxb:package, but if I understand correctly the following snippet just generates the classes into another package and doesn't really solve the problem?
<jaxb:schemaBindings>
<jaxb:package name="com.example.package"/>
</jaxb:schemaBindings>
You'll be surprized, but old-school XML inclusion works with XJB files.
binding.xjb:
<!DOCTYPE jaxb:bindings [
<!ENTITY gh24type SYSTEM "gh24type.xml">
]>
<jaxb:bindings
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:annox="http://annox.dev.java.net"
jaxb:extensionBindingPrefixes="annox"
jaxb:version="2.1">
<jaxb:bindings schemaLocation="schema.xsd" node="/xsd:schema">
<!-- ... -->
&gh24type;
</jaxb:bindings>
</jaxb:bindings>
gh24type.xml:
<jaxb:bindings node="xsd:complexType[#name='gh24Type']">
<annox:annotate>#javax.annotation.Generated({"jaxb2-annotate-plugin"})</annox:annotate>
</jaxb:bindings>
So basically nothing spectacular, just entity-based XML inclusion. If you have exactly the same fragments, just include your entity several times for each of the schemas in question.
Alternatives would be writing a special plugin to simplify customization. Which might be a good idea anyway.
I am using JAXB to process multiple XML documents.
My issue is that I cannot change the related xsd's and I don't want to amend the generated classes.
What I want to do is employ JAXB Binding customization files to achieve the desired result.
All I need to do is perform the equivalent of using the #XmlType.namespace annotation.
Is it possible to set the #XmlType.namespace annotation via JAXB Binding Customization files?
Disclaimer: I am the author of the jaxb2-annotate-plugin.
You can use the jaxb2-annotate-plugin to add arbitrary annotations to your schema-derived classes. #XmlType will be something like:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<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"
jaxb:extensionBindingPrefixes="xjc annox"
version="2.1">
<jaxb:bindings schemaLocation="schema.xsd" node="/xs:schema">
<jaxb:bindings node="xs:complexType[#name='someType']">
<annox:annotateClass>#javax.xml.bind.annotation.XmlType(namespace="urn:test")</annox:annotateClass>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
If you already have an #XmlType there, the customized annotation will be "merged" into it.
I am new to XJC. I'm attempting to consume a WSDL and generate binding classes with the XJC command and I got the following error:
C:\jaxb>xjc -verbose -b c:\jaxb\bindings-wsdl.xjb -wsdl c:\jaxb\BioMetScrnSvc.wsdl
parsing a schema...
[ERROR] XPath evaluation of "//*[local-name()='schema']" results in empty target node
line 8 of file:/C:/jaxb/bindings-wsdl.xjb
Failed to parse a schema.
My binding file is as follows:
<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:impl="http://www.openuri.org/"
xmlns:apachesoap="http://xml.apache.org/xml-soap"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:intf="http://www.openuri.org/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<jaxb:bindings node="//*[local-name()='schema']">
<jaxb:globalBindings generateElementProperty="false"/>
</jaxb:bindings>
</jaxb:bindings>
The WSDL provided to me is something as follows:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://www.openuri.org/"
xmlns:impl="http://www.openuri.org/"
xmlns:apachesoap="http://xml.apache.org/xml-soap"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:intf="http://www.openuri.org/">
<wsdl:types>
<schema elementFormDefault="qualified" targetNamespace="http://www.openuri.org/"
xmlns="http://www.w3.org/2001/XMLSchema">
...
From all the suggestions I have read from this site, I have included the necessary namespaces into the binding file to no avail. I have tested the Xpath and it is correct.
If I don't have a binding file, a JAXBElement is generated instead of a String. Understood it is because of minOccurs and nillable occurring together.
Regards,
Wes
I could not make bindings work with node. This might be a bug in XJC, I'll check/report to Oracle.
But SCD bindings do work! So here's a solution for you. Make a file namely "wsdl.xjb" and put following code in it. And place it on the same folder (for simplicity OR you can place anywhere then you will need to mention its path) where you have your example.wsdl file.
<jaxb:bindings
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
jaxb:version="2.0">
<jaxb:bindings scd="x-schema::tns" xmlns:tns="http://www.openuri.org/">
<jaxb:globalBindings generateElementProperty="false"/>
</jaxb:bindings>
</jaxb:bindings>
You'll need to include a -extension command switch and your final command will look like this:
xjc -extension -verbose -wsdl example.wsdl -b wsdl.xjb
I use the Dali plugin in Eclipse to generate Java classes using an xsd file, which essentially just invokes xjc on the schema file. I used the advice here to resolve naming conflicts by applying an XML binding file to the class generation. This worked well, but I tried to take it a step further by renaming the root element, and the result was that I lost the XmlRootElement annotation. I tried using annox to add the root element annotation back in, but I get this error: Unsupported binding namespace "http://annox.dev.java.net". Perhaps you meant "http://java.sun.com/xml/ns/jaxb/xjc"?
Here is my initial binding.xml file (without annox):
<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:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
version="2.1">
<!-- Force all classes to be generated at the top level, this will potentially cause name conflicts -->
<jaxb:globalBindings localScoping="toplevel"/>
<jaxb:bindings schemaLocation="mySchema-1.0.0.xsd">
<!-- Rename the root element -->
<jaxb:bindings node="//xs:element[#name='MyRootClassNameIsReallyLong']/xs:complexType">
<jaxb:class name="ShorterName"/>
</jaxb:bindings>
<!-- Rename the Bar class to resolve a naming conflict -->
<jaxb:bindings node="//xs:element[#name='Foo']/xs:complexType/xs:sequence/xs:element[#name='Bar']/xs:complexType">
<jaxb:class name="FooBar"/>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
By the way, it's worth noting that the schema file came from a third party, so I have no interest in modifying it. Likewise, I'd rather not tamper with the generated Java files, so that's why I am interested in the binding xml approach.
Edit (9/11/2013) - Here is the binding XML with annox:
<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:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
xmlns:annox="http://annox.dev.java.net"
version="2.1">
<!-- Force all classes to be generated at the top level, this will potentially cause name conflicts -->
<jaxb:globalBindings localScoping="toplevel"/>
<jaxb:bindings schemaLocation="mySchema-1.0.0.xsd">
<!-- Rename the root element -->
<jaxb:bindings node="//xs:element[#name='MyRootClassNameIsReallyLong']/xs:complexType">
<jaxb:class name="ShorterName"/>
<annox:annotate>
<annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="MyRootClassNameIsReallyLong" />
</annox:annotate>
</jaxb:bindings>
<!-- Rename the Bar class to resolve a naming conflict -->
<jaxb:bindings node="//xs:element[#name='Foo']/xs:complexType/xs:sequence/xs:element[#name='Bar']/xs:complexType">
<jaxb:class name="FooBar"/>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
Annox is an XJC add on, so you in addition to declaring the namespace prefx (xmlns:annox="http://annox.dev.java.net), you also need to declare it as an extensionBindingPrefix.
Your openning tag should then look like this:
<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:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb
http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
jaxb:extensionBindingPrefix="annox"
version="2.1">