[ http://issues.apache.org/jira/browse/WSCOMMONS-87?page=all ]
Marc Gagnon updated WSCOMMONS-87: --------------------------------- Attachment: XmlSchemaTestInclude.zip I attached the test files mentioned in the previous comment. Also, here is some background information about the origin of the problem. (this is a copy of an email I sent originally on the axis2 users liste and on the Google OTA implementers forum). --- I observed the same issue with another toolkit (axis2). Reference: http://marc.theaimsgroup.com/ (search for "xsd:include", message title "[Axis2] WSDL2Java does not handle xsd:include correctly") I am willing to switch to xfire if this issue gets solved! I agree on a previous comment: the issue lies in the Apache SchemaBuilder. The problem is with the following construct found in the OTA file "OTA_SimpleTypes.xsd": ... <xs:simpleType name="PaymentCardCodeType"> <xs:annotation> <xs:documentation xml:lang="en">The 2 digit code used that references the credit card used.</xs:documentation> </xs:annotation> <xs:union> <xs:simpleType> <xs:restriction base="UpperCaseAlphaLength1to2"> .. The base mentioned above is defined a few lines later in the same file: ... <xs:simpleType name="UpperCaseAlphaLength1to2"> ... Note that the shema does not use a fully qualified name --> base="UpperCase..". In most other restriction base types of the same file, a fully qualified name is used: ... <xs:simpleType name="TransactionActionType"> <xs:annotation> <xs:documentation xml:lang="en">To specify the type of action requested when more than one function could be handled by the message. </xs:documentation> </xs:annotation> <xs:restriction base="xs:string"> <xs:enumeration value="Book"/> ... In this case, base="xs:string". Looking at the code where the NPE happens, we see that a fully qualified name is mandatory: Look at class SchemaBuilder, method handleSimpleType: ... XmlSchemaSimpleType handleSimpleType(XmlSchema schema, Element simpleEl, Element schemaEl) { ... 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 namespace = schema.namespaces.get(namespace).toString(); name = Tokenizer.lastToken(name, ":")[1]; restriction.baseTypeName = new QName(namespace, name); //simpleType.name = name; } else if (inlineSimpleType != null) { ... The comment in this code clearly states that a fully qualified name is required when defining a restriction base type definition for a simple type. Now, what is the good behavior in this situation? To summarize, from a WSDL definition using OTA shema, we have a xsd:include of a message like "OTA_HotelAvailRQ.xsd". This message includes basic types like "OTA_SimpleTypes.xsd" which defines UpperCaseAlphaLength1to2 which is used as a base to define "PaymentCardCodeType". We need to follow the namespace definitions closely in this scenario in order to understand what the code should have done instead of the NPE. Our understanding must also be valid agains the W3C specification... Let's start with the WSDL (I'm using the files.ZIP attachement): In types, we find: <schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:client="http://xmlns.oracle.com/OTA_HotelAvail" xmlns:ns1="http://www.opentravel.org/OTA/2003/05" xmlns:plnk="http://schemas.xmlsoap.org/ws/2003/05/partner-link/"> <import namespace="http://www.opentravel.org/OTA/2003/05" schemaLocation="xsd/OTA_HotelAvailRQ.xsd"/> </schema> The default namespace is therefore "http://www.opentravel.org/OTA/2003/05" The import declares the same namespace. Now, in file OTA_HotelAvailRQ.xsd: <xs:schema xmlns="http://www.opentravel.org/OTA/2003/05" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.opentravel.org/OTA/2003/05" elementFormDefault="qualified" version="1.005" id="OTA2006A"> ... <xs:include schemaLocation="OTA_SimpleTypes.xsd"/> Again, the default namespace is "http://www.opentravel.org/OTA/2003/05", this is also the target namespace. Finally, look at the OTA_SimpleTypes.xsd file: <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" version="2.002" id="OTA2003A2006A"> Here, only the xs namespace is defined for internal references like xs:string. The real question is: Which namespaces should be known and valid when dealing with this inclusion coming from OTA_HotelAvailRQ? In the OTA messages, 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. ... ===== 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. > SchemaBuilder handleSimpleType does not find default namespace which gives a > NPE > -------------------------------------------------------------------------------- > > Key: WSCOMMONS-87 > URL: http://issues.apache.org/jira/browse/WSCOMMONS-87 > Project: WS-Commons > Issue Type: Bug > Components: XmlSchema > Environment: WinXP home, jdk 1.5.0_06, > also reported as xfire-617 > Reporter: Marc Gagnon > Attachments: XmlSchemaTestInclude.zip > > > This issue was reported on axis2's user list and later in xfire as issue > xfire-617. > I've been able to reproduce the issue in XmlSchema independently of xfire > (see attached files). > To reproduce, get XmlSchema (I used 1.0.3, same behavior as 1.0.1) and unzip > IncludeTest.java in the tests directory, unzip the xsd files in > test-resources and run the unit tests. > One test case is ok: the one which defines a default namespace in the > included file. > The other test case fails because there is no default namespace defined, just > like in OTA_SimpleTypes.xsd > Sample xsd from the attachement: > <schema targetNamespace="http://soapinterop.org/xsd" > xmlns="http://www.w3.org/2001/XMLSchema" > xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" > xmlns:xsd="http://www.w3.org/2001/XMLSchema" > xmlns:xsd1="http://soapinterop.org/xsd" > xmlns:xsd2="http://soapinterop.org/xsd2" > elementFormDefault="qualified"> > <include schemaLocation="includeAux.xsd"/> > </schema> > includeAux= > <schema > xmlns="http://www.w3.org/2001/XMLSchema" > xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" > xmlns:xsd="http://www.w3.org/2001/XMLSchema" > xmlns:xs="http://www.w3.org/2001/XMLSchema" > xmlns:xsd1="http://soapinterop.org/xsd2" > elementFormDefault="qualified"> > <xs:simpleType name="PaymentCardCodeType"> > <xs:union> > <xs:simpleType> > <xs:restriction base="UpperCaseAlphaLength1to2"/> > </xs:simpleType> > </xs:union> > </xs:simpleType> > <xs:simpleType name="UpperCaseAlphaLength1to2"> > <xs:restriction base="xs:string"> > <xs:pattern value="[A-Z]{1,2}"/> > </xs:restriction> > </xs:simpleType> > </schema> > This example is ok, remove line <<xmlns="http://www.w3.org/2001/XMLSchema">> > in the file above and it will fail. It seems to me that this declaration > should be considered implicit and this should be handled in > ShemaBuilder.handleSimpleType -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]