Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I specify JAXB customizations externally to a WSDL file?

I have a WSDL file for a service implemented in .NET. I also have the same file with some "customizations" made by a 3rd-party to make the file tolerable to wsimport, mostly of the form:

<s:annotation>
  <s:appinfo>
    <jaxb:property name="result"/>
  </s:appinfo>
</s:annotation>

I'd like to be able to process the original WSDL from the vendor plus these overrides, but I'd like to specify them externally. I see that I can use the -b option for wsimport for "binding files" and I've tried to write an override file that currently looks like this:

<jxb:bindings version="1.0"
  xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
  xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <jxb:bindings node="//xs:element[@name='MyElementResult']">
    <jxb:property name="result"/>
  </jxb:bindings>
</jxb:bindings>

I've verified that "MyElementName" does in fact exist, in an element found here:

<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions
     xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
     xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
     xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
     xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
     xmlns:tns="vendor-uri"
     xmlns:s="http://www.w3.org/2001/XMLSchema"
     xmlns:s2="http://microsoft.com/wsdl/types/"
     xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
     xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
     targetNamespace="vendor-namespace"
     xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">

  [...]
  <s:element name="MyElementResponse">
    <s:complexType>
      <s:sequence>
        <s:element minOccurs="0" maxOccurs="1" name="MyElementResult" type="tns:Result" />

I'm getting this warning (and therefore no changes) from wsimport:

[ERROR] XPath evaluation of "//xs:element[@name='MyElementResult']" results in empty target node
  line 4 of file:/Users/..../wsdl/custom-bindings.xjb

Am I missing something in my declaration(s)? Do I have my XPath expression incorrect? If I get my XPath/overrides working, is it formatted correctly in order to achieve the same result as if I had edited the original WSDL?

Is this even possible using external files, or will I have to re-modify any future versions of the WSDL with these same changes?

like image 379
Christopher Schultz Avatar asked Sep 13 '13 14:09

Christopher Schultz


People also ask

How add binding to WSDL?

In the Customization Options wizard page, click the Add button and choose WebContent/WEB-INF/wsdl/productBindings. xml from the Bindings Selection dialog. Click Finish. You may get a prompt for overwriting the ProductWebServiceService.

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?

Generally we create a bindings file with . 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.

When parsing XML What is the default value of choice content property in the global binding attribute?

choiceContentProperty can be either true, false, 1, or 0. The default value is false.


1 Answers

You need to give the schema location in your bindings XML file.

<jxb:bindings version="1.0"
     xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
     xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <jxb:bindings 
         schemaLocation="PATH_TO_YOUR_WSDL#types?schema1"
         node="//xs:schema[@targetNamespace='SCHEMA_NAMESPACE']">
        <jxb:bindings node="//xs:element[@name='MyElementResult']">
            <jxb:property name="result"/>
        </jxb:bindings>
    </jxb:bindings>
</jxb:bindings>

The #types?schema1 after the WSDL file name will specify which schema in the WSDL you are binding, starting at 1.

like image 127
Michael Edgar Avatar answered Sep 27 '22 22:09

Michael Edgar