Wsdl20Validator.java - WSDL 2.0 Validator

This section provided a tutorial example on how to create a WSDL 2.0 document validator with the Woden Java API.

If we use the WSDLReader.readWSDL() parse method from the Woden API, we can actually create a very simple WSDL 2.0 document validator, Wsdl20Validator.java:

/* Wsdl20Validator.java
 * Copyright (c) HerongYang.com, All Rights Reserved.
 */
import org.apache.woden.WSDLFactory;
import org.apache.woden.WSDLReader;
import org.apache.woden.wsdl20.Description;
class Wsdl20Validator {
   public static void main(String[] args) {
      if (args.length < 1) {
         System.err.println("Usage: java Wsdl20Validator URL");
         System.err.println("URL example: file:Hello_WSDL_20_SOAP.wsdl");
         return;
      }
      try {
         WSDLFactory wFactory = WSDLFactory.newInstance();
         WSDLReader wReader = wFactory.newWSDLReader();
         wReader.setFeature(WSDLReader.FEATURE_VALIDATION, true);
         Description wDescription = wReader.readWSDL(args[0]);
         System.out.println("This is a valid WSDL 2.0 document.");
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

First, let's try it with a valid WSDL 2.0 document, Hello_WSDL_20_SOAP:

C:\herong>javac -cp .;\local\axis2\lib\* Wsdl20Validator.java

C:\herong>java -cp .;\local\axis2\lib\* Wsdl20Validator \
   file:Hello_WSDL_20_SOAP.wsdl

This is a valid WSDL 2.0 document.

Now, let's try it with an invalid WSDL 2.0 document:

C:\herong>java -cp .;\local\axis2\lib\* Wsdl20Validator \
   file:Hello_WSDL_11_SOAP.wsdl

2:55:23 PM org.apache.woden.internal.ErrorHandlerImpl error
SEVERE: Woden[Error],5:56,null,cvc-elt.1.a: Cannot find the declaration of
   element 'wsdl:definitions'.

2:55:23 PM org.apache.woden.internal.ErrorHandlerImpl fatalError
SEVERE: Woden[Fatal Error],0:0,WSDL514,It appears as though you are trying
   to parse a WSDL 1.1 document but Woden is a WSDL 2.0 parser.

WSDLException: faultCode=INVALID_WSDL: Fatal WSDL error:
0:0,WSDL514,It appears as though you are trying to parse a WSDL 1.1 document
  but Woden is a WSDL 2.0 parser.:
	at org.apache.woden.internal.ErrorReporterImpl.reportError(...)
  at org.apache.woden.internal.BaseWSDLReader.parseDescription(...)
	at org.apache.woden.internal.DOMWSDLReader.readWSDL(...)
	at Wsdl20Validator.main(Wsdl20Validator.java:18)

Not too bad. It does detect the obvious error.

Table of Contents

 About This Book

 Introduction to WSDL 2.0

 WSDL 2.0 Document Structure and Syntax

 WSDL Version 2.0 Part 2: Adjuncts

 WSDL 2.0 Document Examples with SOAP Binding

 Using WSDL Document in Java Apache Axis2/Java for WSDL

Apache Woden for WSDL Documents in Java

 What Is Apache Woden - WSDL Parser API

 Java API for WSDL 2.0 Component Model

 WodenHelloComponent.java - Testing WSDL 2.0 Components

 Java API for WSDL 2.0 Element Model

 WodenHelloElement.java - Testing WSDL 2.0 Elements

Wsdl20Validator.java - WSDL 2.0 Validator

 WSDL 2.0-2 Adjuncts Not Supported by Woden API

 Convert WSDL 1.1 to 2.0 with Woden API

 SoapUI - Web Service Testing Tool

 PHP SOAP Extension for WSDL

 Perl SOAP::Lite for WSDL

 Introduction to WSDL 1.1

 WSDL 1.1 Document Structure and Syntax

 WSDL 1.1 Binding Extension for SOAP 1.1

 SoapUI as WSDL 1.1 Testing Tool

 WSDL 1.1 and SOAP 1.1 Examples - Document and RPC Styles

 PHP SOAP Extension for WSDL 1.1

 Perl SOAP::Lite for WSDL 1.1

 Apache Axis2/Java for WSDL 1.1

 Using WSDL2Java to Generate Web Service Stub Classes

 WSDL 1.1 Binding Extension for SOAP 1.2

 WSDL 1.1 and SOAP 1.2 Examples - Document and RPC Styles

 SOAP 1.2 Binding - PHP, Java and Perl Clients

 WSDL Related Terminologies

 Outdated Tutorials

 References

 Full Version in PDF/EPUB