Here POST request which is using MIME type as Multipart/form-data and parameter as spb I'm passing 1 text file which has complete JSON body.
text file : upload.txt
{
"id":"Rx2160C-019A",
"iAgree":false,
"price":"31.25",
"maxDispenceDays":null,
"RxId":"DRAFT9800E",
.......
}
Every time I need to update the id
and RxId
in the text file based on the last HTTP request.
I was trying do with BeanShell PostProcessor
element, But I am not getting proper code and solution for this.
f = new FileOutputStream("/Users/bhkuma/Documents/Bharath/Jmeter/LoadTesting/goRxDigitize.txt", true);
p = new PrintStream(f);
this.interpreter.setOut(p);
print(name + "," + email);
f.close();
How can i achieve this?
This is the updated code that i m trying..
import java.io.File;
import java.io.FileWriter;
import java.io.FileReader;
import java.io.IOException;
import java.io.BufferedReader;
import org.json.JSONException;
import org.json.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
//ObjectMapper mapper = new ObjectMapper();
//JSONObject root = mapper.readValue(new File("/Users/bhkuma/Documents/Bharath/Jmeter/LoadTesting/upload.txt"), JSONObject.class);
FileReader fr = new FileReader("/Users/bhkuma/Documents/Bharath/Jmeter/LoadTesting/upload.txt");
BufferedReader br = new BufferedReader(fr);
String sCurrentLine;
String output="";
while ((sCurrentLine = br.readLine()) != null) {
output += sCurrentLine;
//System.out.println(sCurrentLine);
}
log.info("bharath");
log.info(output);
JSONObject obj = new JSONObject(output);
JSONObject value = new JSONObject();
value.put("id","Rx2160C-100A");
log.info(value);
obj.put(value);
log.info(output);
System.out.println("Successfully updated json object to file...!!");
and here JSON object wont work...
I've heard Groovy is the New Black so I would recommend switching from Beanshell to JSR223 PostProcessor. The relevant Groovy code to replace
id
would be something like:References: