Tutorials : Using Apache Axis version 1 to build Web Services :

The DVDService class

The analysis above shows that we now need to implement a Java class that exposes these services: return DVD titles, return DVD details, update, create, delete DVD, and save DVDs. Several of these services transmits the properties of a DVD, so it would be nice to implement a DVD JavaBean, which could be transmitted over the wire. If the client is also a Java program then there’s nothing wrong with this approach. If we want to talk to .NET clients for example, we’ll have to find a solution that is not specific for Java, but this will be a topic for another article.

This leads to this service description:

service

method signature

return DVD titles

Vector getTitles()

return DVD details

DVD getDetails(int i)

update DVD

void update(DVD dvd)

create DVD

void create(DVD dvd)

delete DVD

void delete()

save DVDs

void save()

Utilizing the DVDManager class, it’s straightforward to code a class--DVDService--which implements these methods. Click to see complete code for the DVDService class There’s nothing in this class that shows it’ll end up becoming a web service. I’ve enclosed a small main method that tests a couple of the methods.

The next step is to deploy the DVDService to Axis. In order to do that we must first create a Web Service Deployment Descriptor (WSDD) file. The basic format of this is simply to name the service and to specify the name of the class file:

<deployment xmlns="http://xml.apache.org/axis/wsdd/"
            xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
  <service name="DVDService" provider="java:RPC">
    <parameter name="className" value="hansen.playground.DVDService"/>
    <parameter name="allowedMethods" value="*"/>
  </service>
</deployment> 

I’ve set in bold the name of the service--which we’ll use in the client request to the Axis server--and the name of the Java class. We have allowed all methods in the class to be called by specifying "*" to allowedMethods. This means that main also may be called as a web service(!), and if you don’t like that you may specify all allowed methods separated by a space instead of the "*".

We also have to map the DVD JavaBean to an "XML QName" (Qualified Name), so we add this XML element to the wsdd file:

<beanMapping qname="myNS:DVD" xmlns:myNS="urn:BeanService"
       languageSpecificType="java:hansen.playground.DVD"/>

It’s normal practice to name this file deploy.wsdd. Click to see the complete deployment file.

Deployment of the DVDService

It’s now time to deploy our service class. First we must place the class file in the project directory. On Tomcat this is webapps/axis/web-inf/classes, and since the package name of the DVDservice is hansen.playground you must place the class file in webapps/axis/web-inf/classes/hansen/playground.

As shown in the Axis User’s Guide, deployment is done with the AdminClient. So, now’s the time to use the adminclient bat-file we created previously (see figure 2). Having placed the deploy.wsdd file in the WEB-INF directory together with the utility bat-files we issue the commands:

  setcp
  adminclient deploy.wsdd

If adminclient works correctly you’ll receive this XML-answer: <Admin>Done processing</Admin>. You cannot, however, be sure that deployment was a success. It seems that the adminclient merely checks if the deployment file contains valid XML, and then updates the server-config.wsdd (located in the WEB-INF directory) with the information from the deploy.wsdd file.

To see if the DVDService has been deployed correctly, go to the Axis home page--http://localhost:8080/axis--and click on "View the list of deployed Web services". If deployment has completed successfully you’ll see a page like this:

 

Listed on the page are all the methods in DVDService--including the main method! If you can only see the headline, "And now. . . Some Services", then there’s most likely an error in the deploy.wsdd file. It can be anything from spelling errors to missing Java classes. The cause of the error can almost always be found by looking in one of the server log-files. On my Tomcat installation the log file to look in is called localhost_log.<date>.txt.

If you want to undeploy a service then create an undeploy.wsdd file with these contents:

<undeployment xmlns="http://xml.apache.org/axis/wsdd/">
  <service name="DVDService"/>
</undeployment>

Use the adminclient to undeploy the service:

  adminclient undeploy.wsdd

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.