apache > ws.apache
WSRF
 

Using Wsdl2Java

Introduction

The Wsdl2Java tool is used to generate a set of artificats for a WS-Resource. The artifacts include:

  • A set of Java classes based on the WSDL definition. This includes a service, resource, and home class. Some of the Java code will need to be manually edited after the files are generated.
  • Interfaces for custom operations.
  • Java bindings for all XML schema types that are defined in the WSDL. The interfaces and classes are created using the XMLBeans schema compiler
  • An Axis Web Service Deployment Descriptor (WSDD) for your service (service_deploy.wsdd). This file is used to deploy your service to Axis.
  • A WSRF configuration file for the resource home associated with your service (service_wsrf-config.xml). This file defines the information necessary for Apache WSRF to initialize and dispatch requests to your service.

The tool saves you a great deal of time, since these files do not have to be created from scratch. You simply pass the tool a WSRF WSDL and the files are automatically generated. You can use the tool directly or you can use an Ant task.

Ant Task

The Wsdl2Java tool can be invoked using the wsdl2Java Ant task (org.apache.ws.resource.tool.Wsdl2JavaTask). The INSTALL_DIR/template/build.xml script contains a target that already implements this task.

To use the target:

  1. Copy INSTALL_DIR/template/build.xml and build.properties to any directory. This directory will be referred to as WORK_DIR.
  2. Using a text editor, open WORK_DIR/build.properties.
  3. Uncomment the wsrf.webapp.dir property and set it to the location where the WSRF Web application is installed. If you are using Tomcat and have the CATALINA_HOME environment variable set, you do not need to modify this property.
  4. Uncomment and modify the proxy settings if you require a proxy to connect to external Web sites.
  5. Copy your WSRF WSDL to WORK_DIR. If your WSDL depends on a schema that is not accessible over the network, you must copy the schema to this directory as well.
  6. From a command prompt, change directories to WORK_DIR.
  7. Run the following command.
    ant generate

    Check WORK_DIR/generated to see the generated files.

Task Definition

The task is defined as follows:

<taskdef name="wsdl2Java" 
 	 classname="org.apache.ws.resource.tool.Wsdl2JavaTask" 
 	 classpath="path/to/wsrf.jar" />  

Parameters

The task takes the following parameters:

Attribute Description Required
wsdl Enter the full path to a WSRF WSDL file. Yes, unless a wsdls parameter is used.
wsdls Entered as a nested element following the rules of fileset. This parameter is used instead of the wsdl parameter to indicate multiple WSRF WSDLs to be converted. No
classpath The classpath to be passed to the XMLBeans schema compiler. The classpath should reference all the jars in the INSTALL_DIR/wsrf/webapp/lib, as well as the /classes directory. Yes
classpathref Adds a classpath, given as reference to a path defined elsewhere. No
outputdir Enter a directory where the generated files will be placed. Yes
verbose Enter true to increase build message output. No, default is false
proxyHost Enter the Host IP address of a proxy that is used to connect to the Internet. No
proxyPort Enter the Port number of a proxy that is used to connect to the Internet. No
nonProxyHosts Enter the Host IP address separated by "|" to indicate Hosts that do not require a proxy. No

Example

The following example generates files for a single WSDL and places the generated files in a subdirectory of the current directory named generated. To simplify the example, the classpath is referenced. You must set the ${wsrf.home} Ant property to INSTALL_DIR (e.g. /opt/wsrf-1.1).

			 
	<property name="wsrf.webapp.dir" location="${wsrf.home}/webapps/wsrf" />
	<path id="wsrf.classpath.id">
          <pathelement location="${wsrf.webapp.dir}/WEB-INF/classes" />
          <fileset dir="${wsrf.webapp.dir}/WEB-INF/lib" includes="*.jar" />
        </path>

        <taskdef name="wsdl2Java" classname="org.apache.ws.resource.tool.Wsdl2JavaTask" classpath="wsrf.classpath.id" />

        <wsdl2Java wsdl="path/to/your.wsdl"
                   outputdir="generated"                   
                   classpath="wsrf.classpath.id" />

If you want to generate the files for multiple WSDLs, you can use:


	<wsdl2Java outputdir="generated" classpath="wsrf.classpath.id" />
	   <wsdls dir="path/to/wsdls/">
             <include name="**/*.wsdl" />	  
          </wsdls>
       </wsdl2Java>