How to develop a BioMoby service

This document summarises steps in order to develop (to implement) a BioMoby service based on generated code. The full description what kind of code can be generated and how to use it is in a separate document about MoSeS (Moby Services Support). This is, however, a good starting point.

The main thing to understand is that MoSeS does not give you a full implementation of your service. You still need to program the business logic (e.g. to extract data from your database) - but you do not need to worry about the BioMoby and SOAP protocol details.

A typical situation is to develop (to implement) your service in a separate directory, not within your local copy of jMoby. This document describes exactly that.

The major jMoby components used for a new service development are:

Table of Contents

Step 1: What is needed
Step 2: Service registration
Step 3: Service generation
Step 4: Service implementation
Step 5: Service testing
Step 6: Service deployment

Step 1: What is needed

First of all, you need a Java installed on your machine.

Second, you will need jMoby itself. Take it using a CVS checkout. Details are in a separate document, here only a quick guide:

Then, you need a space (a directory) where you are going to develop your service. One possible way is to use an empty project in empty_project.tar.gz. You can develop anywhere, and you can use any tools, of course. This document just needs to explain connections between the jMoby (now checked-out in moby-live/Java directory) and your project. It will be, therefore, using the suggested empty project as an example. Note, that especially you can develop using Eclipse - and still using the suggested empty project.

I will be using a name MyPoject for the new project directory. Go where you wish to have your new project and:

cp ....moby-live/Java/docs/empty_project.tar.gz .
tar xzf empty_project.tar.gz
mv EmptyProject-RENAME-ME MyProject
cd MyProject
cp ....moby-live/Java/build/lib/jmoby.jar lib/
Note that the last line filled the new project with the jMoby libraries. But you need more libraries. There are third-party libraries that are used by jMoby so you can take them from your jMoby copy:
cp ....moby-live/Java/lib/alltools.jar lib/
cp ....moby-live/Java/lib/jdom.jar lib/
cp ....moby-live/Java/lib/xercesImpl.jar lib/
cp ....moby-live/Java/lib/xml-apis.jar lib/
I am no sure now about the last two jar files. Perhaps you do not need them if you are using Java 1.5.

In order to build everything you need an Apache Ant installed, a Java-based build tool. If you are using Eclipse, it is already part of it.

This is how you will be building everything (now it does little because you do not have any source code there yet):

ant all
For a compilation only, it is enough to day:
ant

Step 2: Service registration

Every BioMoby service must be first registered, together with data types it uses. The best way to do it is to use a Registration Panel in BioMoby Dashboard:

cd moby-live/Java
ant dashboard
Setting -> Panel selection -> Registration -> Service Registration

Step 3: Service generation

A service generation generates source code of a Java class (called a skeleton) that will be a super-class for your own implementation. It also generates Java classes representing all BioMoby data types. All this is part of MoSeS. Again, you are going to use BioMoby Dashboard, this time the MoSeS Generator Panel:

cd moby-live/Java
ant dashboard
Setting -> Panel selection -> MoSeS Generator

Select service...: your-service-name
Button: All-in-One: Do it all

This also packs generated code into two jar files that you need to copy to your project directory:

cd MyProject
cp ...moby-live/Java/build/lib/biomoby-datatypes.jar lib/
cp ...moby-live/Java/build/lib/biomoby-skeletons.jar lib/

Step 4: Service implementation

Now it is your turn to play.

Put your implementation sources into MyProject/src/main - using any package structure as you wish. An example of an implementation is in MoSeS.

The skeleton API documentation (you need to know it in order to find what methods are available in your implementing class) is available in moby-live/Java/docs/APIservice/index.html.

You compile by calling:

ant
In order to learn what Ant's tasks are available in your project, type:
ant -projecthelp

Step 5: Service testing

Surprisingly, the best time for testing a service is before its deployment. It helps to find and fix problems without hassle with Tomcat and Axis. (But come back to test again after deployment.)

There are many BioMoby clients that can be used to call our services. Let's show two of them. One is a command-line program that is the best for fast debugging, the other one is again the BioMoby Dashboard.

Command-line testing

The command-line program has its own help:
build/run/run-service -help
and its details are described in the Moses documentation. Start testing with parameter -class - it calls your local implementation directly. This is good for debugging. You may use the same program to call a real service later, just use instead a parameter -e with a service endpoint.

Check also the log file project.log.

Testing with Dashboard

The testing is perhaps more comfortable with the Dashboard. Details are in the documentation of the Simple Client Panel.
cd moby-live/Java
ant dashboard
Setting -> Panel selection -> Simple Client
Select service...: your-service-name
add your input data on the right
Button: Call service

Here also, you can test your service before it is deployed. Check the box Use this local class and enter a full name of your service implementation class. This, however, will not work - because Dashboard is started from the jMoby directory and it does not know anything about your implementation classes. Your classes are not on the Dashboard's CLASSPATH. The best way to rectify this is to copy script moby-live/Java/build/run/run-service to your project directory, edit it (see what build/run/run-* scripts how to set your CLASSPATH), and start Dashboard by calling the new script.

Step 6: Service deployment

Deployment of a Web service means to move all necessary files to a Tomcat, and to tell Apache Axis what service is being deployed and what implementation class represents it. It seems easy but often some files are forgotten and the service suddenly does not start when it is called as a real Web service. Fortunately, most of the job can be done by the BioMoby Dashboard.

Before any deployment, make sure that:

The Dashboard knows what jMoby files are needed and what are the service and implementation class names. But Dashboard does not know anything about files coming from your project. For that, there is an Ant task that collects all needed files and put them in MyProject/build/lib:

cd MyProject
ant pre-deploy
Remember this directory - you will need it in a minute in Dashboard.

The core of deployment is done by the BioMoby Dashboard in the MoSeS Generator Panel:

cd moby-live/Java
ant dashboard
Setting -> Panel selection -> MoSeS Generator

Pattern for implementation class names: your-package-name.{SERVICE}Impl
Select service...: your-service-name
Button: Deploy

Before you press the Deploy button check at least these three things:

After deployment, restart your Tomcat (I recommend to use Tomcat Manager and to reload only Axis), and try the service, now using its real endpoint.


Martin Senger
Last modified: Thu Feb 14 14:58:25 2008