Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Applying external JAXB binding file to schema elements imported from WSDL

The XPath expression in my external binding files can't target the elements in my XML schemas which are imported into my WSDL.

Everything runs if I do inline binding customization but I really wanted to have external binding files that way I never accidentally overwrite(refresh) the files containing my customizations.

The start of my binding file:

<jaxb:bindings
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
    version="2.1">
    <jaxb:bindings schemaLocation="../wsdl/localhost_7001/ExampleSessionBean/ExampleSessionBeanService.wsdl#types?schema1">
        <jaxb:bindings node="//xs:schema[@targetNamespace='urn:myExample']">

My WSDL contains:

<types>
<xsd:schema>
<xsd:import namespace="urn:myExample" schemaLocation="http://localhost:7001/ExampleSessionBean/ExampleSessionBeanService?xsd=1"/>
</xsd:schema>
<xsd:schema>
<xsd:import namespace="http://ejbs/" schemaLocation="http://localhost:7001/ExampleSessionBean/ExampleSessionBeanService?xsd=2"/>
</xsd:schema>
</types>

No matter what I do XPath can't find anything in the xsd:import'ed schemas. The error I get is:

[ERROR] XPath evaluation of "//xs:schema[@targetNamespace='urn:myExample']" results in empty target node

I've tried accessing the xs:schema by index number instead of the namespace and that doesn't work either. It seems like my XPath expressions can't reach elements from imported schemas...is there anyway to fix this?

This is a Java SE 7 project being developed under NetBean 7.2. I'm using NetBeans to do all my wsimport stuff if that matters but the command output looks fairly standard for RI/Metro.

EDIT: I figured out that I can get an external binding file to work if I use SCD. This XPath example doesn't work:

<bindings node="//xsd:schema[@targetNamespace='urn:myExample']">
    <bindings node="//xs:complexType[@name='myType']">
        <class name="MyClass"/>
    </bindings>
</bindings>

But this SCD example does.

<bindings scd="x-schema::tns" xmlns:tns="urn:myExample">
    <bindings scd="~tns:myType">
        <class name="MyClass"/>
    </bindings>
</bindings>

Is this a known thing where XPath doesn't work in xjb files when using wsimport but SCD does?

like image 867
Chase Avatar asked Feb 26 '13 01:02

Chase


People also ask

What is JAXB binding file?

JAXB is an XML-to-Java binding technology that enables transformation between schema and Java objects and between XML instance documents and Java object instances. JAXB technology consists of a runtime API and accompanying tools that simplify access to XML documents.

What is the use of XJB file?

xjb extension to resolve any conflicts in the WSDL or schema. For example if two elements have the same name and you want to distinguish between them you can rename one by specifying it the bindings file.

What is JAXB used for?

JAXB simplifies access to an XML document from a Java program by presenting the XML document to the program in a Java format. The first step in this process is to bind the schema for the XML document into a set of Java classes that represents the schema.


2 Answers

you should use it like:

<jaxws:bindings node="wsdl:definitions/wsdl:types/xsd:schema[@targetNamespace='http://duke.example.org']">
    <jaxb:schemaBindings>
        <jaxb:package name="fromwsdl.server"/>
    </jaxb:schemaBindings>
</jaxws:bindings>

Be careful with the namespaces

It all is explained here: https://jax-ws.java.net/nonav/2.1.2/docs/customizations.html

like image 104
elro Avatar answered Sep 21 '22 12:09

elro


You could compile each of the XML schemas to Java classes individually. Then you can leverage episode files so that the generated classes can be used when you compile schemas that import that XML schema.

Below is an example of how you produce an episode file.

xjc -b binding1.xml -episode common.episode common.xsd

And below is an example of how you consume and episode file. The episode file is just a JAXB external bindings file and therefore is specified using the -b flag.

xjc -d out main.xsd -extension -b common.episode   

For More Information

  • http://blog.bdoughan.com/2011/12/reusing-generated-jaxb-classes.html
like image 29
bdoughan Avatar answered Sep 20 '22 12:09

bdoughan