How to invoke a simple web service using Apache JMeter

Let’s see how to invoke a simple SOAP/REST service using WSO2 products.

First, start WSO2 Application Server and deploy the SOAP web service.

Here we have used web service as OrderPWebservice

as-web-service

Now you can see that your SOAP web service is up and running at WSO2 AS.

Let’s create a Test plan in JMeter.

Right click on Test Plan and go Add -> Threads(Users) -> Thread Group

jmeteronw

In the Thread Group element, set the thread properties,
    • Number of threads(users) : No. of concurrent users to be simulated.
    • Ramp – up period(in seconds) :Time taken by the JMeter to invoke the threads
    • Lop count : No of times the test plan should be repeated.

Then right click on Thread Group and add a SOAP/XML-RPC Request as below.

abc

Then right click on Thread Group and add -> Listener -> View Results Tree. This is to view the requests and responses to check whether they executed successfully.

In SOAP/XML-RPC Request window, add the url of the web service and the SOAP request to the web service as below.

url : http://${host}:${port}/services/OrderPWebService/

SOAP?XML-RPC Data :

<soapenv:Envelope xmlns:soapenv=”http://schemas.xmlsoap.org/soap/envelope/&#8221; xmlns:ord=”http://order.com”&gt;
<soapenv:Header/>
<soapenv:Body>
<ord:displayOrder>
<ord:name>IBM</ord:name>
</ord:displayOrder>
</soapenv:Body>
</soapenv:Envelope>

Here, in the url, i have parameterized the url and port of the service(${host}:${port}).

In order to parameterized values in you request, you can add the parameters to the script as below.

Go to Test Plan–>Pre processors–> User Parameters and add parameters for the host and port as below.

URL_PORT_Par1

jmeter

Now, adding url and port for the script as shown below.

jmeter222222

Also you can add an assertion to the script too.I am going to use a response assertion  to verify whether the response contain pattern 200.

Add a response assertion as below.

jmeter3333

Also you can add an assertion results to see the success and the failure of the tests based on assertions.

Now, save the Test Plan and click on the green arrow button to start sending requests to the web service.

Since we have specified “one” as number of threads in Thread Group, it will send only one message at one start.

Click on View results tree.Click on SOAP/XML-RPC Request and you will see the request, response and sampler result on the right side as below.

gfd

And if you look at the assertion results, it will be shown the test success  as below.

jmeeee

and if the responses do not contain the stated response code, the assertion results window will show it as below.

abc



Now let’s see how to invoke a REST web service.

Deploy a REST web service in WSO2 Application Server.

For the same Thread Group you can add a HTTP Request Sampler.

Right click on Thread Group -> add -> sampler -> HTTP request

123

Next we need to add a HTTP Header Manager to send parameters in the header of the request. We need to send “Content-Type” and “Access” variables as request headers.

345

This is because the REST service might expects “Content-Type” and “Access” parameters in the header request.

Fill in the HTTP request window using the IP, port, path, HTTP request details and request Body data.

real

If you click on the View Result tree you can see the request and response and the response in Json format as well.

ttt

Also, you can use the same steps to invoke SOAP web service as well.

Leave a comment