wsimport bindings namespace error - jaxb

I'm trying to change the package name space for some namespaces because they have objects that collide.
Here is the wsdl:
<wsdl:definitions
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://tempuri.org/"
<wsdl:types>
<xsd:schema targetNamespace="http://tempuri.org/Imports">
<xsd:import schemaLocation="https://localhost/DS/Search.svc?xsd=xsd0" namespace="http://tempuri.org/"/>
<xsd:import schemaLocation="https://localhost/DS/Search.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
</xsd:schema>
</wsdl:types>
</wsdl:definitions>
Here are the bindings:
<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
jaxb:version="2.0"
wsdlLocation="https://localhost/DS/Search.svc?wsdl">
<jaxb:bindings node="//wsdl:definitions/wsdl:types/xsd:schema/xsd:import[#namespace='http://tempuri.org/']">
<jaxb:schemaBindings>
<jaxb:package name="directoryservice"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings node="//wsdl:definitions/wsdl:types/xsd:schema/xsd:import[#namespace='http://localhost.datacontract.org/2004/07/Search.Models.SearchAPI']">
<jaxb:schemaBindings>
<jaxb:package name="directoryservice.model"/>
</jaxb:schemaBindings>
</jaxb:bindings>
</jaxb:bindings>
When I run wsimport with the -b option I get this error
[ERROR] XPath evaluation of "//wsdl:definitions/wsdl:types/xsd:schema/xsd:import[#namespace='http://tempuri.org/']" results in empty target node
line 7 of file:service-bindings.xml
I get the error for both bindings..
Am I missing something with the definition of the bindings?

I found a way round this issue by using the global binding. The binding will create the serivce ObjectFactory but not the model pojos.
<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
jaxb:version="2.0">
<jaxb:globalBindings generateElementProperty="false"/>
</jaxb:bindings>

Related

XPath evaluation always results in empty target node

I'm trying to create a bind file to change the base type of a property:
XSD
My bind file:
<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
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
http://www.w3.org/2001/XMLSchema http://www.w3.org/2001/XMLSchema.xsd"
version="2.1">
<bindings schemaLocation="*">
<bindings node="//xsd:element[#name='EFilingPriorDocumentNumber']">
<baseType name="java.lang.String"/>
</bindings>
</bindings>
</bindings>
But XJC always give me the error:
[ERROR] XPath evaluation of "//xsd:element[#name='EFilingPriorDocumentNumber']" results in empty target node
Someone knows how to fix it?

Refining external bindings XML for xjc

Hi I'm trying to create an external bindings XML for xjc but I'm getting 2 errors:
[ERROR] A class/interface with the same name "x.x.DaysOfWeek" is already in use. Use a class customization to resolve this conflict.
[ERROR] (Relevant to above error) another "DaysOfWeek" is generated from here.
Am I missing something major? I need a second pair of eyes. Thanks
<!-- data.xsd -->
<xs:complexType name="DaysOfWeek">
<xs:sequence>
<xs:element ref="DaysOfWeek"/>
</xs:sequence>
</xs:complexType>
<xs:element name="DaysOfWeek">
<xs:complexType mixed="true">
<xs:attribute name="Type" use="required" type="xs:NCName"/>
</xs:complexType>
</xs:element>
and I have bindings.xml right now
<jaxb:bindings version="1.0" 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:bindings schemaLocation="data.xsd">
<jaxb:schemaBindings>
<jaxb:package name="net.opengis.kml.v_2_2_0"/>
</jaxb:schemaBindings>
<jaxb:bindings node="xs:complexType[#name='DaysOfWeek']//xs:element[#ref='DaysOfWeek']">
<jaxb:property name="ComplexDaysOfWeek"/>
</jaxb:bindings>
<jaxb:bindings node="xs:element[#name='DaysOfWeek']">
<jaxb:factoryMethod name="ComplexDaysOfWeek"/>
</jaxb:bindings>
</jaxb:bindings>
You have a collision on generated classes. Try adding:
<jaxb:bindings node="xs:element[#name='DaysOfWeek']//xs:complexType">
<jaxb:class name="ComplexDaysOfWeekType"/>
</jaxb:bindings>
(Maybe without //xs:complexType, not quite sure.)
The issue has been solved using
<jaxb:bindings schemaLocation="data.xsd" node="/xs:schema">
<jaxb:bindings node="xs:element[#name='DaysOfWeek']">
<jaxb:class name="ComplexDaysOfWeek"/>
</jaxb:bindings>
<jaxb:bindings node="xs:complexType[#name='DaysOfWeek']//xs:element[#ref='DaysOfWeek']">
<jaxb:property name="ComplexDaysOfWeek"/>
</jaxb:bindings>
</jaxb:bindings>

wsdl with conflicting xsd imports

I tried to find a solution for some time to the following problem. I have a wsdl file containing several (6) xsd imports. I cannot change these xsd's because they are external to my project. There are 4 definitions all together which are slightly defined different in 2 of these schemas. I was attempting to translate each 'conflicting' xsd schema to it's own package. I tried following bindings, but it did not do the job:
testbindings.jaxb:
<bindings xmlns="http://java.sun.com/xml/ns/jaxb" version="2.1">
<bindings schemaLocation="a.xsd">
<schemaBindings>
<package name="org.wsi.a" />
</schemaBindings>
</bindings>
</bindings>
using: wsimport -p org.wsi -b testbindings.jaxb broker.wsdl
All classes are generated in org.wsi and no classes in org.wsi.a. Without the -p switch all xsd are generated in their own default package. But could not tell wsimport to use specific packages for each xsd. At this moment I use following binding file, which is probably incorrect, but for which the wsimport doesn't complain:
<?xml version="1.0"?>
<jaxws:bindings xmlns:jaxws="http://java.sun.com/xml/ns/jaxws" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb">
<jaxws:bindings wsdlLocation="broker.wsdl" node="wsdl:definitions/wsdl:types/xsd:schema">
<jaxb:bindings xmlns:xs="http://www.w3.org/2001/XMLSchema" node="//xs:schema/xs:import[#namespace='http://docs.oasis-open.org/wsn/b-2']">>
<jaxb:schemaBindings>
<jaxb:package name="org.broker.wsi.b_2"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings xmlns:xs="http://www.w3.org/2001/XMLSchema" node="//xs:schema/xs:import[#namespace='http://docs.oasis-open.org/wsn/t-1']">>
<jaxb:schemaBindings>
<jaxb:package name="org.broker.wsi.t_1"/>
</jaxb:schemaBindings>
</jaxb:bindings>
</jaxws:bindings>
In packages org.broker.wsi.b_2 and org.broker.wsi.t_1, no files are generated.
I used bindings as specified in: http://docs.oracle.com/cd/E13222_01/wls/docs103/webserv/data_types.html#wp227713 but probably incorrect.
Suggestions are welcome.
The problem of setting up the correct package names for the wsdl, the internal xsd and the external xsd's is described in question/answer:
wsimport - how to generate service endpoint classes and JAXB classes in separate projects/folders, posted by:
dma-k
int-bindings.xml file:
<?xml version="1.0"?>
<jaxws:bindings version="2.0"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
wsdlLocation="broker.wsdl">
<jaxws:package name="org.broker.wsi" />
<jaxb:bindings node="//xsd:schema">
<jaxb:schemaBindings>
<jaxb:package name="org.broker.wsi.al"/>
</jaxb:schemaBindings>
</jaxb:bindings>
The external-bindings file (abbreviated):
<jaxb:bindings version="1.0"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<jaxb:bindings schemaLocation="http://docs.oasis-open.org/wsn/b-2.xsd" node="//xsd:schema">
<jaxb:schemaBindings>
<jaxb:package name="org.broker.wsi.oasis.b2"/>
</jaxb:schemaBindings>
</jaxb:bindings>
</jaxb:bindings>

JAXB External Custom Binding XJC Issue - Parsing results in empty node

Forgive me if this is a duplicate. Here is my binding.xjb file. But now i am getting the regular error that the complex type target "AddBankVaultRplyType" is not found. I don't see any issue. Can somebody help me with this? I am listing the xsd that i am trying to customize
<jxb:bindings
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:pd="http://chubb.com/cpi/polsvc/xmlobj"
xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
jxb:extensionBindingPrefixes="inheritance"
jxb:version="2.1"
>
<jxb:bindings node="/xs:schema/xs:ServiceReply/xs:complexType[#name='AddBankVaultRplyType']">
<inheritance:extends>com.print.poc.AddressTypeHelper</inheritance:extends>
</jxb:bindings>
Here is the piece of XSD that i am trying to customize
<xs:schema xmlns:pd="http://com/polsvc/xmlobj" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://com/polsvc/xmlobj" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:complexType name="AddBankVaultRplyType">
</xs:complexType>
<xs:element name="ServiceReply">
<xs:complexType>
<xs:sequence>
<xs:element name="ReplyHeader" type="pd:MsgHeaderType"/>
<xs:element name="RequestHeader" type="pd:MsgHeaderType"/>
<xs:choice>
<xs:element name="AddBankVaultReply" type="pd:AddBankVaultRplyType"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Now if i run XJC it is saying me that the target "/xs:schema/xs:ServiceReply/xs:complexType[#name='AddBankVaultRplyType']" results in empty node. What is the mistake i am doing here
You will need to wrap in a bindings that has the schema location set. It should be something like:
<jxb:bindings
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:pd="http://chubb.com/cpi/polsvc/xmlobj"
xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
jxb:extensionBindingPrefixes="inheritance"
version="2.1">
<jxb:bindings schemaLocation="your-schema.xsd">
<jxb:bindings node="//xs:complexType[#name='AddBankVaultRplyType']">
<inheritance:extends>com.print.poc.AddressTypeHelper</inheritance:extends>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
For more information:
http://jaxb.java.net/guide/Dealing_with_errors.html
I finally got mine workign with subclassing as well as adding #XmlRootElement to those dang complexTypes that are used by a root element(I don't get why JAXB doesn't add it for me, but this does the trick of doing that since JAXB doesn't)
<?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"
xmlns:annox="http://annox.dev.java.net"
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd
http://annox.dev.java.net "
jaxb:extensionBindingPrefixes="xjc annox"
version="2.1">
<jaxb:globalBindings>
<jaxb:serializable uid="1"/>
<!-- All generated classes must have MySignature interface (supplied in dependencies) -->
<xjc:superClass name="com.cigna.framework.DataObject"/>
<xjc:superInterface name="com.cigna.framework.InterfaceTest"/>
<!-- All temporal fields are implemented as Joda DateTime and use DateUtils as an adapter -->
<jaxb:javaType
name="org.joda.time.DateTime"
xmlType="xs:time"
parseMethod="com.cigna.framework.util.DateUtil.stringToDateTime"
printMethod="com.cigna.framework.util.DateUtil.dateTimeToString"
/>
</jaxb:globalBindings>
<!-- Application of annotations to selected classes within schemas -->
<!-- org.example.SomeRootType #XmlRootElement -->
<jaxb:bindings schemaLocation="../schemas/externalaction_2012_03.xsd" node="/xs:schema">
<jaxb:schemaBindings >
<jaxb:package name="com.framework.action"></jaxb:package>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="../schemas/common_2012_04.xsd" node="/xs:schema">
<jaxb:schemaBindings >
<jaxb:package name="com.framework.common"></jaxb:package>
</jaxb:schemaBindings>
<jaxb:bindings node="xs:complexType[#name='PersonNameType']">
<annox:annotate>
<annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="SomeRootType"/>
</annox:annotate>
</jaxb:bindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="../schemas/utilities_2012_03.xsd" node="/xs:schema">
<jaxb:schemaBindings >
<jaxb:package name="com.framework.util"></jaxb:package>
</jaxb:schemaBindings>
</jaxb:bindings>
</jaxb:bindings>
Of course I struggled with the pom.xml alot but finally came to this solution which worked for me.
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.8.1</version>
<executions>
<execution>
<id>process-xsd</id>
<goals>
<goal>generate</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<schemaIncludes>
<include>schemas/*.xsd</include>
</schemaIncludes>
<bindingIncludes>
<include>schemas/*.xjb.xml</include>
</bindingIncludes>
<generateDirectory>${project.build.directory}/generated-sources</generateDirectory>
<extension>true</extension>
<args>
<arg>-Xannotate</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-annotate</artifactId>
<version>0.6.3</version>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.6.3</version>
</plugin>
</plugins>
</configuration>
</execution>
</executions>
</plugin>
later,
Dean

Compiling multiple schemas into different packages using JAXB 2.1

I have a CommonTypes.xsd which I'm including in my all other XSDs using xs:include. I get
Multiple <schemaBindings> are defined for the target namespace ""
when I try to compile it into different packages using binding files. Please tell me whether there is a way to compile them into different packages. I'm using jaxb 2.1
Yeah, there is a way.
Assuming:
xsd/common/common.xsd
xsd/foo/foo.xsd
In the common directory place common.xjb:
<jxb:schemaBindings>
<jxb:package name="mypkg.common">
</jxb:package>
</jxb:schemaBindings>
In the foo directory place foo.xjb:
<jxb:schemaBindings>
<jxb:package name="mypkg.foo">
</jxb:package>
</jxb:schemaBindings>
In the build.xml file, create one xjc task for each:
<xjc destdir="${app.src}" readOnly="true" package="mypkg.common">
<schema dir="${app.schema}/common" includes="*.xsd" />
<binding dir="${app.schema}/common" includes="*.xjb" />
</xjc>
<xjc destdir="${app.src}" readOnly="true" package="mypkg.foo">
<schema dir="${app.schema}/foo" includes="*.xsd" />
<binding dir="${app.schema}/foo" includes="foo.xjb" />
</xjc>
You need to make sure that common.xsd has a targetNameSpace that is different from foo.xsd's targetNameSpace.
As stated already by Ben there is no way to do that if they have the same namespace.
But how to do it if you do have different namespaces?
<jxb:bindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb" version="2.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
<jxb:bindings namespace="http://www.openapplications.org/oagis/9/unqualifieddatatypes/1.1" schemaLocation="oagi/Common/UNCEFACT/ATG/CoreComponents/UnqualifiedDataTypes.xsd" >
<jxb:schemaBindings>
<jxb:package name="com.test.oagi.udt"/>
</jxb:schemaBindings>
</jxb:bindings>
<jxb:bindings namespace="http://www.openapplications.org/oagis/9/codelists" schemaLocation="oagi/Common/OAGi/Components/CodeLists.xsd" >
<jxb:schemaBindings>
<jxb:package name="com.test.oagi.cl"/>
</jxb:schemaBindings>
</jxb:bindings>
</jxb:bindings>
but be sure you do not use the command line parameter -p, since that will override your config.
I've meet the same problem and haven't solve it yet, but I'm afraid that it can't be possible to generate XSD into differents packages :
It is not legal to have more than one <jaxb:schemaBindings> per namespace, so it is impossible to have two schemas in the same target namespace compiled into different Java packages
from Compiler Restrictions at the end of this page
but if some one find some work around, just inform us please
I know it is an old post, but, as there is no answer for the exact question, here is my proposal:
As mmoossen explained, the trick is to specify different namespaces for the XSDs.
But, adding a namespace attribute in the jxb:bindings tag doesn't work:
<jxb:bindings namespace="http://www.openapplications.org/oagis/9/unqualifieddatatypes/1.1" schemaLocation="oagi/Common/UNCEFACT/ATG/CoreComponents/UnqualifiedDataTypes.xsd" >
Instead of that, you need to add a targetNamespace attribute to the xs:schema tags of your XSDs:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified"
targetNamespace="some.namespace"
version="1.0">
Once done, you will be able to have 1 external customization file (.xjb) declaring different schemaBindings, each of them possibly using a different package:
<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings version="2.1"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
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:extensionBindingPrefixes="xjc annox inherit">
<jaxb:bindings schemaLocation="MyFirstXSD.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.a" />
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="MySecondXSD.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.b" />
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="MyThirdXSD.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.c" />
</jaxb:schemaBindings>
</jaxb:bindings>
</jaxb:bindings>
Can be done as mentioned in jaxb maven plugin usage page in case of having Multiple schemas with different configuration.
Separate packages can be configured for each schema.
<packageName>se.west</packageName>
complete example configuration below:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<id>xjc-schema1</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<!-- Use all XSDs under the west directory for sources here. -->
<sources>
<source>src/main/xsds/west</source>
</sources>
<!-- Package name of the generated sources. -->
<packageName>se.west</packageName>
</configuration>
</execution>
<execution>
<id>xjc-schema2</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<!-- Use all XSDs under the east directory for sources here. -->
<sources>
<source>src/main/xsds/east</source>
</sources>
<!-- Package name of the generated sources. -->
<packageName>se.east</packageName>
<!--
Don't clear the output directory before generating the sources.
Clearing the output directory removes the se.west schema from above.
-->
<clearOutputDir>false</clearOutputDir>
</configuration>
</execution>
</executions>

Resources