Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

Axis: The next generation of Apache SOAP

Apache takes its SOAP implementation to new heights

  • Print
  • Feedback

Page 2 of 5

Now, let's install Axis and create a simple service with it.

Install Axis

Although the Axis installation guide is fairly straightforward, these instructions will further ease the process:

First, ensure you have a Web server installed. I use Tomcat. If you have another Web server, you can still download Tomcat's latest version (version 4.0.1, at the time of this publication) from http://jakarta.apache.org/tomcat/index.html. Unzip the downloaded zip file into your C drive, or your preferred drive. (Note that I refer to the C drive in all my instructions.) You should see Tomcat installed in the directory C:\jakarta-tomcat-4.0.1 (if you have a different version, substitute your version number in place of 4.0.1). I will refer to this directory as TOMCAT_HOME.

Second, download Axis's latest release from http://xml.apache.org/axis/index.html. Unzip this zip file into your C drive as well. Axis should now be installed in the directory C:\axis-1_0 (for version 1.0, alpha 2). I will refer to this directory as AXIS_HOME.

Third, copy the Axis folder from AXIS_HOME\webapps into TOMCAT_HOME\webapps.

Now copy xerces.jar from your Xerces installation into the TOMCAT_HOME\webapps\axis\WEB-INF\lib directory. If you don't have Xerces, you can download it for free from http://xml.apache.org/xerces2-j/index.html. All you have to do is download the zip file and unzip it into your C drive. xerces.jar will be in the root of your Xerces installation -- for example, C:\xerces-1_4_4.

Finally, set up a context in the server.xml file in the directory TOMCAT_HOME\conf by adding this line:

<Context path="/axis" docBase="axis" debug="0" reloadable="true"/>


That's it. Axis is now installed and ready to use.

Create the Web service

Like the service in "Clean Up Your Wire Protocol with SOAP, Part 2," the Web service that we will create here is the "Hello World" of Web services. As you can see below, it is a class that has one method, sayHelloTo(), which takes a name as its only parameter and returns a customized hello message. Note that the class is not littered with any Axis-specific code:

public class HelloServer 
{
    public String sayHelloTo(String name)
    {
      System.out.println("sayHelloTo(String name)");
      return "Hello " + name + ", How are you doing?";       
    }
}


Deploy the Web service the easy way

To deploy this Hello World Web service, just copy and paste the HelloServer.java file into the TOMCAT_HOME\webapps\ directory and change its extension from .java to .jws. That's all there is to it; the Web service is deployed and ready for use. And you didn't even have to compile the Java file! This is Axis feature number 6 (described above) in action.

When a client invokes a service deployed in this manner, Axis will automatically locate the file, compile the class, and convert SOAP calls correctly into your service class's Java invocations. As you will see in the next section, the service name corresponds to the name of the .jws file. The magic that allows the Web server to invoke the Axis engine (i.e., servlet) when a .jws file is requested is located in the TOMCAT_HOME\webapps\axis\WEB-INF directory. This file's appropriate section is shown below:

  • Print
  • Feedback

Resources