I'm trying to get a jexl script to work.
|// arranging namespace Print Map<String, Object> ns = new HashMap<>(1);
ns.put("Print", System.out); // make System.out.println available in
expressions JexlEngine je = new JexlBuilder().namespaces(ns).create();
// arranging custom Map for accessible variable 'agent' in script
Map<String, Object> myMap = ....; myMap.put("test", testRef);
JexlContext jc = new MapContext(myMap); // arranging script JexlScript
script = je.createScript(expression); Object result = script.execute(jc); |||||
|The testRef is just a simple instance of this class: |
privatestaticclassTestContextVar {
publicString getInstanceVar(){
return"instanceValue";
}
}
with the expression being this:
|{ Print:println("blabla"); const x = test.getInstanceVar();
Print:println(x); return true; } |
||
The first command just prints "blabla" to the console, so the printing
via System.out.println works flawless.
However, for the variable test: it does exist, because jexl doesn't
report "unsolvable variable". Also, Print:println(test) just prints the
memory address as expected.
However, any method of the test Object which I try to call, always
returns null. I just get a null printed to the console.
Also, when I call test.instanceVar (which should be possible, it is just
a POJO), I get "undefined property 'id', assuming false". Whereas
test.getInstanceVar() returns just null.
Anyone any idea what could go wrong here?
thanks, Rinke