minimal-json icon indicating copy to clipboard operation
minimal-json copied to clipboard

JMeter Post-procesor BeanShell - No such field Member

Open kslysz opened this issue 7 years ago • 1 comments

Hi,

I've tried to extract values from json responose in JMeter Post-processor BeanShell.

My sample response is: {"tableName":"users","tagName":"registered","bundleId":33,"tagId":2,"owner":"JMeter","description":"","locked":false,"properties":{"address":"London","name":"John","id":"95","email":"[email protected]"}}

My BeanShell is:

debug();

import com.eclipsesource.json.Json;
import com.eclipsesource.json.JsonObject;
import com.eclipsesource.json.JsonObject.Member;

JsonObject bundle = Json.parse(prev.getResponseDataAsString()).asObject();

vars.put("b_tableName", bundle.get("tableName").asString());
vars.put("b_tagName", bundle.get("tagName").asString());
vars.put("b_bundleId", Long.toString(bundle.get("bundleId").asLong()));
vars.put("b_tagId", Integer.toString(bundle.get("tagId").asInt()));
vars.put("b_owner", bundle.get("owner").asString());
vars.put("b_description", bundle.get("description").asString());
vars.put("b_locked", Boolean.toString(bundle.get("locked").asBoolean()));

JsonObject properties = bundle.get("properties").asObject();


try {
	for (Member property : properties)
		vars.put("p_" + property.getName(), property.getValue().asString());
} catch (Exception e) {
	e.printStackTrace();
}

I've tried almost the same code (istead of vars.put is System.out) in Eclipse and everything works fine. The problem is with this line: for (Member property : properties) Does JMeter don't read nested class?

Log: // Debug: field reflect error: bsh.ReflectError: No such field: Member // Debug: Trying to load class: com.eclipsesource.json.JsonObject$Member Can't iterate over type: class com.eclipsesource.json.JsonObject : at Line: 21 : in file: inline evaluation of: ``debug(); import com.eclipsesource.json.Json; import com.eclipsesource.json.Json . . . '' : for ( com .eclipsesource .json .JsonObject .Member property : properties ) vars .put ( "p_" + property .getName ( ) , property .getValue ( ) .asString ( ) ) ;

at bsh.BSHEnhancedForStatement.eval(BSHEnhancedForStatement.java:57)
at bsh.BSHBlock.evalBlock(BSHBlock.java:130)
at bsh.BSHBlock.eval(BSHBlock.java:80)
at bsh.BSHBlock.eval(BSHBlock.java:46)
at bsh.BSHTryStatement.eval(BSHTryStatement.java:86)
at bsh.Interpreter.eval(Interpreter.java:645)
at bsh.Interpreter.eval(Interpreter.java:739)
at bsh.Interpreter.eval(Interpreter.java:728)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.jmeter.util.BeanShellInterpreter.bshInvoke(BeanShellInterpreter.java:166)
at org.apache.jmeter.util.BeanShellInterpreter.eval(BeanShellInterpreter.java:189)
at org.apache.jmeter.util.BeanShellTestElement.processFileOrScript(BeanShellTestElement.java:151)
at org.apache.jmeter.extractor.BeanShellPostProcessor.process(BeanShellPostProcessor.java:64)
at org.apache.jmeter.threads.JMeterThread.runPostProcessors(JMeterThread.java:827)
at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:517)
at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:425)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:254)
at java.lang.Thread.run(Thread.java:745)

kslysz avatar Apr 21 '17 13:04 kslysz

you have a promme jmeter no used this

HuxiaoZhang avatar May 06 '19 09:05 HuxiaoZhang