0
votes

I have a BeanShell postprocessor which has the below code:

props.put("accDom",vars.get("DOMAIN_ID_1"));

Although the code works, and the value does get written to the defined property correctly, the log file is filled with such errors:

2020-11-24 14:41:19,655 ERROR o.a.j.u.BeanShellInterpreter: Error invoking bsh method: eval     Sourced file: inline evaluation of: ``props.put("accDom",vars.get("DOMAIN_ID_1"));'' : Method Invocation props.put
2020-11-24 14:41:19,655 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: ``props.put("accDom",vars.get("DOMAIN_ID_1"));'' : Method Invocation props.put

Any ideas?

2
I modified the script to use this: ``` String accDom = vars.get("DOMAIN_ID_1"); props.put("accDom",accDom); ``` But still no success.nexxus007

2 Answers

0
votes

I changed the BeanShell PostProcessor to a JSR223 Sampler, and edited the syntax to:

String accDom = vars.get("DOMAIN_ID_1");
props.put("accDom",accDom);

// Hide sampler
SampleResult.setIgnore();

This stopped all errors in the logs

0
votes

The log entry doesn't tell the full story, my expectation is that your DOMAIN_ID_1 variable is null at some point, you can try surrounding your code into try block like:

try {
    props.put("accDom", vars.get("DOMAIN_ID_1"));
}
catch (Exception ex) {
    log.error("Failure", ex);
}

this way you will get more comprehensive stacktrace in the jmeter.log file

Be aware that since JMeter 3.1 you should be using JSR223 Test Elements and Groovy language for scripting so:

  1. Change your Beanshell PostProcessor to JSR223 PostProcessor

  2. Amend your code to use Elvis operator to provide the default value if DOMAIN_ID_1 variable is not set:

    props.put("accDom", vars.get("DOMAIN_ID_1") ?: "some default value");
    

More information on Groovy scripting in JMeter: Apache Groovy - Why and How You Should Use It

And last but not the least, it might be the case your PostProcessor placement causes its extra execution, see JMeter Scoping Rules chapter for detailed explanation, you should put the PostProcessor as a child of the Sampler which defines this DOMAIN_ID_1 variable, if you place it at the same level with all the Samplers - it will be executed after each sampler causing errors as the variable is not defined.