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;
}
}