Does the Google App Engine support the Java Script Engine?

I want to evaluate dynamic JavaScript code inside the Google App Engine runtime.

Java has this feature, but I want to know if it is also supported by GAE.

If you can provide a simple code, you will be very grateful, and if you use it, please share comments with it, thanks.

...

GAE support Scripting languages, but by default the JavaScript service is not registered. Therefore, GAE out of the box does not evaluate JavaScript.

+1
source share
2 answers

The last time I tried, although ScriptEngine is whitelisted, it is not available in the production environment. I had to pack Rhino.jar along with my application.

In examples of common use of scripts in Java, you can directly refer to the Java documentation .

Although, note that in a GAE / J environment, you will need to directly access the Rhino APIs.

For instance,

// Import statements. import org.mozilla.javascript.Context; import org.mozilla.javascript.Scriptable; private Object executeUsingRhino(String script) throws Exception { Context ctx = Context.enter(); try { Scriptable scope = 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 snippet String output = Context.toString(executeUsingRhino(script)); 
+2
source

https://developers.google.com/appengine/docs/java/jrewhitelist includes javax.script.ScriptEngine in its white (allowed) APIs, so yes.

+2
source

Source: https://habr.com/ru/post/1382616/


All Articles