I am writing an implementation for the OpenTravel Alliance message PkgAvail.
The version is 2006A.
I decided to use XMLBeans because it is a mature tool and it is the best 
supported binding for Axis2.

Using vanilla XmlBeans schema compiler works fine (version 2.10).
But when using the same message schemas from a WSDL it does not work.
The difference I see is that wsdl2java is using apache xmlschema...

It is easy to compile the schema using XMLBeans (complete or in parts).
For instance, to compile the request and response messages for OTA 
PkgAvail, simply use this command:

scomp -compiler c:\j2sdk1.4.2_12\bin/javac -mx 512m -src src 
OTA_PkgAvailRQ.xsd OTA_PkgAvailRS.xsd

The high level messages use the targetNamespace to set the namespace.

By design, all more primitive types are in separated schemas which are 
included and they do not define a namespace.
This is a documented OTA practice: see OTA 2006A, "XML Schema Design 
Best Practices"version 3.04 June 2006,page 15,
section 4.6.2 "No namespace for common XML schema files". The rationale 
states that the messages which includes simple types
will 'coerce' the content in the RQ or RS schema.

This looks fine and seems logical.

Also, the W3C specification documents this practice. Specifically, the 
document "XML Schema part 1: Structures" (W3C Recommendation 2 May 201) 
says the following in section 4.2.1:
=====
...
A <schema> information item may contain any number of <include> 
elements. Their schemaLocation attributes, consisting of a URI 
reference, identify other ·schema 

documents·, that is <schema> information items.

The ·XML Schema· corresponding to <schema> contains not only the 
components corresponding to its definition and declaration [children], 
but also all the components 

of all the ·XML Schemas· corresponding to any <include>d schema 
documents. Such included schema documents must either (a) have the same 
targetNamespace as the 

<include>ing schema document, or (b) no targetNamespace at all, in which 
case the <include>d schema document is converted to the <include>ing 
schema document's 

targetNamespace.
...
=====

So, xsd:include must work from wsdl2java the same as with scomp. And the 
included schema will be in the OTA's RQ or RS namespace according to the 
W3C recommendation AND the OTA's best practice guide.

The next step for me was to look at the OTA document "Implementation 
guide: WSDL", version 0.2, 7 June 2006.
On page 9 you'll find a sample OTA WSDL for a vehicule RQ/RS service 
which is pretty close to what I want.

I simply used this example WSDL as is... and the fun began.

I get an exception and it is related to the fact that there is no 
namespace in the included simple types.
The were some messages about this issue (google groups thread "Use xsd 
OTA"): Some people said it is bad practice from OTA, which is obviously 
wrong.


Here are some outputs...

==> File OTA_PkgAvailRQ.xsd: (to show you how types are included):


<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://www.opentravel.org/OTA/2003/05"; 
elementFormDefault="qualified" version="3.002" id="OTA2006A" 

xmlns:xs="http://www.w3.org/2001/XMLSchema"; 
xmlns="http://www.opentravel.org/OTA/2003/05";>
        <xs:include schemaLocation="OTA_PkgCommonTypes.xsd"/>
        <xs:include schemaLocation="OTA_SimpleTypes.xsd"/>
        <xs:include schemaLocation="OTA_CommonTypes.xsd"/>
...



==> File OTA_SimpleTypes.xsd: (to show there is no namespace):

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"; 
elementFormDefault="qualified" version="2.002" id="OTA2003A2006A">
        <xs:annotation>
                <xs:documentation xml:lang="en">All Schema files in the OTA 
specification are made available according to the terms defined by the 
OTA License 

Agreement at 
http://www.opentravel.org/ota_downloads_form.cfm</xs:documentation>
        </xs:annotation>
        <xs:simpleType name="ActionType">
                <xs:annotation>
                        <xs:documentation xml:lang="en">Identifes an action to 
take 
place.</xs:documentation>
                </xs:annotation>
                <xs:restriction base="xs:string">
                        <xs:enumeration value="Add-Update">
                                <xs:annotation>
                                        <xs:documentation xml:lang="en">
                        Typically used to add an item where it does not exist 
or to update an 
item where it does exist.
                        </xs:documentation>
                                </xs:annotation>
                        </xs:enumeration>
                        <xs:enumeration value="Cancel">
                                <xs:annotation>
                                        <xs:documentation xml:lang="en">
                        Typically used to cancel an existing item.
                        </xs:documentation>
                                </xs:annotation>
                        </xs:enumeration>
        ...
                </xs:restriction>
        </xs:simpleType>
...


======================

This is the OpenTravel Alliance WSDL Implementation Guide version 0.2, 7 
June 2006: Example from page 9 (file name OTA_VehResInterface.wsdl):

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/";
xmlns:ota="http://www.opentravel.org/OTA/2003/05";
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/";
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/";
xmlns:xs="http://www.w3.org/2001/XMLSchema";
targetNamespace="http://www.opentravel.org/OTA/2003/05";
name="VehReservationService">
<!-- Define data types (import OTA schemas) -->
<wsdl:types>
<xs:schema>
<xs:import namespace="http://www.opentravel.org/OTA/2003/05";
schemaLocation="OTA_VehResRQ.xsd"/>
</xs:schema>
<xs:schema>
<xs:import namespace="http://www.opentravel.org/OTA/2003/05";
schemaLocation="OTA_VehResRS.xsd"/>
</xs:schema>
</wsdl:types>
<!-- Define request and response messages-->
<wsdl:message name="VehicleReservationRequest">
<wsdl:part name="OTA_VehResRQ" element="ota:OTA_VehResRQ"/>
</wsdl:message>
<wsdl:message name="VehicleReservationResponse">
<wsdl:part name="OTA_VehResRS" element="ota:OTA_VehResRS"/>
</wsdl:message>
<!-- Define operation and reference messages-->
<wsdl:portType name="VehicleReservationPortType">
<wsdl:operation name="OTA_VehResRQ">
<wsdl:input message="ota:VehicleReservationRequest"/>
<wsdl:output message="ota:VehicleReservationResponse"/>
</wsdl:operation>
</wsdl:portType>
</wsdl:definitions>

And the binding/service definition WSDL (page 10):

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/";
xmlns:ota="http://www.opentravel.org/OTA/2003/05";
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/";
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/";
xmlns:xs="http://www.w3.org/2001/XMLSchema";
targetNamespace="http://www.opentravel.org/OTA/2003/05";>
<!-- Import Interface Definition WSDL-->
<import namespace="http://www.opentravel.org/OTA/2003/05"; 
location="OTA_VehResInterface.wsdl"/>
<!-- Define SOAP binding-->
<binding name="VehicleReservationBinding" 
type="ota:VehicleReservationPortType">
<!-- Use document style and not rpc-->
<soap:binding style="document" 
transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="OTA_VehResRQ">
<!-- Use 'literal' to include OTA XML as-is-->
<soap:operation soapAction="CreateReservation" style="document"/>
<input>
<soap:body use="literal" 
namespace="http://www.opentravel.org/OTA/2003/05"/>
</input>
<output>
<soap:body use="literal" 
namespace="http://www.opentravel.org/OTA/2003/05"/>
</output>
</operation>
</binding>
<!-- Define SOAP interface with previously declared binding-->
<service name="OTAVehicleReservationService">
<port name="VehicleReservationPort" 
binding="ota:VehicleReservationBinding">
<!-- Replace "http://mydomain/myservicename"; with actual service 
endpoint-->
<soap:address location="http://mydomain/myservicename"/>
</port>
</service>
</definitions>

I get an exception while processing the WSDL:

wsdl2java -uri vehicule.wsdl

Using AXIS2_HOME:   c:\JavaLib\axis2-std-1.0_bin
Using JAVA_HOME:    c:\Program Files\Java\jdk1.5.0_06
Retrieving document at 'OTA_VehResInterface.wsdl', relative to 
'file:/C:/workspace/TestOTA/WSDL/'.
Retrieving schema at 'OTA_VehResRQ.xsd', relative to 
'file:/C:/workspace/TestOTA/WSDL/OTA_VehResInterface.wsdl'.
Retrieving schema at 'OTA_VehicleCommonTypes.xsd', relative to 
'file:/C:/workspace/TestOTA/WSDL/OTA_VehResRQ.xsd'.
Retrieving schema at 'OTA_SimpleTypes.xsd', relative to 
'file:/C:/workspace/TestOTA/WSDL/OTA_VehicleCommonTypes.xsd'.
Retrieving schema at 'OTA_CommonTypes.xsd', relative to 
'file:/C:/workspace/TestOTA/WSDL/OTA_VehicleCommonTypes.xsd'.
Retrieving schema at 'OTA_SimpleTypes.xsd', relative to 
'file:/C:/workspace/TestOTA/WSDL/OTA_CommonTypes.xsd'.
Retrieving schema at 'OTA_AirCommonTypes.xsd', relative to 
'file:/C:/workspace/TestOTA/WSDL/OTA_VehicleCommonTypes.xsd'.
Retrieving schema at 'OTA_SimpleTypes.xsd', relative to 
'file:/C:/workspace/TestOTA/WSDL/OTA_AirCommonTypes.xsd'.
Retrieving schema at 'OTA_CommonTypes.xsd', relative to 
'file:/C:/workspace/TestOTA/WSDL/OTA_AirCommonTypes.xsd'.
Retrieving schema at 'OTA_CommonPrefs.xsd', relative to 
'file:/C:/workspace/TestOTA/WSDL/OTA_VehicleCommonTypes.xsd'.
Retrieving schema at 'OTA_SimpleTypes.xsd', relative to 
'file:/C:/workspace/TestOTA/WSDL/OTA_CommonPrefs.xsd'.
Retrieving schema at 'OTA_CommonTypes.xsd', relative to 
'file:/C:/workspace/TestOTA/WSDL/OTA_CommonPrefs.xsd'.
Retrieving schema at 'OTA_SimpleTypes.xsd', relative to 
'file:/C:/workspace/TestOTA/WSDL/OTA_VehResRQ.xsd'.
Retrieving schema at 'OTA_CommonTypes.xsd', relative to 
'file:/C:/workspace/TestOTA/WSDL/OTA_VehResRQ.xsd'.
Retrieving schema at 'OTA_AirCommonTypes.xsd', relative to 
'file:/C:/workspace/TestOTA/WSDL/OTA_VehResRQ.xsd'.
Retrieving schema at 'OTA_CommonPrefs.xsd', relative to 
'file:/C:/workspace/TestOTA/WSDL/OTA_VehResRQ.xsd'.
Retrieving schema at 'OTA_VehResRS.xsd', relative to 
'file:/C:/workspace/TestOTA/WSDL/OTA_VehResInterface.wsdl'.
Retrieving schema at 'OTA_VehicleCommonTypes.xsd', relative to 
'file:/C:/workspace/TestOTA/WSDL/OTA_VehResRS.xsd'.
Retrieving schema at 'OTA_SimpleTypes.xsd', relative to 
'file:/C:/workspace/TestOTA/WSDL/OTA_VehResRS.xsd'.
Retrieving schema at 'OTA_CommonTypes.xsd', relative to 
'file:/C:/workspace/TestOTA/WSDL/OTA_VehResRS.xsd'.
Retrieving schema at 'OTA_AirCommonTypes.xsd', relative to 
'file:/C:/workspace/TestOTA/WSDL/OTA_VehResRS.xsd'.
Retrieving schema at 'OTA_CommonPrefs.xsd', relative to 
'file:/C:/workspace/TestOTA/WSDL/OTA_VehResRS.xsd'.
log4j:WARN No appenders could be found for logger 
(org.apache.axis2.i18n.ProjectResourceBundle).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" 
org.apache.axis2.wsdl.codegen.CodeGenerationException: Error parsing 
WSDL
        at 
org.apache.axis2.wsdl.codegen.CodeGenerationEngine.<init>(CodeGenerationEngine.java:94)
        at org.apache.axis2.wsdl.WSDL2Code.main(WSDL2Code.java:32)
        at org.apache.axis2.wsdl.WSDL2Java.main(WSDL2Java.java:21)
Caused by: org.apache.axis2.AxisFault: java.lang.RuntimeException: 
java.lang.RuntimeException: java.lang.NullPointerException; nested 
exception is: 
        java.lang.RuntimeException: java.lang.RuntimeException: 
java.lang.RuntimeException: java.lang.NullPointerException
        at 
org.apache.axis2.description.WSDL2AxisServiceBuilder.populateService(WSDL2AxisServiceBuilder.java:243)
        at 
org.apache.axis2.wsdl.codegen.CodeGenerationEngine.<init>(CodeGenerationEngine.java:87)
        ... 2 more
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: 
java.lang.RuntimeException: java.lang.NullPointerException
        at 
org.apache.ws.commons.schema.SchemaBuilder.resolveXmlSchema(SchemaBuilder.java:1916)
        at 
org.apache.ws.commons.schema.SchemaBuilder.resolveXmlSchema(SchemaBuilder.java:1929)
        at 
org.apache.ws.commons.schema.SchemaBuilder.handleImport(SchemaBuilder.java:1714)
        at 
org.apache.ws.commons.schema.SchemaBuilder.handleXmlSchemaElement(SchemaBuilder.java:126)
        at 
org.apache.ws.commons.schema.XmlSchemaCollection.read(XmlSchemaCollection.java:250)
        at 
org.apache.axis2.description.WSDL2AxisServiceBuilder.getXMLSchema(WSDL2AxisServiceBuilder.java:959)
        at 
org.apache.axis2.description.WSDL2AxisServiceBuilder.copyExtensibleElements(WSDL2AxisServiceBuilder.java:1067)
        at 
org.apache.axis2.description.WSDL2AxisServiceBuilder.populateService(WSDL2AxisServiceBuilder.java:221)
        ... 3 more
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: 
java.lang.NullPointerException
        at 
org.apache.ws.commons.schema.SchemaBuilder.resolveXmlSchema(SchemaBuilder.java:1916)
        at 
org.apache.ws.commons.schema.SchemaBuilder.handleInclude(SchemaBuilder.java:1746)
        at 
org.apache.ws.commons.schema.SchemaBuilder.handleXmlSchemaElement(SchemaBuilder.java:121)
        at 
org.apache.ws.commons.schema.SchemaBuilder.build(SchemaBuilder.java:53)
        at 
org.apache.ws.commons.schema.XmlSchemaCollection.read(XmlSchemaCollection.java:255)
        at 
org.apache.ws.commons.schema.XmlSchemaCollection.read(XmlSchemaCollection.java:217)
        at 
org.apache.ws.commons.schema.SchemaBuilder.resolveXmlSchema(SchemaBuilder.java:1911)
        ... 10 more
Caused by: java.lang.RuntimeException: java.lang.NullPointerException
        at 
org.apache.ws.commons.schema.SchemaBuilder.resolveXmlSchema(SchemaBuilder.java:1916)
        at 
org.apache.ws.commons.schema.SchemaBuilder.handleInclude(SchemaBuilder.java:1746)
        at 
org.apache.ws.commons.schema.SchemaBuilder.handleXmlSchemaElement(SchemaBuilder.java:121)
        at 
org.apache.ws.commons.schema.SchemaBuilder.build(SchemaBuilder.java:53)
        at 
org.apache.ws.commons.schema.XmlSchemaCollection.read(XmlSchemaCollection.java:255)
        at 
org.apache.ws.commons.schema.XmlSchemaCollection.read(XmlSchemaCollection.java:217)
        at 
org.apache.ws.commons.schema.SchemaBuilder.resolveXmlSchema(SchemaBuilder.java:1911)
        ... 16 more
Caused by: java.lang.NullPointerException
        at 
org.apache.ws.commons.schema.SchemaBuilder.handleSimpleType(SchemaBuilder.java:343)
        at 
org.apache.ws.commons.schema.SchemaBuilder.handleSimpleType(SchemaBuilder.java:477)
        at 
org.apache.ws.commons.schema.SchemaBuilder.handleXmlSchemaElement(SchemaBuilder.java:104)
        at 
org.apache.ws.commons.schema.SchemaBuilder.build(SchemaBuilder.java:53)
        at 
org.apache.ws.commons.schema.XmlSchemaCollection.read(XmlSchemaCollection.java:255)
        at 
org.apache.ws.commons.schema.XmlSchemaCollection.read(XmlSchemaCollection.java:217)
        at 
org.apache.ws.commons.schema.SchemaBuilder.resolveXmlSchema(SchemaBuilder.java:1911)
        ... 22 more


The problem happens in 
org.apache.ws.commons.schema.SchemaBuilder.handleSimpleType:
...
           if (restrictionEl.hasAttribute("base")) {
                String name = restrictionEl.getAttribute("base");
                String[] temp = Tokenizer.tokenize(name, ":");
                String namespace = "";

                if (temp.length != 1) {
                    namespace = temp[0];
                }

                //let it crash because its mean being refered
                //to unregistered namespace
(a)             namespace = schema.namespaces.get(namespace).toString();
                name = Tokenizer.lastToken(name, ":")[1];
                restriction.baseTypeName = new QName(namespace, name);
...

The namespace="" and the schema to which the code refers is the included 
one (it defines ws=http://www.w3.org/2001/XMLSchema).
So, the get(namespace) at (a) returns null and we get a NPE right after.

There is definitely a difference between schema handling in scomp and 
using WSDL2Java when it comes to "include" directives.
To me, the problem is in the apache commons schema component.
I used the version packaged with Axis2 1.0 : XmlSchema-1.0.2
I also tried with the latest release: 1.0.3 and got the same exception.
I saw no wiki, jira, or other mecanism to report bugs for this project 
(looking at http://ws.apache.org/commons/XmlSchema/index.html): any 
idea?

I would appreciate if we can identify a few OTA schema users in this 
list so we can exchange ideas and fix this problem.
Then, we should report our results, our successes, to the OTA Google 
group implementers forum: that would give some visibility for Axis2.
One posting on this forum mentioned an interoperability project to test 
various open source frameworks with OTA schemas and WSDL.
I hope we can make it work so that Axis2 can be judged as good framework 
for OTA-related projects.

The first thing I would like to see is someone who would try the same 
steps I have done so far, and we'll work on a solution from there.

_____________________________________________________________
Obtenez aussi votre adresse electronique gratuite de
Quebecemail.com http://www.quebecemail.com, un service gratuit et permanent.

Reply via email to