问题
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?
回答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.
回答2:
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.
回答3:
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 !)
来源:https://stackoverflow.com/questions/5484345/combine-jaxb-and-jaxws-for-an-imported-xml-schema