Open jmetertea opened 4 years ago
The linked answer is right that downcasting is required. This was discussed when the minimal scripting support was introduced. It probably would not be too difficult for a motivated individual to add a cast in the code text generated to access the bound object. Alternatively, wrap the bound object as Dynamic
. The set of bindings is already modeled as Dynamic
selection (instead of just a Map). Maybe the original impetus was for it to supply Dynamic
objects you could drill into reflectively.
With current and future changes to REPL support, it's an appropriate moment to commit to an improved scripting experience.
There is a bit more. If we try to use Compile the scala source code as script it would not even compile.
import javax.script.*;
final String code = "x" ;
Bindings b = new SimpleBindings();
b.put("x", 42 );
final ScriptEngine engine = ScriptEngineManager.getEngineByName("scala");
CompiledScript compiled = ((Compilable) engine).compile(code); // boom --> compile issue right here...
This will state that variable "x" is not found.
I try to use JSR223 code using bindings parameters (using JMeter):
bindings parameters can't be used when using Scala engine (in other engines as beanshell,groovy,velocity,... it works)
I expect one of syntax to work in script
First asked in https://stackoverflow.com/questions/57266997/scala-jsr223-script-using-jmeter-java-context