Issue while sending a JSON object with BeanShell PreProcessor

Viewed 2679

I want to send one JSON Object to the HTTP Request body in JMeter using the BeanShell PreProcessor. To model the JSON object I am using java code (with some business logic). Hence I created one BeanShell PreProcessor and wrote the java code as follows,

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

And in the HTTP request body, I am trying to fetch the data as follows,

${jsonData}

With the above code, It is throwing the below shared error

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'

Can any one suggest what is issue with above code and how to resolve the same.

any suggestions or solutions will also be appreciated.

2 Answers
Related