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