COMP534B Axis Tutorial
Getting Started with Axis and SOAP
The purpose of this tutorial is to allow you to become familiar with installing the Axis SOAP engine and writing, deploying and testing simple web services.
Part Two: Writing and testing a web services version of the CurrencyExchange Bean
Making the CurrencyExchange bean into a web service will make its operation slightly different from that of the assignment. In the assignment the CurrencyExchange bean broadcasts currency values to listeners at regular intervals. In the web service scenario, the bean waits for clients to connect and request a currency value. To simplify things for this exercise the CurrencyExchange web service could load the currency data at startup and then serve values from the current row of the data when a client makes a request. The CurrencyExchange could either advance the current row every x number of seconds or (even simpler) after each request.
You will use the Java2WSDL and WSDL2Java tools to create the necessary files for the web service.
1) Create a directory to hold the files necessary for this exercise.
2) Inside this directory create:
Š A directory called currencyex (for holding your interface to the currency exchange service)
Š A directory called axisAutoSource (for holding automatically created bindings)
3) Write a java interface called CurrencyQuote.java for the currency exchange web service and package it in the currencyex directory (i.e. include the package statement package currencyex; in the source code). Your interface should contain at least two methods: one for obtaining a quote (a floating point return value) given a string argument which is the name of the currency in question; and a second one for “resetting” the service (i.e. setting the current row back to zero).
4) Compile the interface.
5) Generate the WSDL file by using the Java2WSDL tool. Type
java org.apache.axis.wsdl.Java2WSDL \
-o axisAutoSource/currencyex.wsdl \
-l http://localhost:8080/axis/services/currencyService \
-n urn:currencyex currencyex.CurrencyQuote
6) Generate the client-side and server-side bindings using WSDL2Java. Type
java org.apache.axis.wsdl.WSDL2Java –o axisAutoSource –d Application \
If you look in the axisAutoSource directory you will see that a currencyex package has been created that contains the client-side bindings and an additional server-side implementation called CurrencyServiceSoapBindingImpl.java. This file contains trivial implementations of the methods declared in your CurrencyQuote interface (eg. the method for obtaining a quote just returns –3). Whilst you can test deploying the service as it is, you will need to code sensible implementations of the service methods. Note that we have specified Application scope for our web service. This means there will only ever be one object of the web service running on the server.
7) Write code for the currency exchange service by filling in implementations of the methods in CurrencyServiceSoapBindingImpl.java. You may use java.io classes to read in the currencyData.txt (from assignment 1) from the current ($AXIS_HOME) directory.
8) Write code for a test client that allows the user to obtain a quote from the service by specifying a currency string on the command line (eg. java currencyex.MyFunkyClient USD/CAD).
9) Compile all code in the currencyex directory.
10) Create a jar file currencyService.jar that contains the server side component (i.e. should contain the generated CurrencyQuote interface and the CurrencyServiceSoapBindingImpl). Move this file to $AXIS_HOME/lib.
11) Deploy the service using the AdminClient and the generated deploy.wsdd
12) Copy the currencyData.txt file from assignement 1 to $AXIS_HOME.
13) Test the service using the test client that you wrote in step 8.