6

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
Neill
  • 556
  • 2
  • 8
  • 18
  • Not sure but possibly because your `node` attribute should start with a `//`? Can you not do something like `//*[@name='parameters']` instead? – WGS Jun 13 '14 at 19:11
  • @Nanashi, this fails with the error, XPath evaluation of "//wsdl:definitions/wsdl:message[@name='IServiceWeb_GetPaymentInfo_OutputMessage']/wsdl:part[@name='parameters']" results in empty target node – Neill Jun 14 '14 at 01:16
  • Is there a declaration for the element attribute that needs to be included? How would I declare it? – Neill Jun 14 '14 at 01:17

3 Answers3

2

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.

Neill
  • 556
  • 2
  • 8
  • 18
0

Your bindings file should declare the namespace for the XPath expression associated with the wsdl prefix you are using in the XPath expression:

<bindings xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
          xmlns="http://java.sun.com/xml/ns/jaxb" version="1.0"
          node="wsdl:definitions/wsdl:message[@name='IServiceWeb_GetPaymentInfo_OutputMessage']/wsdl:part[@name='parameters']">
    <class name="GetPaymentInfoInputMessage" />
</bindings>

If you have XPath expressions that use other namespaces (such as XML Schema types, SOAP envelopes, etc.), you must declare them as well and use the declared prefixes to qualify each selector. Any XPath selector that refers to an element that is part of a namespace must be prefixed (even if in the source the namespace is declared as default).

helderdarocha
  • 23,209
  • 4
  • 50
  • 65
0

In your snippet, the node is

<wsdl:message name="IServiceWeb_GetPaymentInfo_InputMessage">

while in your bindings file, you called an xpath that contains

<bindings
    node="wsdl:definitions/wsdl:message[@name='IServiceWeb_GetPaymentInfo_OutputMessage']/wsdl:part[@name='parameters']">

try changing the xpath in your bindings file to reflect IServiceWeb_GetPaymentInfo_InputMessage

<bindings
    node="wsdl:definitions/wsdl:message[@name='IServiceWeb_GetPaymentInfo_InputMessage']/wsdl:part[@name='parameters']">
Joel M. Lamsen
  • 7,143
  • 1
  • 12
  • 14
  • You are correct, I had the wrong node declared, however, it was a node that existed, just not the right one. I changed my node declaration to the correct node and get the same error, documented in **EDIT** in the original question. – Neill Jun 16 '14 at 14:26