apache > ws.apache
Pubscribe
 

Using WsnWsdl2Java

Introduction

The WsnWsdl2Java tool is used to generate a set of artifacts from a WSRF/WSN WSDL. The artifiacts 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 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/WSN WSDL and the files are automatically generated. You can use the tool directly or you can use an Ant task.

Ant Task

The WsnWsdl2Java tool can be invoked using the WsnWsdl2Java Ant task (org.apache.ws.notification.tool.WsnWsdl2JavaTask) which extends the Apache WSRF 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 pubscribe.webapp.dir property and set it to the location where the Pubscribe 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/WSN 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.notification.tool.WsnWsdl2JavaTask" 
 	 classpath="path/to/pubscribe.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 and /classes directories. 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 directory named /generated. To simplify the example, the classpath is referenced. You must set the ${pubscribe.home} Ant property to INSTALL_DIR (e.g. /opt/pubscribe-1.0beta).

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

        <taskdef name="wsdl2Java" classname="org.apache.ws.notification.tool.WsnWsdl2JavaTask" classpath="pubscribe.classpath.id" />

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

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


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