12
Feb

The danger of importing multiple XSDs from the same namespace

When you define a Web Service interface with WSDLs and XSDs, you need to be careful on the structure of such elements, so I recommend you to avoid at all costs importing more than one XSD from the same namespace.

Importing multiple XSDs from the same namespace is not prohibited by the specification but it’s also not clear how parsers should handle them, so some parsers take only the first import into consideration while others take all of the imports. This is the worst situation ever as for some situations you will face errors and in others it will work.

As an example, take the following WSDL:


<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
	xmlns:tns="http://www.example.org/NewWSDLFile/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
	xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="NewWSDLFile"
	xmlns:schema="http://www.example.org/schema"
	targetNamespace="http://www.example.org/NewWSDLFile/">

	<wsdl:types>
		<xsd:schema targetNamespace="http://www.example.org/NewWSDLFile/">

			<xsd:import schemaLocation="Schema1.xsd" namespace="http://www.example.org/schema"/>
			<xsd:import schemaLocation="Schema2.xsd" namespace="http://www.example.org/schema"/>
			
			<xsd:element name="NewOperation">
				<xsd:complexType>
					<xsd:sequence>
						<xsd:element name="in" type="schema:MyType1" />
					</xsd:sequence>
				</xsd:complexType>
			</xsd:element>
			<xsd:element name="NewOperationResponse">
				<xsd:complexType>
					<xsd:sequence>
						<xsd:element name="out" type="schema:MyType2" />
					</xsd:sequence>
				</xsd:complexType>
			</xsd:element>
		</xsd:schema>
	</wsdl:types>

	<wsdl:message name="NewOperationRequest">
		<wsdl:part element="tns:NewOperation" name="parameters" />
	</wsdl:message>

	<wsdl:message name="NewOperationResponse">
		<wsdl:part element="tns:NewOperationResponse" name="parameters" />
	</wsdl:message>

	<wsdl:portType name="NewWSDLFile">
		<wsdl:operation name="NewOperation">
			<wsdl:input message="tns:NewOperationRequest" />
			<wsdl:output message="tns:NewOperationResponse" />
		</wsdl:operation>
	</wsdl:portType>

	<wsdl:binding name="NewWSDLFileSOAP" type="tns:NewWSDLFile">
		<soap:binding style="document"
			transport="http://schemas.xmlsoap.org/soap/http" />
		<wsdl:operation name="NewOperation">
			<soap:operation soapAction="http://www.example.org/NewWSDLFile/NewOperation" />
			<wsdl:input>
				<soap:body use="literal" />
			</wsdl:input>
			<wsdl:output>
				<soap:body use="literal" />
			</wsdl:output>
		</wsdl:operation>
	</wsdl:binding>

	<wsdl:service name="NewWSDLFile">
		<wsdl:port binding="tns:NewWSDLFileSOAP" name="NewWSDLFileSOAP">
			<soap:address location="http://www.example.org/" />
		</wsdl:port>
	</wsdl:service>

</wsdl:definitions>


If you validate this WSDL in Eclipse, it validates OK, however if you try to create Java classes to it using wsimport command, it presents some warnings indicating it can't find some of the types. Actually you see that the problems are found on the types of the second XSD imported, showing it was silently ignored by the parser. Bellow we see the warnings:


[WARNING] src-resolve: Cannot resolve the name 'schema:MyType2' to a(n) 'type definition' component.
line 24 of file:/D:/temp/NewWSDLFile.wsdl#types?schema1

[WARNING] src-resolve: Cannot resolve the name 'schema:MyType2' to a(n) 'type definition' component.
line 24 of file:/D:/temp/NewWSDLFile.wsdl#types?schema1

For other parsers it will not be just a warning, but an error that will make it impossible to consume the web service. For example, if you try to validate this WSDL via WS-I basic profile validation tool, it fails indicating it can’t find the types of the second XSDs.

So, all that said, avoid having multiple XSDs from the same namespace imported by another WSDL or XSD or you're going to have some hard times.


free b2evolution skin
29
Dec

What happened to Eclipse’s Generate XML from XSD Schema menu?

Eclipse and Oracle Enterprise Pack for Eclipse have a very helpful option to generate XML from a XSD as we can see bellow:

 

Sometimes, however, this menu just does not appear for a XSD file and this is due to the fact that the XSD file does not have the XML prolog, like the one bellow:

<?xml version="1.0" encoding="UTF-8"?>

 

Adding the prolog back to the XSD file, makes Eclipse treat the file as an XSD again and the Generate > XML File… menu will be back.

When you need to generate a XML from a XSD and the menu isn’t there, it can become an awful situation and this tip will help you to have the menu back.


free b2evolution skin
7
Oct

Defining smart ranges in XSD

Sometimes we need to specify a range in XML and to validate such XML the natural option is to leverage the XSD language for such.

The following XSD illustrates one way to define a range in XSD, where we defined a range of two dates:


<element name="DateRange" type="tns:DateRangeType"/>

<complexType name="DateRangeType">
  <sequence>
   <element name="From" type="date" />
   <element name="To" type="date" />
  </sequence>
</complexType>


 
The approach above is nice but it only works if what you want is always specify the start and end of the range. If your range may allow one of the sides to be omitted, tending to infinity, you will have to specify something like the one bellow:


<element name="DateRange" type="tns:DateRangeType"/>

<complexType name="DateRangeType">
  <sequence>
   <element name="From" type="date" minOccurs="0"/>
   <element name="To" type="date" minOccurs="0"/>
  </sequence>
</complexType>


 
The approach above is also nice but as both elements are optional, an element without From and To will be considered valid but this is something we do not want as in this case, we may omit the parent element at all. Our problem is that this element would be considered valid:


<DateRange/> 


 
We would like to consider an element valid only if contains at least the From, To or both elements. The solution for this dilemma is the following XSD:


<element name="DateRange" type="tns:DateRangeType"/>

<complexType name="DateRangeType">
  <sequence>
   <choice>
    <sequence>
     <element name="From" type="dateTime" />
     <element name="To" type="dateTime" minOccurs="0" />
    </sequence>
    <element name="To" type="dateTime" />
   </choice>
  </sequence>
 </complexType>


 

It may seem complicated at first sight but it’s extremely simple:

The XSD is a choice of one sequence where the element From is mandatory and the element To is optional. So an element of this type with From or From + To would be considered valid. The other part of the choice specifies element To, so an element of this type with only a single To element would also be valid, what covers all of ours requirements.


free b2evolution skin
30
Jun

A great book on WebLogic administration!

If you are a WebLogic Admin or even a developer willing to learn more about WebLogic infrastructure, I highly recommend the new launched book from my friend Dalton Iwazaki: Oracle WebLogic Server 12c Advanced Administration Cookbook.

I’m one of the book reviewers and I can assure it goes a long way teaching WLS installation, administration, tuning and troubleshooting in a very practical approach.

You can reach the book here and I can assure it’s a worth reading no matter your level on WLS infrastructure knowledge, I'm certain you'll learn something. Buy it!


free b2evolution skin
3
Feb

SOA Bundle Patches

Periodically Oracle releases some bundle patches over SOA versions like 11.1.1.5 and 11.1.1.6.

These patches are recommended and tested and you can find them in a single place by looking at the article 1485949.1 at MyOracle Support


free b2evolution skin

:: Next >>