You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@jmeter.apache.org by bu...@apache.org on 2018/08/07 20:59:23 UTC

[Bug 62604] New: Not being able to use json-smart in BeanShell

https://bz.apache.org/bugzilla/show_bug.cgi?id=62604

            Bug ID: 62604
           Summary: Not being able to use json-smart in BeanShell
           Product: JMeter
           Version: 4.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: major
          Priority: P2
         Component: Main
          Assignee: issues@jmeter.apache.org
          Reporter: ricardogaspar2@gmail.com
  Target Milestone: ---

Created attachment 36076
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=36076&action=edit
jmx file

I'm using JMeter 4.0r1823414

I'm trying to use the library json-smart that resides in lib folder of jmeter
inside a BeanShell script  but without  success.

I'm already using JSON Extractor just to extract some JSONs, but now I need to
manipulate them; that's why I I'm using BeanShell. 

I'm getting the following errors:

2018-08-07 21:38:03,549 ERROR o.a.j.u.BeanShellInterpreter: Error invoking bsh
method: eval     Sourced file: inline evaluation of: ``import
net.minidev.json.JSONObject; import net.minidev.json.parser.JSONParser;   . . .
'' : Typed variable declaration
2018-08-07 21:38:03,549 WARN o.a.j.e.BeanShellPostProcessor: Problem in
BeanShell script: org.apache.jorphan.util.JMeterException: Error invoking bsh
method: eval      Sourced file: inline evaluation of: ``import
net.minidev.json.JSONObject; import net.minidev.json.parser.JSONParser;   . . .
'' : Typed variable declaration

And this is my BeanShell Script:

-------
import net.minidev.json.JSONObject;
import net.minidev.json.parser.JSONParser;

// formats JSON variables houseDataJson; entityTypeGroupsJson
// takes the variable with the JSON for entityTypeGroups and adds the prefix
"entityTypeGroups":{ VARIABLE WITH JSON CODE HERE} 

String SCRIPT_NAME = "[FormatJsonVariables]";

// names of the variables retrieved from JSON Extractor from get_house_data
request
String PKID_VAR_NAME = "pkid";
String HOUSE_DATA_VAR_NAME = "houseDataJson";
String ENTITY_TYPE_GROUPS_VAR_NAME = "entityTypeGroupsJson";

log.info(SCRIPT_NAME+ " checking id variables " + HOUSE_DATA_VAR_NAME +" and "
+ ENTITY_TYPE_GROUPS_VAR_NAME + " are present");

String currentPkid = vars.get(PKID_VAR_NAME);
JSONParser parser = new JSONParser(JSONParser.MODE_JSON_SIMPLE);

JSONObject currentHouseDataJson = (JSONObject)
parser.parse(vars.get(HOUSE_DATA_VAR_NAME));
JSONObject currentEntityTypeGroupsJson = (JSONObject)
parser.parse(vars.get(ENTITY_TYPE_GROUPS_VAR_NAME));

log.info(SCRIPT_NAME + " current variable values:\n-currentPkid: " +
currentPkid + "\ncurrentHouseDataJson: "+ currentHouseDataJson
+"\ncurrentEntityTypeGroupsJson: " +currentEntityTypeGroupsJson)

------------

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 62604] Not being able to use json-smart in BeanShell

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=62604

Felix Schumacher <fe...@internetallee.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID

--- Comment #1 from Felix Schumacher <fe...@internetallee.de> ---
Please ask user questions on the users mailing list before opening a bug.

You gave a pretty detailed description of your problem, but cut the error
messaage short before the real clue was probably shown. When I tested the jmx
file, it barfed on wrong input data. Be sure to give the correct JSON
representation to the parser when you expect an JSON Object (instead of say a
JSON Array).

Note that you could switch to groovy instead of beanshell. It is more modern
and gives nicer error messages.

-- 
You are receiving this mail because:
You are the assignee for the bug.