XPath evaluation results in empty target node

Neill picture Neill · Jun 13, 2014 · Viewed 10k times · Source

I'm attempting to consume a WSDL and generate binding classes using maven-jaxb2-plugin.

The WSDL is this,

<wsdl:definitions>
  <wsdl:types>
  ...
  </wsdl:types>
  ...
  <wsdl:message name="IServiceWeb_GetPaymentInfo_InputMessage">
    <wsdl:part name="parameters" element="tns:GetPaymentInfo"/>
  </wsdl:message>
  ...
  <wsdl:portType name="IServiceWeb">
      ...
      <wsdl:operation name="GetPaymentInfo">
         <wsdl:input wsaw:Action="*****" message="tns:IServiceWeb_GetPaymentInfo_InputMessage"/>
         <wsdl:output wsaw:Action="*****" message="tns:IServiceWeb_GetPaymentInfo_OutputMessage"/>
       </wsdl:operation>
  </wsdl:portType>

When I initially attempted to generate classes, I got this error,

org.xml.sax.SAXParseException: A class/interface with the same name "org.package.GetPaymentInfoResponse" is already in use. Use a class customization to resolve this conflict.

I added a binding.xjb file with this content,

<?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"
    xsi:schemaLocation=" http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" version="2.1">
    <bindings
        node="wsdl:definitions/wsdl:message[@name='IServiceWeb_GetPaymentInfo_OutputMessage']/wsdl:part[@name='parameters']">
        <class name="GetPaymentInfoOutputMessage" />
    </bindings>
</bindings>

and the error I get is,

com.sun.istack.SAXParseException2: XPath evaluation of "wsdl:definitions/wsdl:message[@name='IServiceWeb_GetPaymentInfo_OutputMessage']/wsdl:part[@name='parameters']" results in empty target node

Any suggestions to get these files generated?

EDIT I had the wrong node declared, IServiceWeb_GetPaymentInfo_InputMessage should be IServiceWeb_GetPaymentInfo_InputMessage, the corrected binding is,

<?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"
    xsi:schemaLocation=" http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" version="2.1">
    <bindings
        node="wsdl:definitions/wsdl:message[@name='IServiceWeb_GetPaymentInfo_InputMessage']/wsdl:part[@name='parameters']">
        <class name="GetPaymentInfoOutputMessage" />
    </bindings>
</bindings>

and the error message is,

com.sun.istack.SAXParseException2: XPath evaluation of "wsdl:definitions/wsdl:message[@name='IServiceWeb_GetPaymentInfo_InputMessage']/wsdl:part[@name='parameters']" results in empty target node

Answer

Neill picture Neill · Jun 16, 2014

SOLVED

My binding file was missing the schemaLocation attribute giving the import value of the specific XSD, which is shown here, and the correct XPath expression for my specific schema,

<bindings schemaLocation="https://myURI/mySchema.xsd">
    <bindings
        node="//xs:complexType[@name='GetPaymentInfoResponse']">
        <class name="GetPaymentInfoResponseType" />
    </bindings>
</bindings>

Additionally, using JDK 1.6, I needed to d/l and add jaxb 2.2 jars to my jdk endorsed lib dir as described here, http://cxf.apache.org/docs/23-migration-guide.html

Using either of two alternate methods, {JAVA_HOME}/bin/wsimport.exe or using jaxws-maven-plugin, caused a "Use a class customization to resolve this conflict" error that was resolved using this configuration,

                <configuration>
                <args>
                    <arg>-B-XautoNameResolution</arg>
                    </args>
                            </configuration>

but would not run with the endorsed jars as above.

So, my classes are generated, now it's on to exercising the web service. Maven is a nice way to generate class files.