i have a problem with code from here https://www.blazemeter.com/blog/saving-data-to-csv-files-with-java-through-jmeter I try to write data to csv. I use all code - i only change line 47 String[] params = {${context1}, ${context2}};
when i execute the test i get such a message in sampler result
Response code: 500
Response message: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of:
'import java.io.FileWriter; import java.util.Arrays; import java.io.Writer; impor . . . '
: Typed variable declaration : Error in array initializer: null in log file2018/02/01 12:32:52 ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of:
'import java.io.FileWriter; import java.util.Arrays; import java.io.Writer; impor . . . '
: Typed variable declaration : Error in array initializer: null2018/02/01 12:32:52 WARN - jmeter.protocol.java.sampler.BeanShellSampler: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of:
'import java.io.FileWriter; import java.util.Arrays; import java.io.Writer; impor . . . '
: Typed variable declaration : Error in array initializer: null
any help ? :)
import java.io.FileWriter;
import java.util.Arrays;
import java.io.Writer;
import java.util.List;
//Default separator
char SEPARATOR = ',';
//function write line in csv
public void writeLine(FileWriter writer, String[] params, char separator)
{
boolean firstParam = true;
StringBuilder stringBuilder = new StringBuilder();
String param = "";
for (int i = 0; i < params.length; i++)
{
//get param
param = params[i];
log.info(param);
//if the first param in the line, separator is not needed
if (!firstParam)
{
stringBuilder.append(separator);
}
//Add param to line
stringBuilder.append(param);
firstParam = false;
}
//prepare file to next line
stringBuilder.append("\n");
//add to file the line
log.info(stringBuilder.toString());
writer.append(stringBuilder.toString());
}
//get path of csv file (creates new one if its not exists)
String csvFile = "/JMeter/dane.csv"; // for example '/User/Downloads/blabla.csv'
String[] params = {${context1}, ${context2}};
FileWriter fileWriter = new FileWriter(csvFile, true);
writeLine(fileWriter, params, SEPARATOR);
//proper close to file
fileWriter.flush();
fileWriter.close();