Does Google App Engine Support Java Script Engine?
I want evaluate dynamically JavaScript code inside the Google App Engine runtime. Java have this feature but Want to know if this is supported by GAE too. If you can provide a simp
Solution 1:
Last time I tried, though ScriptEngine is whitelisted, it is not available in the production environment. I had to package the Rhino.jar along with my app.
For examples on general usage of scripting in Java, you can refer to the Java documentation itself.
Though, note that in the GAE/J environment you will need to invoke the Rhino APIs directly.
For example,
// Import statements.import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
private Object executeUsingRhino(String script)throws Exception
{
Contextctx= Context.enter();
try
{
Scriptablescope= ctx.initStandardObjects();
return ctx.evaluateString(scope, script, "<cmd>", 1, null);
}
finally
{
Context.exit();
}
}
// Invoke a script that returns a string output using the following code snippetStringoutput= Context.toString(executeUsingRhino(script));
Solution 2:
https://developers.google.com/appengine/docs/java/jrewhitelist includes javax.script.ScriptEngine in its whitelisted (allowed) APIs, so, yes.
Post a Comment for "Does Google App Engine Support Java Script Engine?"