JMeter to save the response information to the local file code

Source: Internet
Author: User

JMeter do performance testing, you need to save the data from the server back to the local and every time the returned data saved to a document, JMeter can use "Save response to file", but each data returned by the server is saved separately as a document, is not conducive to data statistics. Save the data returned by the server to a local file code as follows:

Import Org.apache.commons.io.FileUtils;

Import org.apache.jmeter.config.Arguments;

Importorg.apache.jmeter.protocol.java.sampler.JavaSamplerClient;

Importorg.apache.jmeter.protocol.java.sampler.JavaSamplerContext;

Importorg.apache.jmeter.samplers.SampleResult;

Import Java.io.File;

Import java.io.IOException;

Import java.util.ArrayList;

Import java.util.List;

public class Getresposedata Implementsjavasamplerclient {

String file = "E:" + file.separator + "javatest" +file.separator + "input.txt";

public void Setuptest (Javasamplercontext javasamplercontext) {

}

Public Sampleresult runtest (Javasamplercontext javasamplercontext) {

List<string> contents=new arraylist<string> ();

Contents.add (Javasamplercontext.getparameter ("Responsestr"));

Sampleresult sampleresult=new Sampleresult ();

Sampleresult.samplestart ();

try {

Fileutils.writelines (new file (file), contents,true);

if (true) {

Sampleresult.setresponsedata ("The contents of the preservation are:" +contents.get (0), "UTF-8");

Sampleresult.setsuccessful (TRUE);

}

catch (IOException e) {

E.printstacktrace ();

}

Sampleresult.sampleend ();

return sampleresult;

}

public void Teardowntest (Javasamplercontext javasamplercontext) {

}

Public Arguments getdefaultparameters () {

Arguments Arguments = new Arguments ();

Arguments.addargument ("Responsestr", "");

return arguments;

}

}

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.