Search in sources :

Example 81 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 82 with ScriptException

use of javax.script.ScriptException in project midpoint by Evolveum.

the class Jsr223ScriptEvaluator method createCompiledScript.

private CompiledScript createCompiledScript(String codeString, String contextDescription) throws ExpressionEvaluationException {
    CompiledScript compiledScript = scriptCache.get(codeString);
    if (compiledScript != null) {
        return compiledScript;
    }
    try {
        InternalMonitor.recordScriptCompile();
        compiledScript = ((Compilable) scriptEngine).compile(codeString);
    } catch (ScriptException e) {
        throw new ExpressionEvaluationException(e.getMessage() + " in " + contextDescription, e);
    }
    scriptCache.put(codeString, compiledScript);
    return compiledScript;
}
Also used : CompiledScript(javax.script.CompiledScript) ScriptException(javax.script.ScriptException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException)

Example 83 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 84 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 85 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)

Aggregations

ScriptException (javax.script.ScriptException)106 ScriptEngine (javax.script.ScriptEngine)42 IOException (java.io.IOException)41 Bindings (javax.script.Bindings)30 ScriptEngineManager (javax.script.ScriptEngineManager)20 InputStreamReader (java.io.InputStreamReader)12 CompiledScript (javax.script.CompiledScript)12 Map (java.util.Map)11 Invocable (javax.script.Invocable)11 ScriptContext (javax.script.ScriptContext)11 SimpleBindings (javax.script.SimpleBindings)10 File (java.io.File)8 Reader (java.io.Reader)7 Writer (java.io.Writer)7 HashMap (java.util.HashMap)7 PrintWriter (java.io.PrintWriter)6 ArrayList (java.util.ArrayList)6 SlingBindings (org.apache.sling.api.scripting.SlingBindings)6 MissingMethodException (groovy.lang.MissingMethodException)5 MissingPropertyException (groovy.lang.MissingPropertyException)5