Wizard API updated!
Tim Boudreau has released a new version of the Swing Wizard library (version 0.997) that fixes the WizardException bug reported in JavaWorld's recent Open Source Java Project profile. The article's examples have been reworked to test out the new, improved WizardException. Thanks, Tim, for this helpful fix!
Open Source Java Projects: The Wizard API

Newsletter sign-up

Sign up for our technology specific newsletters.

Enterprise Java
View all newsletters

Email Address:

Client-side WSDL processing with Groovy and Gant

Automatically generate Java Web service clients with Axis2, XFire, CXF, and Java 6, including WSDL compatibility checks

Like it or not, service-oriented architecture (SOA) is a hot topic, and SOAP-based Web services have emerged as the most common implementation of SOA. But, as James Governor put it, "SOA reality brings SOA problems." You can mitigate these problems by creating useful Web service clients, and also by thoroughly testing your Web services on both the server side and the client side. WSDL files play a central role in both of these activities, so in this article Klaus P. Berg presents an extensible toolset that facilitates client-side WSDL processing using Gant and Groovy.

As part of a cross-platform Web service testing team responsible for testing functional aspects as well as the performance, load, and robustness of Web services, I recently realized the need for a small, easy-to-use, command-line-based solution for WSDL processing. I wanted the toolset to help testers and developers check and validate WSDL 1.1 files coming from different sources for compatibility with various Web service frameworks, as well as generating test stubs in Java to make actual calls. For the Java platform, that meant using Java 6 wsimport, Axis2, XFire, and CXF. (We also needed an environment based on Visual Studio .Net, and C# that tested WSDL and the services themselves in a pure-Windows environment -- but that's another story not suited to an article in a Java magazine.)

We started client-side test development with XFire, but then switched to Axis2 because of changing customer requirements in our agile project. (Axis2 was considered to be more popular and widespread than XFire.) We also used ksoap2 -- a lightweight Web service framework especially for the Java ME developer. We didn't expand the toolset to use ksoap2 because it has no WSDL-to-Java code generator.

Besides being controllable via simple commands, the toolset had to be able to integrate at least the WSDL checker into an automated build environment like Ant. One solution would have been to develop everything as a set of Ant targets. But executing everything with Ant is cumbersome when tasks become more complex, and you need control structures like if-then-else or for loops.

Even using ant-contrib binds you to XML-structures that are not easy to read, although you will have more functionality available. Anyhow, in the end you might need to implement some jobs as Ant tasks. All of this is possible, of course, but I was looking for a more elegant solution. Finally, I decided to use Groovy and a smart combination of Groovy plus Ant, called Gant. The components I have developed for the resulting Toolset can be divided into two groups:

  • The Gant part is responsible for providing some "targets" for the tester's everyday work, including the WSDL-checker and a Java parser/modifier component.
  • The WSDL-checker part is implemented with Groovy, but callable inside an Ant environment (via Groovy's Ant task) as part of the daily build process

That is an overview of the programming and scripting languages I used to build the Groovy and Gant Toolset. Now let's consider the technologies in detail.

Overview of Ant, Groovy, and Gant

Apache Ant is a software tool for automating software build processes. It is similar to make but is written in the Java language, requires the Java platform, and is best suited to building Java projects. Ant is based on an XML description of targets and their dependencies. Targets include tasks that every project needs, like clean, compile, javadoc, and jar. Ant is the de-facto standard build tool for Java, although Maven is making inroads.

Groovy is an object-oriented programming and scripting language for the Java platform, with features like those of Perl, Ruby, and Python. Groovy sources are dynamically compiled to Java bytecode that works seamlessly with your own Java code or third-party libraries. By means of the Groovy compiler, you can also produce bytecode for other Java projects. It is fair to say that I am biased towards Groovy compared to other scripting languages such as Perl or Ruby. While other people's preferences and experiences may be different from mine, the integration between Groovy and Java code is thorough and smooth. It was also easy, coming from Java, to get familiar with the Groovy syntax. What made Groovy especially interesting for solving my problems was its integration with Ant, via AntBuilder.

Gant (shorthand for Groovy plus Ant) is a build tool and Groovy module. It is used for scripting Ant tasks using Groovy instead of XML to specify the build logic. A Gant build specification is just a Groovy script and so -- to quote Gant author Russel Winder -- can deliver "all the power of Groovy to bear directly, something not possible with Ant scripts." While it might be considered a competitor to Ant, Gant relies on Ant tasks to actually do things. Really it is an alternative way of doing builds using Ant, but using a programming language, instead of XML, to specify the build rules. Consider using Gant if your Ant XML file is becoming too complex, or if you need the features and control structures of a scripting language that cannot be easily expressed using the Ant syntax.

Before you start examining the code in the next sections, here's a word about the OS and Java environment for the tools presented in this article, as well as a preview of what you will find if you download the toolset and associated files.

1 | 2 | 3 | 4 | 5 | 6 | 7 |  Next >

Discuss

Start a new discussion or jump into one of the threads below:

Subject Replies Last post


Resources

 

Downloads

  • Get the source packet for this article, which includes the Groovy and Gant Toolset.
  • Groovy: A dynamic language for the Java platform.
  • Gant: Groovy plus Ant
  • Apache Ant: A build utility for the Java platform.
  • StringUtils: Useful add-ons to the java.lang.String class.
  • BeanUtils: Provides easy-to-use wrappers around reflection and introspection capabilities to work with Java beans.
  • Ant-Contrib tasks: A collection of tasks (and types and other tools) for Apache Ant.
  • JavaCC: A Java parser that understands Java 5 syntax.
  • Eclipse Groovy Plugin: Allows you to edit, compile, and run Groovy scripts and classes. Requires at least Eclipse 3.2.
  • WSI-Basic profile: Recommendations from the Web Services Interoperability Organization.
  • ksoap2: A lightweight Web service framework for JME development.
  • Apache Axis2: A complete re-design and re-write of the widely used Apache Axis SOAP stack, built on the lessons learned from Apache Axis. Apache Axis2 is the core engine for Web services.
  • XFire: Codehaus XFire is a next-generation Java SOAP framework, built on a low-memory StAX-based model for high performance.
  • CXF: Apache CXF is an open source Web services framework. It is the merger of XFire and IONA's Celtix project into a new project, Apache CXF, currently under incubation at the Apache Software Foundation.
  • Java 6: From JDK 6 you will need rt.jar and tools.jar, but only if you want to use Java 6 wsimport with Java 5 installed. Note that you do not have to install a Java 6 JRE to use wsimport with the Groovy and Gant Toolset.