SOA / Web Services / Java

A Technology Blog

Archive for February, 2009

Parse WSDL effectively

Posted by Vivek on February 4, 2009

As a WSDL’s constituents are well-defined already, it is feasible to use a parser that can get the elements of the WSDL using APIs that are already defined. This will minimize complexity in the code and will help in achieving better performance.


Oracle WSDL parser is one such option.


It is only needed to import the necessary classes as the APIs are already defined and packaged with wsdl.jar.


//importing the necessary classes from library

import oracle.wsdl.WSDLDocument;

import oracle.wsdl.internal.Binding;

import oracle.wsdl.internal.Definitions;

import oracle.wsdl.internal.Documentation;

import oracle.wsdl.internal.Import;

import oracle.wsdl.internal.Message;

import oracle.wsdl.internal.PortType;




WSDLDocument wsdldoc = new WSDLDocument(wsdl_url);

//getting definition element

Definitions definition = wsdldoc.getDefinitions();

//getting service element

Map servicesMap = definition.getServices();

//getting binding element

Map bindingsMap = definition.getBindings();

//getting PortType element

Map ptypesMap = definition.getPortTypes();

//getting message element

Map messagesMap = definition.getMessages();

//getting import details

Map importsMap = definition.getImports();

//getting documentation details

Documentation docs = definition.getDocumentation();



As there can be multiple elements, an “iterator” can be used to parse an individual element.

For Example:


Iterator iterator = servicesMap.entrySet().iterator();

        while (iterator.hasNext()) {

            Map.Entry me = (Map.Entry);




The above code fragments keep things fairly simple while processing a WSDL.


Apache Woden


Woden provides Java class library for reading, manipulating, creating and writing WSDL documents.


Woden’s DOM-based XML parsing depends on Apache Xerces 2.7.1. Its XML Schema support it depends on the schema parser and object model implemented by the Apache Web Services Commons (ws-commons) XmlSchema project.


//importing necessary classes from woden jars

import org.apache.woden.WSDLException;

import org.apache.woden.WSDLFactory;

import org.apache.woden.WSDLReader;

import org.apache.woden.wsdl20.Binding;

import org.apache.woden.wsdl20.Description;

import org.apache.woden.wsdl20.Interface;

import org.apache.woden.wsdl20.Service;





WSDLFactory factory = WSDLFactory.newInstance();

WSDLReader reader = factory.newWSDLReader();

reader.setFeature(WSDLReader.FEATURE_VALIDATION, true);

String wsdlurl = “C://axis2-1.4.1//newwsdl.wsdl”;


//reading the WSDL Document

DescriptionElement descElem = (DescriptionElement) reader.readWSDL(wsdlurl);

Description descComp = descElem.toComponent();


//getting Interface, Binding and Service elements

InterfaceElement[] interfaces = descElem.getInterfaceElements();

BindingElement[] bindings = descElem.getBindingElements();

ServiceElement[] services = descElem.getServiceElements();



Complete details about usage and extensibility of woden are available at:





JWSDL is another option that is intended for use by developers of Web services tools and others who need to utilize WSDL documents in Java.

JWSDL is designed to allow users to read, modify, write, create and re-organize WSDL documents in memory. JWSDL is not designed to validate WSDL documents beyond syntactic validity. One use of JWSDL is to develop a tool that validates WSDL semantically.

JWSDL is designed for use in WSDL editors and tools where a partial, incomplete or incorrect WSDL document may require representation.


Details of JWSDL can be obtained by accessing the following link:


Posted in Java/J2EE, Web Services | Tagged: , , | 5 Comments »

What XML parser to use?

Posted by Vivek on February 3, 2009

XML, being the lingua franca of web services, has found its use in many applications mostly because of its platform agnostic feature. Applications using XML and XML-based artifacts like SOAP, WSDL etc. tremendously require traversal, customization and transformation of these artifacts to suit its needs. This is the reason why we see parsing and binding (marshalling and unmarshalling) of XML documents at various critical points in an application. One important thing to note is that XML is verbose and leads to various performance issues when processed, especially in complex environments. Over the years, we have seen use of DOM (Document Object Model) and SAX (Simple API for XML) parsers but these parsers have their own limitations and require trade-offs in some situations. For example,  

DOM requires in-memory representation of the XML document, which exerts unnecessary pressure on system resources and is thus considered impractical for large documents. Also, DOM APIs introduces complexity while processing XML nodes.

Other alternatives or parsers that use tree-based APIs are dom4j, JDOM and XOM. While dom4j document object model is fast and memory-efficient and offers great extensibility, JDOM is mostly known for its ease of use. The XOM document object model protects users from common mistakes in the use of XML, while offering good performance and memory efficiency. 

SAX, on the other hand, is inappropriate when reordering or cross-referencing of XML nodes is desired. 

WoodStox is an XML processor that combines the best of both the worlds. In other words, it is easy to use or convenient like DOM and efficient like SAX. It is an open source implementation of StAX pull parser standard. It, however, encounters performance issues like Xerces2, the Apache Implementation of the W3C document object model standard, when dealing with small documents, for eg. SOAP. 

To improve the performance of such widely-used XML parsers, Apache introduced a new parser. This new parser, AXIs Object Model (AXIOM), is considered not just another object model but a very useful and performance enhancing parser for CPU and Memory intensive applications. AXIOM tries to achieve its objective of being a memory-efficient parser by deferring creation of XML tree when not required. AXIOM is StAX (Streaming Api for XML) based object model and it implements “pull-parsing” methodology, unlike SAX and DOM. It also has built in support for XML Optimized Packaging (XOP) and MTOM, the combination of which allows XML to carry binary data efficiently and in a transparent manner. Another important feature supported by AXIOM is that it provides APIs to parse SOAP (Simple Object Access Protocol) documents effectively. When the APIs are already defined, complexity can be easily avoided and performance overhead can be easily tackled. Apache’s SOAP engine Axis2, thus, has provision for AXIOM. AXIOM’s ability to support various binding mechanisms helps it optimize the marshalling and unmarshalling of XML fragments and hence, results in improved performance.


While AXIOM has pre-defined APIs for parsing a SOAP message, it should also be possible to define APIs that can extract elements from a WSDL (Web Services Description Language) file.


Posted in Java/J2EE, Web Services | Tagged: , , | 2 Comments »