Hi Rinke;
>From the looks of it, I'd say the 'private static ....' and permissions are
>the most likely culprit (if you are using JEXL 3.3).
JEXL will only see/introspect public classes for which it is allowed to through
permissions; you own classes/packages must be allowed (they aren't by default)
and they must be public. (see
https://commons.apache.org/proper/commons-jexl/apidocs/org/apache/commons/jexl3/introspection/JexlPermissions.html#parse-java.lang.String...-)
Cheers
On 2023/11/03 13:28:50 "r.c.hoekstra" wrote:
> 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
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]