Using JMeter to WebService pressure test

Source: Internet
Author: User

using JMeter to WebService pressure test
we used JMeter to test the webservice, and Apache JMeter was a Java-based pressure test tool developed by Apache. Used to make pressure tests on software.
the role of JMeter1. Both the HTTP and Ftpserver can be tested for stress and performance, and the same test (through JDBC) can be done on any database. 2. Total portability and 100% pure java. 3. Full Swing and lightweight components support (precompiled jar using javax.swing.*) package. 4. The fully multithreaded framework agrees to sample multiple threads concurrently and through separate thread groups for different functions at the same time. 5. The careful GUI design agrees with high-speed operation and more accurate timing.

6. Caching and offline analysis/playback of test results.

Second: The configuration of the relevant environment variables for JMeter is similar to the configuration of Java, reference to the online information

Three: JMeter The WebService Test example for the HTTP protocol.


1: First create a new thread group in the test plan



, the number of threads and number of loops in the thread attribute represents the number of actual executions performed at the time of the test. You can also visit the number of WebService.

2: The thread group creates a new HTTP request (about the Access interface service's associated address configuration and some configuration of the parameters) and the HTTP information manager (the public request header when sending the WebService service), aggregating the report (test report).






Four: After configuring everything, click Start Run Test
=============we Test WebService by HTTP head start===========
Name=clark
=============we Test WebService by HTTP head end===========

Note ==================================== The following configuration for the WebService service is integrated into spring

Applicationcontext_webservice.xml
<?

XML version= "1.0" encoding= "UTF-8"?>
<beans xmlns= "Http://www.springframework.org/schema/beans"
Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxrs= "Http://cxf.apache.org/jaxrs"
xmlns:context= "Http://www.springframework.org/schema/context"
Xsi:schemalocation= "
Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
Http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd " >
<context:annotation-config/>
<import resource= "Classpath:meta-inf/cxf/cxf.xml"/>

<jaxrs:server id= "Restcontainer" address= "/" >
<jaxrs:serviceBeans><!--here to configure your WebService bean definition.

Test Org.iboxpay.payment.merchant.ws.MerchantWebService--
<!--<ref bean= "Orderwebservice"/> <ref bean= "Merchantwebservice"/>--
<ref bean= "Clearuserwebservice"/>
<ref bean= "Merchantwebservice"/>
<!--<ref bean= "Balancewebservice"/>--
</jaxrs:serviceBeans>
<jaxrs:extensionMappings>
<entry key= "JSON" value= "Application/json"/>
<entry key= "xml" value= "Application/xml"/>
</jaxrs:extensionMappings>
<jaxrs:providers>
<!--<ref bean= "Jsonexmapper"/>--
<ref bean= "Jaxbprovider"/>
<ref bean= "Jsonprovider"/>
</jaxrs:providers>

</jaxrs:server>
<bean id= "Jaxbprovider" class= "Org.apache.cxf.jaxrs.provider.JAXBElementProvider"/>
<!--******************** using Jackson as the serializer ***********************--
<bean id= "Jsonprovider" class= "Org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>

</beans>

Web. xml file cxf plug-in configuration WebService
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>

Configuration of the Web service service in Java
Package com.iboxpay.clear.webservice;


Import Javax.annotation.Resource;
Import Javax.ws.rs.Consumes;
Import Javax.ws.rs.POST;
Import Javax.ws.rs.Path;
Import javax.ws.rs.Produces;
Import Javax.ws.rs.core.MediaType;

Import Org.springframework.stereotype.Service;

Import Com.iboxpay.clear.service.SysResourceService;

@Path ("/clearpro")
@Service ("Clearuserwebservice")
public class Clearwebservice {

@Resource
Private Sysresourceservice Sysresourceservice;

@Path ("/dispath")
@POST
@Produces ({mediatype.application_xml, Mediatype.application_json})
@Consumes ({mediatype.application_xml, Mediatype.application_json})
public string Dispath (string jsonstr) {
System.out.println ("=============we Test WebService by HTTP head start===========");
System.out.println (JSONSTR);
System.out.println ("=============we Test WebService by HTTP head end===========");
Return "Can You";
}

}

assuming you need to see the results returned in JMeter after running the test, we need to create a new view result tree (right-click Thread Group > Join > Listener > View result tree) below the thread group, and you can see the results returned in the Response data column


Note: When JMeter sends a JSON string in the format of a test, we cannot give the name of the reference when we pass the JSON reference, but should be able to give the value directly.

Otherwise, it will include a series of non-string styles when it is uploaded to the background-causing it to garbled. The object that we need is not resolved correctly.


{"Name": "Zhangsan", "description": "Its"} can be, without jsonstr = {"Name": "Zhangsan", "description": "Its"} The JSON reference we just need to parse into the corresponding object in the background can be.
/**
* Convert a JSON string to an object
*
* @author Weiyuanhua
* @date 2010-11-18 02:52:13
* @param jsonstr
* JSON string
* @param beanclass
* Generic Object
* @param field
* Attributes that need to be ignored in the object
* @return
*/
public static Object Jsontoobject (String jsonstr, class<?> beanclass,string ... field) {
Jsonconfig jsonconfig = getjsonconfig (field);
Jsonobject jsonobject = Jsonobject.fromobject (Jsonstr, jsonconfig);
Return Jsonobject.tobean (Jsonobject, Beanclass);
}

private static Jsonconfig Getjsonconfig (String ... field) {
Jsonconfig jsonconfig = new Jsonconfig ();
if (field! = null) {
Jsonconfig = new Jsonconfig ();
string[] exclu = new String[field.length];
for (int i = 0; i < field.length; i++) {
Exclu[i] = Field[i];
}
Jsonconfig.setexcludes (EXCLU);
}
return jsonconfig;
}

Using JMeter to WebService pressure test

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.