Search in sources :

Example 76 with ScriptException

use of javax.script.ScriptException in project incubator-atlas by apache.

the class Titan1Graph method executeGremlinScript.

private Object executeGremlinScript(String gremlinQuery) throws AtlasBaseException {
    GremlinGroovyScriptEngine scriptEngine = getGremlinScriptEngine();
    try {
        Bindings bindings = scriptEngine.createBindings();
        bindings.put("graph", getGraph());
        bindings.put("g", getGraph().traversal());
        Object result = scriptEngine.eval(gremlinQuery, bindings);
        return result;
    } catch (ScriptException e) {
        throw new AtlasBaseException(AtlasErrorCode.GREMLIN_SCRIPT_EXECUTION_FAILED, gremlinQuery);
    } finally {
        releaseGremlinScriptEngine(scriptEngine);
    }
}
Also used : ScriptException(javax.script.ScriptException) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) GremlinGroovyScriptEngine(org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine) Bindings(javax.script.Bindings)

Example 77 with ScriptException

use of javax.script.ScriptException in project jmeter by apache.

the class JSR223TestElement method getScriptEngine.

/**
     * @return {@link ScriptEngine} for language defaulting to groovy if language is not set
     * @throws ScriptException when no {@link ScriptEngine} could be found
     */
protected ScriptEngine getScriptEngine() throws ScriptException {
    String lang = getScriptLanguageWithDefault();
    ScriptEngine scriptEngine = getInstance().getEngineByName(lang);
    if (scriptEngine == null) {
        throw new ScriptException("Cannot find engine named: '" + lang + "', ensure you set language field in JSR223 Test Element: " + getName());
    }
    return scriptEngine;
}
Also used : ScriptException(javax.script.ScriptException) ScriptEngine(javax.script.ScriptEngine)

Example 78 with ScriptException

use of javax.script.ScriptException in project jmeter by apache.

the class JSR223Timer method delay.

/** {@inheritDoc} */
@Override
public long delay() {
    long delay = 0;
    try {
        ScriptEngine scriptEngine = getScriptEngine();
        Object o = processFileOrScript(scriptEngine, null);
        if (o == null) {
            log.warn("Script did not return a value");
            return 0;
        }
        delay = Long.parseLong(o.toString());
    } catch (NumberFormatException | IOException | ScriptException e) {
        log.error("Problem in JSR223 script, {}", getName(), e);
    }
    return delay;
}
Also used : ScriptException(javax.script.ScriptException) IOException(java.io.IOException) ScriptEngine(javax.script.ScriptEngine)

Example 79 with ScriptException

use of javax.script.ScriptException in project jmeter by apache.

the class JSR223PreProcessor method process.

@Override
public void process() {
    try {
        ScriptEngine scriptEngine = getScriptEngine();
        processFileOrScript(scriptEngine, null);
    } catch (ScriptException | IOException e) {
        log.error("Problem in JSR223 script, {}", getName(), e);
    }
}
Also used : ScriptException(javax.script.ScriptException) IOException(java.io.IOException) ScriptEngine(javax.script.ScriptEngine)

Example 80 with ScriptException

use of javax.script.ScriptException in project maven-plugins by apache.

the class EvalMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    ScriptEngine engine = null;
    if (script != null) {
        engine = getScriptEngine(engineName);
        if (engine == null) {
            throw new MojoFailureException("Missing scriptEngine");
        }
    } else {
    // from file
    }
    try {
        ScriptContext context = engine.getContext();
        context.setAttribute("project", project, ScriptContext.GLOBAL_SCOPE);
        Object result = engine.eval(script);
        getLog().info("Result:");
        if (result != null) {
            getLog().info(result.toString());
        }
    } catch (ScriptException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
}
Also used : ScriptException(javax.script.ScriptException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ScriptContext(javax.script.ScriptContext) ScriptEngine(javax.script.ScriptEngine)

Aggregations

ScriptException (javax.script.ScriptException)98 IOException (java.io.IOException)41 ScriptEngine (javax.script.ScriptEngine)36 Bindings (javax.script.Bindings)27 ScriptEngineManager (javax.script.ScriptEngineManager)17 CompiledScript (javax.script.CompiledScript)12 InputStreamReader (java.io.InputStreamReader)11 Invocable (javax.script.Invocable)11 ScriptContext (javax.script.ScriptContext)10 Map (java.util.Map)9 SimpleBindings (javax.script.SimpleBindings)8 Reader (java.io.Reader)7 HashMap (java.util.HashMap)7 File (java.io.File)6 Writer (java.io.Writer)6 ArrayList (java.util.ArrayList)6 SlingBindings (org.apache.sling.api.scripting.SlingBindings)6 MissingMethodException (groovy.lang.MissingMethodException)5 MissingPropertyException (groovy.lang.MissingPropertyException)5 DelegatingMetaClass (groovy.lang.DelegatingMetaClass)4