Thursday, June 10, 2010

WSDL Parser

Since I am not a monkey (well, I am, but with some value added),
I don't like to type what I can generate.

It happens often to have to generate the same kind of artifacts for each operation in a WSDL.
It becomes then very important to be able to parse the WSLD and find out all its components.

Good candidates containing a WSDLDocument class are:


or C:\bea11\jrockit_160_17_R28.0.0-679\lib\tools.jar


I have tried some of them but could not make them work.

This gives some clues.

Oracle WSDL parser: you get it by installing JDeveloper, it's in C:\beajdev11\jdeveloper\webservices\lib\wsdl.jar

Apache Woden


Javadoc of Oracle WSDL parser is at

Using the Oracle WSDL parser, I get a

Exception in thread "Main Thread" oracle.wsdl.internal.WSDLException: oracle.xml.parser.v2.XMLParseException: Start of root element expected.
    at oracle.wsdl.WSDLDocument.getDefinitions(
    at com.acme.wsdl.WSDLParser.execute(
    at com.acme.wsdl.WSDLParser.main(

I give up.

I try Woden and I get:

WSDLException: faultCode=INVALID_WSDL: Fatal WSDL error:
0:0,WSDL501,Expected a "{}description" element, but found a "{}definitions" element instead.:

Googling around I discover that this means that my WSDL is a 1.1 while Woden processes only 2.0.

You can find here a XSL converter from 1.1 to 2.0
Once converted 1.1 into 2.0 format, Woden manages to parse the WSDL but I get a warning:

The targetNamespace '' is not dereferencable.

which means (I think) that a URL connection open to retrieve the resource gets a "connection refused" (to dereference= to access).

This is a piece of code to print all operations declared in a WSDL:

package com.acme.wsdl;

import org.apache.woden.WSDLException;
import org.apache.woden.WSDLFactory;
import org.apache.woden.WSDLReader;
import org.apache.woden.wsdl20.Description;
import org.apache.woden.wsdl20.xml.BindingElement;
import org.apache.woden.wsdl20.xml.DescriptionElement;
import org.apache.woden.wsdl20.xml.InterfaceElement;
import org.apache.woden.wsdl20.xml.InterfaceOperationElement;
import org.apache.woden.wsdl20.xml.ServiceElement;

public class WSDLParserApache {
public static void main(String[] args) throws WSDLException {
    WSDLParserApache wsdlParserApache = new WSDLParserApache();

public void execute() throws WSDLException {

String filename1 = "C:/bea11/user_projects/workshops/default/GEO_OSB_Portal/WSDL/GEOOSBService20.WSDL";

WSDLFactory factory = WSDLFactory.newInstance();

WSDLReader reader = factory.newWSDLReader();

reader.setFeature(WSDLReader.FEATURE_VALIDATION, true);

String wsdlurl = filename1;

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

InterfaceElement[] interfaces = descElem.getInterfaceElements();

// getting all operations
for (InterfaceElement iface : interfaces) {
   for (InterfaceOperationElement ioe : iface.getInterfaceOperationElements()) {



WebSphere Guy said...


Thanks for your sharing on how to get operations using woden.

Do you know how to get the arguments / parameters for the operations given that the xsd schema for the wsdl is imported?

Pierluigi Vernetto said...

I am sorry WG, I have tried retrieving info about parameter names and types but I could not figure out how to do it... there is a promising getInterfaceMessageReferenceElements() retrieving a InterfaceMessageReferenceElement[] but then who knows...