2009/01/02
2 Jan, 2009

Reference Guide to Axis2 Code Generation Parameters - Part 2

  • Eran Chinthaka
  • Software Engineer - WSO2

Axis2 release comes with the wsdl2java tool to auto-generate programming language code from a given WSDL file; these codes can be used to access or create Web services. This tool has numerous options that can be used to customize the outcome and the functionality. Also, these options can help define the behavior of the generated code. In this three part tutorial series, Eran Chinthaka look at the capabilities of each of these options in detail, so that one can maximize the usefulness of this valuable tool.

Introduction

This reference tutorial consists of three parts. In the first part we introduced the basic concepts of code generation, including how code generation acts as the index for the rest of the parameters. In this tutorial we will continue to discuss the available options.

Other Articles in the Series

Applies To

Project Axis2
Tool WSDL2Java

All the parameters discussed in this tutorial are available in Axis2 1.4 or later releases.

Table of Contents

  1. Introduction
  2. Parameter Reference

Parameter Reference

Now let's continue to look at each parameter in detail.

Don't Copy the Source WSDL

Short Option : <No Short Option>

Long Option : -noWSDL

Description : It is recommended that you keep a copy of the source WSDL file after the code generation process is complete. The code generator will put a copy of the source WSDL inside the resources folder with most of the options; if you don't need the source WSDL file, use this option to force the code generator not to leave it after the code generation is complete.

Default Value : Will create a copy of the source WSDL with most of the options.

Don't Generate Message Receiver

Short Option : <No Short Option>

Long Option : --noMessageReceiver

Description : When you generate server side code, such as the service implementation class, the code generator will also generate the message receiver related to the methods found in the WSDL file. This message receiver is also responsible for marshalling and unmarshalling (converting from SOAP message to Java or programming language specific code) parameters. But if you don't want to have the auto-generated message receiver, use this option to force it.

Default Value : Will generate the message receiver.

Don't Generate Ant Build Script

Short Option : <No Short Option>

Long Option : --noBuildXML

Description: Axis2 code generator is capable of generating an Apache Ant build script for you to use once you are done with the code generation. This script will set the class path properly and also provides the targets to jar the clients, server side code, etc. This could be helpful since Axis2 has few jars for use in the classpath. But if you do not need the build script file, use this option to force the code generator not to create one for you.

Default Value :A build script will be generated.

Generate Asynchronous Client Invocation Code

Short Option : -a

Long Option : --async

Description: Axis2 has the ability to invoke a Web service in two different ways. It can either block during the invocation or it can use callbacks to perform a non-blocking asynchronous invocation. With the latter option, you are forcing the code generator to generate all the method invocations as asynchronous invocations. Once you generate code, you will see a start<MethodName> for each method. This method will have a Callback parameter, in addition to the parameters defined in the WSDL file. You can use this callback method to receive notification once the client gets a reply or completes the invocation (depending on the message exchange pattern).

If you are trying to generate code for GUIs or user interaction code, asynchronous methods are ideal.

Default Value :No asynchronous client code.

Generate Synchronous Client Invocation Code

Short Option : -s

Long Option : --sync

Description:Axis2 has the ability to invoke a Web service in two different ways. It can be either blocked during the invocation or can use callbacks to do a non-blocking asynchronous invocation. With this option, you are forcing the code generator to generate all the method invocations as synchronous invocations. When you invoke a method in the generated code, the control will not be returned back to you until the method invocation is complete.

If you are trying to generate code for GUIs or user interaction code, asynchronous methods will be ideal.

Default Value :No synchronous client code.

Configure the Package Name

Short Option : -p [Package Name]

Long Option : --package [Package Name]

Description: If you are generating Java code using this tool, then you can provide a package name so that the tool will put all the generated code inside this package. This is helpful if you already have your project structure defined and you want to integrate the generated code with that.

Default Value:If you don't provide a package name, the tool will use the target namespace of the source WSDL file to come up with a package name. For example, if the target namespace is https://www.myproject.org/myservice, then the package name will be org.myproject.www.myservice.

Configure the Stub Language

Short Option : -l [Programming Language]

Long Option : --language [Programming Language]

Description: Axis2 code generation framework is designed so that you can easily extend it to generate client code for many different languages. Once the tool reads a given WSDL file, it will create a language-agnostic XML representation which will be used together with set of XSL translations to generate the client code for the target language.

Every Axis2 release comes with built-in capability to generate code for both C and Java programming languages. If you need to extend it to generate for other languages, please refer to the article "Inside the Axis2 Code Generator".

Default Value: Generate client code in Java.

Configure the Data Binding Framework

Short Option : -d [Data binding Framework]

Long Option : --databinding-method [Data Binding Framework]

Description: Data binding refers to the generation of programming language code that maps the parameters embedded inside SOAP messages to programming language code. Data binding code generation is an important part of the code generation as the data-bound objects are used as parameters inside the method invocations. Axis2 code generation framework can generate code for different data binding frameworks, as it also comes with a simple yet powerful data binding framework, ADB (Axis2 Data Binding). In addition, the code generation tool can generate code using XmlBeans, JAXB and JiBX. Again, Axis2 is flexible enough to support other data binding frameworks too, but all the releases have built-in support for the above frameworks. You can choose the framework that best fits your requirements.

You can use "adb", "xmlbeans", "jaxb" and "jibx" as the inputs to the code generation tool. If you use XmlBeans, the tool will also generate a set of descriptor files during the code generation. These are marked as xsb files. Make sure you put them in to the classpath before running your generated code.

Default Value :adb

Unpack Generated Classes

Short Option : -u

Long Option : --unpack-classes

Description: As we mentioned in "Configure the Data Binding Framework" section, the code generator will also generate the data bound objects. There are two places to keep these classes: you can "pack" them inside a one single file, or you can generate one file for each class to be generated and "unpack". This is simply a convenience option. When you generate client-side code, the code generator will generate in the packed mode and all your bean classes will be packed inside the stub class that is generated. If you want to unpack them, use this option. This option will have no effect when you generate server side code.

Default Value : Packed.

Configure Source Folder Name

Short Option : -S [Folder Location]

Long Option : --source-folder [Folder Location]

Description: Once you generate code, the tool will put all the generated source code into "src" folder within $OUTPUT_LOCATION. If you want to change the source folder name, use this option. If this location does not exist, the tool will create one for you provided the tool has sufficient permissions.

Default Value : $OUTPUT_LOCATION/src

Configure Resource Folder Name

Short Option : -R [Folder Location]

Long Option : --resource-folder [Folder Location]

Description: The resource folder is where the tool will put the auto-generated files such as the source WSDL, services.xml, etc. This typically defaults to $OUTPUT_LOCATION/resources. This option will allow you to configure the location of your resource folder. If this location does not exist, the tool will create one for you provided the tool has sufficient permissions.

Default Value: $OUTPUT_LOCATION/resources

Select the Port Name

Short Option : -pn [Port Name]

Long Option : --port-name [Port Name]

Description:A given WSDL file might have multiple ports defined. If you do not provide your preference, Axis2 will generate code for all the ports. If you want to generate code for a selected port name, use this option to express your preference.

Default Value: Generate code for all ports

Select the Service Name

Short Option : -sn [Service Name]

Long Option : --service-name [Service Name]

Description: A given WSDL file also might have multiple services defined. If you don't provide your preference, Axis2 will generate code for all the services. If you want to generate code for a selected service name, use this option to express your preference. It is important to note that if you select JiBX as your data binding framework, and if you have multiple services in your WSDL, you must select a service name using this option. JiBX does not provide support for multiple services.

Default Value: Generate code for all services

Summary

In this tutorial we reviewed some of the important parameters that can be used with wsdl2java tool. In the third and last part of this tutorial series we will continue to discuss the parameters available in the tool.

 

Resources

 

Other Articles in the Series

About the Author

Eran Chinthaka is a pioneering contributor to Apache Axis2, Apache Axiom, and Apache Synapse projects as well as WSO2 WSAS. He is a member of ASF and a PMC Member of the Apache WS project. He also serves on the WS-Addressing and WSDL 2.0 working groups of W3C. Eran is currently at Indiana University reading for his PhD.

 

About Author

  • Eran Chinthaka
  • Software Engineer
  • WSO2 Inc.