How do I use JMeter to call your Restful Web Service? Perform simple stress testing and automated testing

Source: Internet
Author: User

Representational state Transport (REST) is widely accepted in web development as a simple alternative to SOAP-based and Web Service Description Language (WSDL) Web services.
What proves this is the pervasive adoption of REST in the interface design of mainstream WEB 2.0 service providers-including Yahoo, Google, and Facebook-the preference for publishing their services in an easy-to-use, resource-oriented model they have discarded SOAP and WSDL-based interfaces. When you have to test your RESTFul Web service, you may have these two choices:
    • Use URLs to test your WebService with simple access
    • Use JMeter to perform cyclic access testing on the WebService. This kind of test can also play a simple performance test effect.
The example in this article shows how to create a simple Hello world WebService and test the WebService with JMeter access.
If you encounter one of the following problems, then congratulations, you have come to the right place:
    • Functional testing of Soap/rest WebService using JMeter
    • Perform performance tests on a RESTFul API using JMeter
    • Automated testing of Rest APIs using JMeter-that is, performance testing
    • How to test the REST API with JMeter
    • Use JMeter to test a RESTful Web service (Jersey)
Overview of the steps: 1. Prerequisites: A complete implementation of RESTFul Web service.
2. Create a simple Java class: Crunchifyjmetertest.java (we will use the services accessed by JMeter).
3. Redeploy the app on Tomcat.
4. Run JMeter and open the. jmx file provided below.
5. Perform and analyze your test results.
Step 1 Prerequisites: A complete implementation of RESTFul Web service. Deploy and run the application.
Step 2 Create a Crunchifyjmetertest.java file
Package Com.crunchify.restjersey; Import Java.io.filenotfoundexception;import java.io.IOException; Import Javax.ws.rs.get;import Javax.ws.rs.path;import javax.ws.rs.Produces; /** * @author crunchify * *  /@Path ("/index") public class Crunchifyjmetertest {@GET @produces ("text/html") public String Checkecv () throws Interruptedexception, FileNotFoundException, IOException {string result = "<br><div align= ' center ' >

You should then see the following ECLIPSE directory structure:

Step 3 Redeploy Crunchifyrestjerseyexample on Tomcat and use this URL to test your REST service:
url:http://localhost:8080/crunchifyrestjerseyexample/crunchify/index/

Step 4 Copy the following script to a text file and save as CRUNCHIFY-JMETER-TEST.JMX:
<?xml version= "1.0" encoding= "UTF-8"? ><jmetertestplan version= "1.2" properties= "2.4" jmeter= "2.9 r1437961" > 
Step 5
    • Download Apache JMeter
    • Start JMeter with a jmeter.bat or jmeter.sh file
    • Click File, Open
    • Switch to the directory where you saved the Crunchify-jmeter-test.jmx file and select the file
Step 6
    • Expand the Crunchify test case you will see the interface shown
    • Click HTTP Request
    • Verify that the parameters are correct

Step 7 Analyze your test results:

Original link: How to call Your Restful Web Service Using JMeter? Perform a simple Load testing and Automation.
Translator: "Stress test for a restful Web service based on Jersey framework" Jersey Project a RESTful Web service project based on the Jersey framework is as follows:

After you deploy it, access the WADL address HTTP://192.168.23.204/UAS/RESOURCE/APPLICATION.WADL:


Web Service methods We want to test this method:
    /** * Data Initialization * @param request * @return */@Override @POST @Produces (mediatype.application_jso N) @Path ("Push") public userpushresponse push (Userpushrequest request) {Logger.info (">>>> user" +        Request.gettoken () + "information initialization!");        Logger.info (">>>> Data initialization Request message: {}", new object[]{jsonutils.object2jsonstring});        return message userpushresponse response;            try {//Request message Check Userpushservice.validaterequest (requests); Database Operations Redisdao.set (Request.gettoken (), Request.getvalue (), New Long (Request.gettimeou            T ()));        Organization Success Message response = Userpushservice.buildsucessresponse (request);            } catch (Exception e) {logger.info (E.getmessage (), E);        Response = Userpushservice.buildfailresposne (e); } logger.info ("User Information initialization response message: {}", New Object[]{jsonutils.object2jsonstring (responSE)});    return response; }

The method unit tests the relevant code:
 UserResource    Userresource = Restfuljsonclientfactory.createclient (Userresource.class, VIP);    Logger Logger = Loggerfactory.getlogger (This.getclass ());        @Test public void Testresource () {userpushrequest pushrequest = new Userpushrequest ();        Pushrequest.settoken ("mytest004");        Userinfoandmenu Userinfoandmenu = new Userinfoandmenu ();        UserInfo UserInfo = new UserInfo ();        Userinfo.setmercode ("102239");        Userinfo.setaccountlist (Getaccountlist ());        Userinfoandmenu.setuserinfo (UserInfo);        Pushrequest.setvalue (jsonutils.object2jsonstring (Userinfoandmenu));        Pushrequest.settimeout (10000);        SYSTEM.OUT.PRINTLN ("request message: {}" +jsonutils.object2jsonstring (Pushrequest));        Userpushresponse response = Userresource.push (pushrequest);    SYSTEM.OUT.PRINTLN ("Response message: {}" +jsonutils.object2jsonstring (response)); }

Restfuljsonclientfactory is a WebService remote client-created class. Perform the unit test, output:
Request message: {} {"Msgtype": null, "Trancode": null, "Syscode": "1001", "Brccode": "$", "Srccode": "", "Frontno": " ips-02040668 "," Fronttime ":" 2017-01-20 15:27:19 "," Repcode ": null," repmsg ": null," remark ": null," Version ":" 1.0 "," Signature ": null," cerversion ": null," Channelno ":" N "," token ":" mytest004 "," value ":" {\ "csrftoken\": null,\ "UserInfo \ ": {\" loginname\ ": Null,\" mercode\ ": \" 102239\ ", \" mername\ ": Null,\" accountlist\ ": [{\" acccountcode\ ": \" 1022380016 \ ", \" accountname\ ": \" redis test account name \ "}],\" operator\ ": Null,\" role\ ": Null},\" menutree\ ": null}", "TimeOut": "10000", " Reqdate ": null}
Response message: {} {"Msgtype": null, "Trancode": null, "Syscode": "1001", "Brccode": "$", "Srccode": "", "Frontno": " Channel.web.ips.local "," Fronttime ":" 2017-01-20 15:26:24 "," Repcode ":" 000000 "," repmsg ":" Success "," remark ": null," Version ":" 1.0 "," signature ": null," cerversion ": null," Channelno ":" "", "token": "mytest004", "Result": "1", "reqdate": NULL}
HTTP message interception Smartsniff intercepted this Web Service call, including a complete HTTP request message (blue Word section) and return message (The Scarlet Letter part):

Based on the results of Smartsniff, we got the full url:http:192.168.23.204/uas/resource/of this Web Service call. Com.ips.uas.biz.resource.userresource/push, and complete message:
Post/uas/resource/com.ips.uas.biz.resource.userresource/push http/1.1
Content-type:application/json
User-agent:java/1.6.0_29
host:192.168.23.204
Accept:text/html, Image/gif, Image/jpeg, *; Q=.2, */*; q=.2
Connection:keep-alive
content-length:429

{"Syscode": "1001", "Brccode": "$", "Srccode": "Frontno", "ips-02040668": "2017-01-20 17:12:29", " Version ":" 1.0 "," Channelno ":" N "," token ":" mytest004 "," value ":" {\ "csrftoken\": Null,\ "userinfo\": {\ "loginname\": Null,\ "mercode\": \ "102239\", \ "mername\": Null,\ "accountlist\": [{\ "acccountcode\": \ "1022380016\", \ "Accountname\" : \ "redis..................\"}],\ "operator\": Null,\ "role\": Null},\ "menutree\": null} "," TimeOut ": 10000}
http/1.1 OK
server:nginx/1.10.2
Date:fri, 09:11:28 GMT
Content-type:application/json
Transfer-encoding:chunked
Connection:keep-alive

Db
{"Syscode": "1001", "Brccode": "$", "Srccode": "Frontno", "channel.web.ips.local": "2017-01-20 17:11:28 "," Repcode ":" 000000 "," repmsg ":" ... "," Version ":" 1.0 "," Channelno ":" "," token ":" mytest004 "," Result ": 1 }
0
These are useful information, URLs are used when we write the HTTP sampler configuration path, the request message is used when our organization requests the style, and the return message can be used to refer to the write assertion.
The HTTP header Manager JMeter creates a new test thread group, creates a new HTTP header, and the header joins the name Content-type value to the Application/json entry:

The HTTP request Sampler edits the HTTP request sampler based on the interception information, noting the frame section:

The HTTP response Assertion edits the HTTP response assertion based on the interception information:

Perform stress test using view result tree to debug the script successfully, then configure the thread group concurrency number, the number of cycles, etc., start the pressure measurement, one hours after the TRT result:

TPS Data:


Translator PostScript

The stress test script for Web services is very well written, but it often falls into a complex and cumbersome script development debug if the client building the Web service, such as write BeanShell, implements the remote service invocation locally. Another way of thinking, such as from the point of view of the Protocol, the Web Service complex can not get rid of HTTP it? Then, with the help of a reasonable protocol tool, seemingly complex scripting can become very simple.

How do I use JMeter to call your Restful Web Service? Perform simple stress testing and automated testing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.