Incubator > Beehive
 

Web Service Sample: AddressBook from WSDL

Introduction

This sample shows how to generate a web service from a WSDL file.

Running the Sample

Requirements for Running the Sample

To run the Samples, you need:

  • Beehive
  • Tomcat 5
  • J2SE 5
  • Ant 1.6.2

To Set up the Environment

Before proceeding, complete all of the necessary and optional steps in the following topic: Beehive Installation and Setup

Open a command shell and confirm that the following variables have been set:

  • ANT_HOME
  • CATALINA_HOME
  • JAVA_HOME

Also ensure that the following elements are on your PATH:

  • ANT_HOME/bin
  • JAVA_HOME/bin

To Set up the Server

To Copy the Application to a Project Folder (Optional Step)

To keep your Beehive distribution directory pristine, you should copy the application folder to another location before proceeding. The following instructions assume that you have copied the folder

<BeehiveRoot>/samples/wsm-addressbook-fromWSDL

into the directory C:/beehive_projects, resulting in the following directory structure.

C: 
  beehive_projects 
    wsm-addressbook-fromWSDL
Note
<BeehiveRoot> refers to the top-level directory of your Beehive installation. A typical value for <BeehiveRoot> would be C:/apache/apache-beehive-1.0.
Note
Strictly speaking, you do not need to copy the wsm-addressbook-fromWSDL directory to another location. If you wish to leave the wsm-addressbook-fromWSDL directory in place, in the instructions below you must replace occurrences of the path element C:\beehive_projects with this path element: <BeehiveRoot>\samples.

For example, to build a generated web service file, run the following Ant command:

   ant -f <BeehiveRoot>\samples\wsm-addressbook-fromWSDL\src\WEB-INF\build.xml clean build war

To delete the sample's build directory, run the clean target:

   ant -f <BeehiveRoot>\samples\wsm-addressbook-fromWSDL\src\WEB-INF\build.xml clean

To Start Tomcat

To start Tomcat, run the following command:

%CATALINA_HOME%\bin\startup.bat

Edit the build.properties File

In this section you will edit the build.properties file--the file that sets the build-related properties for the application.

Open the file C:/beehive_projects/wsm-addressbook-fromWSDL/WEB-INF/src/build.properties in a text editor.

Edit the files so that the beehive.home property points to the top-level folder of your beehive installation. For example, if you beehive installation resides at C:/apache/apache-beehive-1.0, then your build.properties files would appear as follows.

beehive.home=C:/apache/apache-beehive-1.0

Select a Source WSDL

Select a source WSDL from which to generate a web service. The generated web service will contain method signatures that correspond to the request/response pattern outlined in the WSDL. For example, if the WSDL contains an operation named "fooOperation" that takes an integer request and responds with a string, then the following method will be generated:

String fooOperation(int n)
{
}

Place the selected WSDL in the following directory.

wsm-addressbook-fromWSDL/WEB-INF/wsdl/

The directory already contains a sample WSDL for the AddressBook web service.

Generating a Web Service

To generate a web service from the WSDL file, run the following Ant target:

ant 
  -f C:\beehive_projects\wsm-addressbook-fromWSDL\WEB-INF\src\build.xml 
  source-gen

Copy and paste version:		
ant -f C:\beehive_projects\wsm-addressbook-fromWSDL\WEB-INF\src\build.xml source-gen

Two artifacts are generated: (1) a web service file is written to WEB-INF/src-ws and (2) the related Java types are written to WEB-INF/gen/types. (Note that the types are also compiled directly into the WEB-INF/classes directory.)

The generated mehthods are all empty, so you must add code to implement the remainder of the web service.

Note
The source-gen target will overwrite previous build artifacts. Beware that you do not lose work by running this target more than once.
Note
This process only works for document-style web services. For RPC-encoded web services, you must use Axis type generation.

Compiling the Generated Web Service

To compile the generated web service, enter the following Ant command.

ant 
  -f C:\beehive_projects\wsm-addressbook-fromWSDL\WEB-INF\src\build.xml 
  clean 
  build 
  war

Copy and paste version:

ant -f C:\beehive_projects\wsm-addressbook-fromWSDL\WEB-INF\src\build.xml clean build war

The command above creates a WAR file named fromWSDLWS.war and saves it at C:\beehive_projects.

To deploy the app to Tomcat, run the following command:

copy C:\beehive_projects\fromWSDLWS.war %CATALINA_HOME%\webapps /Y