0
votes

I have a web service I need to test with JMeter but the spec requires compressed json. I need to create the json from data in a CSV file. I have been able to work that out using a beanshell preprocessor and a CSV dataset config. But now I need a way to gzip the data and send it to the server. Is there some sampler out there that will do this?

Hackish Solution

The only working solution I've found is to compress the data from the beanshell script then have JMeter send the file, but this seems a bit nasty to me.

import com.eclipsesource.json.*;
import java.io.FileOutputStream;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.util.zip.GZIPOutputStream;

jsonObject = new JsonObject();
// populate json data here

GZIPOutputStream zip = new GZIPOutputStream(new FileOutputStream("c:\\json.gz"));
writer = new BufferedWriter(new OutputStreamWriter(zip, "UTF-8"));
jsonObject.writeTo(writer);
writer.close();

If there are no samplers that do the compression, is there a way to avoid writing the data to the file system? Should I make a post processor to delete the temp file? Thanks for your help!

1

1 Answers

2
votes

None of the samplers I know will automatically zip for you.

You can use a ByteArrayOutputStream instead of FileOutputStream, then toString it to a jmeter variable or property, so you can use it in the sampler using the variable name.

import com.eclipsesource.json.*;
import java.io.ByteArrayOutputStream;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.util.zip.GZIPOutputStream;

jsonObject = new JsonObject();
// populate json data here

GZIPOutputStream zip = new GZIPOutputStream(new ByteArrayOutputStream());
writer = new BufferedWriter(new OutputStreamWriter(zip, "UTF-8"));
jsonObject.writeTo(writer);
writer.close();

vars.put("ZIPFILE", zip.toString());

Then in the Body Data section of your http request, refer to the variable ${ZIPFILE}