Published on WSO2 Oxygen Tank (http://wso2.org)

Using Apache JMeter to Test Apache Axis2/Java Web Services

By
Created 2007-04-18 01:46

This tutorial by Charitha Kankanamge explains how Apache JMeter can be used to test Apache Axis2/Java Web services. A novice user will be able to get a good understanding on testing an end-to-end scenario, which involves an Apache Axis2/Java service and a client.

Introduction

There are numerous ways to verify the functional correctness of an ApacheAxis2/Java Web service. You can generate the stubs and invoke the service using client code. Then you can check whether the actual response of the Web service is similar to the expected output. However, generating stubs and writing client code require some effort. The QA team has to re-generate stubs and client code when performing regression tests. The use of a commercial or open source testing tool will reduce the QA effort and make it efficient. Apache JMeter is a simple and easy-to-use open source testing tool which can be used to test the functionality or performance of a Web application.

This tutorial will take you through the steps of how to create a simple Web service using Apache Axis2/Java, deploy it in a servlet container, and test the service invocation by sending SOAP requests using JMeter. The same test can be extended to do a load test on the Web service by using JMeter.

Background

Apache Axis2/Java

The Apache Axis2/Java project is a Java-based implementation of both the client and server sides of the Web services equation. Apache Axis2 provides a complete object model and a modular architecture, which makes it easy to add functionality and support for new Web services-related specifications and recommendations.

A more detailed description on Apache Axis2/Java engine check Apache Axis2/Java Web site [1]

Apache JMeter

JMeter is a powerful test tool from the Apache Jakarta project, which can be used to load test Web pages, Web applications, databases, and several other static and dynamic resources. It is highly extensible and can be utilized effectively to verify and analyze the functionality of Web services. In this tutorial, we will see how we can verify the functional correctness of an Apache Axis2/Java Web service using JMeter.

In order to create a test in JMeter, you should build a test plan, which is essentially a sequence of operations JMeter will execute. The simplest test plan normally includes the following elements:

A detailed description about JMeter and its elements can be found at Apache JMeter Web site

Getting Started

Your system should have the following softwares installed and configured.

In this tutorial, we will discuss the following topics in detail.

Creating a Web service and Deploying it on Apache Tomcat6

The following steps are based on Apache Tomcat 6.0. However, you can choose any servlet container and try out the same.

  1. Create the service implementation class.
  2. Here we will create a simple service implementation class which adds two integers and returns its sum.

    public class Jmeterservice {
    public int addition(int x, int y){
    return x+y;
    }
    }

    Compile and save the above Java class.

  3. Now you need to create the service description file (services.xml) as follows. Add the contents given below to a text document and save it as 'services.xml'
  4. <service name="Jmeterservice">
    <description> My first web Service </description>
    <parameter name="ServiceClass" locked="false">Jmeterservice</parameter>
    <operation name="addition">
    <messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
    </operation>
    </service>
  5. Apache Axis2/Java deploys your service as an archive file (*.aar). An archive with the above service class and description file need to be created with the proper structure as follows:
    1. Create a directory (eg_- temp)
    2. Copy the above Java class file (Jmeterservice.class) in to the temp directory (Make sure to copy the compiled Java class file into the service archive directory, not the Java source file)
    3. Create a directory called META-INF under the temp directory
    4. Copy the above services.xml file to the /temp/META-INF directory
    5. Now your archive structure should be like this.

      temp ---> 
      Jmeterservice.class
      META-INF
      ---->services.xml
    1. Make the above directory a service archive file (.aar file). Go to the temp directory and execute the following command

      temp>jar -cvf Jmeterservice.aar *

       

  6. Now you have everything required to deploy an Apache Axis2/Java service. Copy the Jmeterservice.aar into Tomcat_home/webapps/axis2/WEB-INF/services directory.
  7. Refresh the services list in the Apache Axis2 admin console (Navigate to http://localhost:8080/axis2/services/listServices and Jmeterservice should be displayed under the available services list.)

    We created a simple Web service using Apache Axis2/Java and deployed it on Apache Tomcat 6. We will see how Jmeter can be used to test the Web service response in the next section.

Please visit ApacheAxis2 User's Guide -Building Services for more information on creating and deploying Apache Axis2/Java services.

Apache Axis2/Java [3]

[2] Apache JMeter [4]

Author

Charitha Kankanamge, Senior Software Engineer - Quality Assurance, WSO2. charitha at wso2 dot com


Source URL:
http://wso2.org/library/1085