]
RH Bugzilla Integration commented on WFLY-3991:
-----------------------------------------------
David Le Sage <dlesage(a)redhat.com> changed the Status of [bug
JDK 1.8 javax.script.ScriptEngineFactory: Provider
com.sun.script.javascript.RhinoScriptEngineFactory not found
---------------------------------------------------------------------------------------------------------------
Key: WFLY-3991
URL:
https://issues.jboss.org/browse/WFLY-3991
Project: WildFly
Issue Type: Enhancement
Reporter: Manuel Blechschmidt
Assignee: Jason Greene
Labels: JS223, JavaScript, Scripting
When using the ScriptManager in a JSF bean the following happens:
ERROR [stderr] (default task-21) ScriptEngineManager providers.next():
javax.script.ScriptEngineFactory: Provider
com.sun.script.javascript.RhinoScriptEngineFactory not found
{code}
package de.example.log.jsf;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import javax.enterprise.inject.Model;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.script.Bindings;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
@Model
public class Scripting {
private String script;
private String output;
private ScriptEngineManager mgr = new ScriptEngineManager();
public static String utilJavaScript = "var print = function (s) {
__newOut.print(s); }; var println = function (s) { __newOut.println(s); };";
public String execute() {
ScriptEngine jsEngine = mgr.getEngineByName("JavaScript");
ByteArrayOutputStream outputBuffer = new ByteArrayOutputStream(8192);
PrintStream newOut = new PrintStream(outputBuffer, true);
Bindings bindings = jsEngine.createBindings();
bindings.put("__newOut", newOut);
try {
jsEngine.eval(utilJavaScript + getScript(), bindings);
} catch (ScriptException from) {
FacesContext.getCurrentInstance().addMessage(
null,
new FacesMessage(from.getColumnNumber() + " "
+ from.getFileName() + " " + from.getLineNumber()
+ " " + from.getMessage()));
return null;
}
newOut.close();
String returnString = outputBuffer.toString();
setOutput(returnString);
try {
outputBuffer.close();
} catch (IOException e) {
FacesContext.getCurrentInstance().addMessage(
null,
new FacesMessage(e.getLocalizedMessage()));
}
return null;
}
public String getScript() {
return script;
}
public void setScript(String script) {
this.script = script;
}
public String getOutput() {
return output;
}
public void setOutput(String output) {
this.output = output;
}
}
{code}
The script engines are configured in the following file:
WILDFLY_HOME/modules/system/layers/base/sun/jdk/main/service-loader-resources/META-INF/services/javax.script.ScriptEngineFactory
{code}
com.sun.script.javascript.RhinoScriptEngineFactory
jdk.nashorn.api.scripting.NashornScriptEngineFactory
{code}
It should be made sure that with every JDK JSR 223 compliant requests for a JavaScript
engine will work out of the box.