I need to send a JSON Object to the HTTP Request body in JMeter using the BeanShell PreProcessor. The JSON object is modeled using java code with some business logic. I have created a BeanShell PreProcessor and written the java code below,
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
String key="testKey";
int lastID=5548;
int totalCount=198;
JSONObject obj1 = new JSONObject();
JSONArray obj2 = new JSONArray();
for (int i=1;i<=totalCount;i++)
{
JSONObject item = new JSONObject();
item.put("taskId", Integer.toString(lastID+i));
item.put("taskOrder",1);
item.put("snapshotTemplateKey",key);
obj2.put(item);
obj1.put("changeControlTasks", obj2);
obj1.put("ccName","Eleven" );
obj1.put("snapshotTemplateKey",key);
}
log.info(obj1);
vars.putObject("jsonData",obj1);
The data from the above code is being fetched in the HTTP request body as shown below,
${jsonData}
When running this, an error is encountered:
Request :
POST data:
${jsonData}
Error in the logs:
2017/08/06 07:27:10 ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval
Sourced file: inline evaluation of: ``import org.json.JSONArray; import org.json.JSONException;
import org.json.JSONOb . . . '' : Error in method invocation: Method info( ) not found in class'org.apache.log.Logger'
If anyone can provide insights on what could be the issue with the code above and how to resolve it, it would be greatly appreciated.
any suggestions or solutions will also be appreciated.