Uploaded image for project: 'WildFly Core'
  1. WildFly Core
  2. WFCORE-719

JDK 1.8 javax.script.ScriptEngineFactory: Provider com.sun.script.javascript.RhinoScriptEngineFactory not found

    Details

      Description

      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

      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;
      	}
      }
      
      

      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

      com.sun.script.javascript.RhinoScriptEngineFactory
      jdk.nashorn.api.scripting.NashornScriptEngineFactory
      

      It should be made sure that with every JDK JSR 223 compliant requests for a JavaScript engine will work out of the box.

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  ctomc Toma┼ż Cerar
                  Reporter:
                  manuelb Manuel Blechschmidt
                • Votes:
                  1 Vote for this issue
                  Watchers:
                  7 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: