In order to create a test plan for webservice, we need to create a webservice project and deploy it locally on the Tomcat server.

Step1: Creating Webservice Project

Using Eclipse IDE, write SEI (Service Endpoint Interface) HiUser under com.jmeterwstestplan.ws which will look like as below

package com.jmeterwstestplan.ws;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;


//Service Endpoint Interface
@WebService
@SOAPBinding(style = Style.RPC)
public interface HiUser{

  @WebMethod String getHiUserMessage(String string);

}

 

The service getHiUserMessage has a string parameter

Next step is to create HiUserImpl.java, the implementation class under the package com.jmeterwstestplan.ws

package com.jmeterwstestplan.ws;

import javax.jws.WebService;

@WebService(endpointInterface="com. jmeterwstestplan.ws.HiUser")
public class HiUserImpl  implements HiUser  {
   @Override
	
   public String getHiUserMessage(String myName){
      return("Hi "+myName+" to JAX WS User");
   }
}

This web service will now need to be published through an Endpoint publisher and place this service on the server.

HiUserPublisher.java will look like

package com.jmeterwstestplan.endpoint;

import javax.xml.ws.Endpoint;

import com.jmeterwstestplan.ws.HiUserImpl;

public class HiUserPublisher {

   public static void main(String[] args){
      Endpoint.publish("http://localhost:9000/ws/hello", new HiUserImpl());
   }
}

In the next step, web.xml file needs to be modified as

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">

<web-app>

   <listener>
      <listener-class>
         com.sun.xml.ws.transport.http.servlet.WSServletContextListener
      </listener-class>
   </listener>
	
   <servlet>
      <servlet-name>hello</servlet-name>
      <servlet-class>
         com.sun.xml.ws.transport.http.servlet.WSServlet
      </servlet-class>
      <load-on-startup>1</load-on-startup>
   </servlet>
	
   <servlet-mapping>
      <servlet-name>hello</servlet-name>
      <url-pattern>/hello</url-pattern>
   </servlet-mapping>
	
   <session-config>
      <session-timeout>120</session-timeout>
   </session-config>
	
</web-app>

The configuration file sun-jaxws.xml is also needed to deploy this application as web service which will look like

<?xml version="1.0" encoding="UTF-8"?>
<endpoints xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime" version="2.0">

   <endpoint name="HelloWorld" implementation="com.jmeterwstestplan.ws.HelloWorldImpl" url-pattern="/hello"/>
	
</endpoints>

 

Next step is to create and export the WAR file. Save it as hi.war under webapps directory and start the Tomcat server which will give you access to URL http://localhost:8080/hi/hi

Step 2: Creating Jmeter Test Plan

Step 3:Rename Test Plan node

Open the Jmeter window and you will need to rename the Test Plan node as WebserviceTest.

Adding Thread Group

Add one thread group by right clicking on WebserviceTest (The renamed one) and then click on Add then Threads and Thread Groups. You can change the default parameters such as Name, Number of threads, Ramp up Period and Loop count as shown below.

Step 4: Adding Sampler

After adding the users, it is now time to add the tasks these users will be performing which can be done by adding a SOAP/XML-RPC request element.

This can be done by selecting Add menu by right clicking the mouse, then select sampler and then SOAP/XML-RPC request.  Edit the Name as SOAP/XML-RPC Request, URL as http://localhost:8080/Hi/Hi?wsdl and SOAP/XML-RPC data as follows

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://ws.jmeterwstestplan.com/">

   <soapenv:Header/>
	
   <soapenv:Body>
	
      <web:getHelloWorldMessage>
         <arg0>Manisha</arg0>
      </web:getHelloWorldMessage>
		
   </soapenv:Body>

Step 5: Adding Listener

Listener is responsible for storing the results of the test plan and you can add a listener by selecting Listener in the Add menu and choose Listener and then View results Tree

Step 6: Run and View the Results

Save the test plan as test_webservice.jmx and run the test plan from the Run menu and choosing the option Start.

The listener will show the following output after the execution