Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JMeter Post-procesor BeanShell - No such field Member #78

Open
kslysz opened this issue Apr 21, 2017 · 1 comment
Open

JMeter Post-procesor BeanShell - No such field Member #78

kslysz opened this issue Apr 21, 2017 · 1 comment

Comments

@kslysz
Copy link

kslysz commented Apr 21, 2017

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)
@HuxiaoZhang
Copy link

you have a promme jmeter no used this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants