When I get Context from a Spring Process Application (Shared Engine) I get an empty Class, I mean that every property is null.
It’s weird because the classLoader is the same.
Example:
ScriptingEgines scriptEngines = (StandaloneProcessConfiguration)(processEngine.getProcessEngineConfiguration()).getScriptingEngines()
This will return the right object, the same object that can be returned from a script executed from a camunda engine.
But if I call something like:
scriptEngines.getScriptEngineForLanguage(“groovy”)
I get nullPointer exception. The error is generated by the code of the ScriptEngines Class using Context.getProcessEngineConfiguration statically.
This fails because you are using internal API that is not meant to be run outside of an engine command (e.g. Context.get
methods only return useful things within an engine command).
You have two options to continue:
Thanks Thorben.
I used JSR-223 API to create with a brand new ScriptEngineManager and it works very well with compilation cache and all.
However I read some subtleties about thread safety of the api and that was the very reason that made me think to use internal camunda classes to get around this problem.
I execute the script in this way:
ScriptEngine engine = scriptEngineManager.getEngineByName(“groovy”);
Bindings b = engine.createBindings();
//…(put some variables in the bindings object)
engine.eval(new java.io.FileReader(path), b);
This is executed inside a spring bean called by a ServiceTask. I don’t know what possible problems could have this solution.
Do you have a reference for the thread-safety issues?
The process engine does not do much more than what you do, just that it caches the scripting engines (i.e. asks the script engine manager only once). This should not be too hard to build yourself, if that is required. Depending on the scripting engine you want to use, you may have to apply extra configuration (http://groovy-lang.org/integrating.html#jsr223 mentions some things).
Cheers,
Thorben