Combine JAXB and JAXWS for an imported XML Schema
Asked Answered
L

3

3

How can I specify a JAXB Binding for an imported XSD within a WSDL when using wsimport?

I tried following binding, which causes the error "XPath evaluation of //xs:element[@name='isFoobar'] results in an empty target node".

<?xml version="1.0" encoding="UTF-8"?>
<jaxws:bindings xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" wsdlLocation="example.wsdl"
    xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
    <jaxws:bindings node="wsdl:definitions">
        <jaxws:bindings node="wsdl:types" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb">
            <jaxws:bindings
                node="//xs:schema[@targetNamespace='http://www.example.org/']">
                <jaxb:globalBindings>
                    <xjc:serializable uid="10000001" />
                </jaxb:globalBindings>
                <jaxb:bindings
                    node="//xs:element[@name='isFoobar']">
                    <jaxb:typesafeEnumClass name="IsFoobar">
                        <jaxb:typesafeEnumMember value="01" name="TRUE" />
                        <jaxb:typesafeEnumMember value="02" name="FALSE" />
                    </jaxb:typesafeEnumClass>
                </jaxb:bindings>
            </jaxws:bindings>
        </jaxws:bindings>
    </jaxws:bindings>
</jaxws:bindings>

Any ideas?

Lime answered 30/3, 2011 at 9:13 Comment(1)
Dis you find a way to do what you wanted to do ? I'm interested.Rexfourd
D
1

I did something similar ages ago, I think you need to specify the node to select with XPath as follows:

//xs:element[@name='isFoobar']/xs:complexType

Or replace xs:complexType with whatever kind of type you are using here. Hopefully it will fix your probelm.

Dimmick answered 1/4, 2011 at 6:24 Comment(2)
I had no time to test it. But I accept it nevertheless, as there are no other suggestions.Lime
well, accepting without testing might be misleading for othersInfantryman
F
2

Sorry for the necro-threading, I encountered this problem and although this is one of the first answer that showed up on google with various key word combination it didn't hold the answer I ended up using.


For imported schemas, the easiest way to specify a JAXB binding on an imported XSD within a WSDL is... to treat it as a completely different schema !

Short example :

MyXSD.xsd

<xsd:schema targetNamespace="whatever"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xs:complexType name="ThingThatNeedsToBeBound">
        <!-- Whatever this is made of -->
    </xs:complexType>
</xsd:schema>

No matter where this xsd is imported (wether it's at the root of the of my wsdl or within a nested import), all I need to write to bind my "ThingThatNeedsToBeBound" in my custom binding is :

customBindings.xml

<jaxb:bindings schemaLocation="Path/To/MyXSD.xsd" node="/xs:schema/xs:complexType[@name='ThingThatNeedsToBeBound']">
    <!-- your custom binding -->
</jaxb:bindings>

So, it's just like a regular case, except that you specify the schemaLocation, but then you can consider the imported schema as a whole itself instead of a part of something.

I hope this will help others stumbling upon this problem.


Source : http://www.oracle.com/technetwork/articles/grid/jax-ws-jaxb-customization-082750.html

(Note : in the source, the solution seems way more complicated, so my case might have been simpler than what they described, I found my solution using that none the less !)

Fichu answered 13/3, 2017 at 17:1 Comment(1)
I cannot test it, but it sounds reasonable. Btw there is no such thing as necro-threading on StackOverflow. Questions and answers should be kept up-to-date. :-)Lime
D
1

I did something similar ages ago, I think you need to specify the node to select with XPath as follows:

//xs:element[@name='isFoobar']/xs:complexType

Or replace xs:complexType with whatever kind of type you are using here. Hopefully it will fix your probelm.

Dimmick answered 1/4, 2011 at 6:24 Comment(2)
I had no time to test it. But I accept it nevertheless, as there are no other suggestions.Lime
well, accepting without testing might be misleading for othersInfantryman
G
1

My first try at resolving this was trying to somehow use XPath or multiple jxb:binding elements, but that didn't work. As far as I know the XPath just isn't validated properly against imported schemas unless it would all be rewritten and mashed together with DOM.

So the way I resolved this problem was by using inline customizations in the imported XSD. I didn't test this approach with multiple nested imports, but if you got access and time to modify all the imported XSDs this should work out ok. In my opinion this is only necessary if you need to generate the mapping and can be scrubbed/removed from the XSD once the mapping is done.

Gingergingerbread answered 23/9, 2011 at 13:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.