login button

Using Apache JMeter to Test Apache Axis2/Java Web Services

Story :

Level : Project :

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

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:

  • Thread group - These elements are used to specify the number of running threads and the ramp-up period. Each thread simulates a user, and the ramp-up period specifies the time to create all the threads.
  • Samplers - These elements are configurable requests to the server HTTP, SOAP/XML-RPC, or LDAP requests. This tutorial focuses on the SOAP/XML-RPC requests only.
  • Listeners - These elements are used to post the process request data. For example, you can save the data to a file or illustrate the results using a chart.

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 simple Web service implementation class
  • Generating a service archive and deploying it on Apache Tomcat 6
  • Creating a JMeter test plan
  • Sending a SOAP request using JMeter SOAP/XML-RPC Sampler
  • Checking the response SOAP message

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.


Sending a SOAP Request Using JMeter SOAP/XML-RPC Sampler

In this tutorial, we use JMeter version 2.2. Download a binary executable from the Web site, unzip it, and the application is ready for use on Windows or Unix platforms.

Go to the bin folder and start the application by runningjmeter.bat or jmeterw.bat if you are on MS Windows operating system, jmeter.sh if you are on a Linux operating system.

The initial user interface you will get is shown in Figure 1.

Figure-1

Creating and Running a SOAP-XML Test Plan

Each JMeter test is associated with a test plan. A complete test plan will consist of one or more thread groups, logic controllers, sample generating controllers, listeners, timers, assertions, and configuration elements. Lets create a test plan and add a thread group to it. Right-click on the test plan element and add a thread group. Leave the default settings of the thread group.

Figure-2

Next, right-click on Thread Group, point to Add, then Sampler, and then click SOAP/XML-RPC

Figure-3

In order to visualize the SOAP-XML test result, a listener should be added to the thread group. Right-click on SOAP/XML-RPC, point to Add, then Listener, and then click View Results Tree.

 

Figure-4

Now your JMeter environment is ready for use, and the SOAP request can be sent to our sample service. We need to have a valid SOAP envelope which can be used to invoke our service. We will use the following SOAP envelope, which was captured using Apache tcpmon (For more information about tcpmon visit Apache tcpmon Web page)

<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body><ns0:addition xmlns:ns0="http://ws.apache.org/axis2/xsd">
<ns0:x>20</ns0:x><ns0:y>10</ns0:y></ns0:addition>
</soapenv:Body>
</soapenv:Envelope>

Copy the above code and paste it on the Soap/XML-RPC datasection of the JMeter SOAP/XML-RPC sampler.

Figure-5

Select the Send SOAPAction check box and enter'urn:addition' as the soapAction. (This can be obtained from theWSDL of our service)

Enter 'http://localhost:8080/axis2/services/Jmeterservice 'as the URL. This is the EPR (end-point reference) of our service.

Now everything is ready to test our Web service using the JMeterSOAP/XML-RPC sampler. Save your JMeter test plan.

Right-click on Thread Group and select Run from the main menu. Click Start to run the thread group.

Next select View Results Tree and SOAP/XML-RPC Request. You can see the result on the Response Data tab as follows.

Figure-6

The response value will be shown in <ns:return> element. Check the response with what we have passed to the service.

You can extend this simple test and create a load test in JMeter very easily. Just increase the thread count and add a graphical result viewer.

Summary

We discussed how easily we can verify the functional correctness of a Web service using Apache JMeter soap/xml-rpc sampler. You just need to have a SOAP request (SOAP envelope) and JMeter will look after the rest. The same soap/xml-rpc test can be extended to generate a comprehensive load test by increasing the thread count. Also, this can be used as a starting point to learn Apache Axis2/Java Web services without writing client applications.

References

[1] Apache Axis2/Java

[2] Apache JMeter

Author

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

2
Average: 2 (1 vote)