use of javax.script.ScriptException in project zipkin by openzipkin.
the class ZipkinMySQLContainer method containerIsStarted.
@Override
protected void containerIsStarted(InspectContainerResponse containerInfo) {
String[] scripts = { // Drop all previously created tables in zipkin.*
"drop_zipkin_tables.sql", // Populate the schema
"mysql.sql" };
try (Connection connection = dataSource.getConnection()) {
for (String script : scripts) {
URL scriptURL = Resources.getResource(script);
String statements = Resources.toString(scriptURL, Charset.defaultCharset());
ScriptUtils.executeSqlScript(connection, script, statements);
}
} catch (SQLException | IOException | ScriptException e) {
throw new RuntimeException(e);
}
}
use of javax.script.ScriptException in project camel by apache.
the class ScriptBuilder method evaluateScript.
protected Object evaluateScript(Exchange exchange) {
try {
if (reuseScriptEngine(exchange)) {
// It's not safe to do the evaluation with a single scriptEngine
synchronized (this) {
LOG.debug("Calling doEvaluateScript without creating a new scriptEngine");
return doEvaluateScript(exchange, scriptEngine);
}
} else {
LOG.debug("Calling doEvaluateScript with a new scriptEngine");
// get a new engine which we must for each exchange
ScriptEngine engine = scriptEngineFactory.getScriptEngine();
return doEvaluateScript(exchange, engine);
}
} catch (ScriptException e) {
if (LOG.isDebugEnabled()) {
LOG.debug("Script evaluation failed: " + e.getMessage(), e);
}
if (e.getCause() != null) {
throw createScriptEvaluationException(e.getCause());
} else {
throw createScriptEvaluationException(e);
}
} catch (IOException e) {
throw createScriptEvaluationException(e);
}
}
use of javax.script.ScriptException in project gremlin by tinkerpop.
the class GremlinGroovyScriptEngineTest method untestUsingClassesIsGood.
public void untestUsingClassesIsGood() throws ScriptException {
GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine();
final Graph g = TinkerGraphFactory.createTinkerGraph();
final Bindings bindings = engine.createBindings();
bindings.put("g", g);
// works when it's all defined together
assertEquals(true, engine.eval("class c { static def isVadas(v){v.name=='vadas'}};c.isVadas(g.v(2))", bindings));
// let's reset this piece and make sure isVadas is not hanging around.
engine = new GremlinGroovyScriptEngine();
// validate that isVadas throws an exception since it is not defined
try {
engine.eval("c.isVadas(g.v(2))", bindings);
// fail the test if the above doesn't throw an exception
fail();
} catch (Exception ex) {
// this is good...we want this. it means isVadas isn't hanging about
}
// now...define the class separately on its own in one script...
// HERE'S and AWKWARD BIT.........
// YOU HAVE TO END WITH: null;
// ....OR ELSE YOU GET:
// javax.script.ScriptException: javax.script.ScriptException:
// org.codehaus.groovy.runtime.metaclass.MissingMethodExceptionNoStack: No signature of method: c.main()
// is applicable for argument types: ([Ljava.lang.String;) values: [[]]
// WOULD BE NICE IF WE DIDN'T HAVE TO DO THAT
engine.eval("class c { static def isVadas(v){v.name=='vadas'}};null;", bindings);
// make sure the class works on its own...this generates: groovy.lang.MissingPropertyException: No such property: c for class: Script2
assertEquals(true, engine.eval("c.isVadas(g.v(2))", bindings));
}
use of javax.script.ScriptException in project gremlin by tinkerpop.
the class GremlinGroovyScriptEngineTest method testThreadSafetyOnEngine.
public void testThreadSafetyOnEngine() throws Exception {
final ScriptEngine engine = new GremlinGroovyScriptEngine(10);
int runs = 500;
final CountDownLatch latch = new CountDownLatch(runs);
final List<String> names = Arrays.asList("marko", "peter", "josh", "vadas", "stephen", "pavel", "matthias");
final Random random = new Random();
for (int i = 0; i < runs; i++) {
new Thread() {
public void run() {
String name = names.get(random.nextInt(names.size() - 1));
try {
final Bindings bindings = engine.createBindings();
bindings.put("g", TinkerGraphFactory.createTinkerGraph());
bindings.put("name", name);
final Object result = engine.eval("pipe = g.V('name',name); if(pipe.hasNext()) { pipe.out.count() } else { null }", bindings);
if (name.equals("stephen") || name.equals("pavel") || name.equals("matthias"))
assertNull(result);
else
assertNotNull(result);
} catch (ScriptException e) {
//System.out.println(e);
assertFalse(true);
}
latch.countDown();
}
}.start();
}
latch.await();
}
use of javax.script.ScriptException in project gremlin by tinkerpop.
the class GremlinGroovyScriptEngine method readFully.
private String readFully(final Reader reader) throws ScriptException {
char[] arr = new char[8192];
StringBuilder buf = new StringBuilder();
int numChars;
try {
while ((numChars = reader.read(arr, 0, arr.length)) > 0) {
buf.append(arr, 0, numChars);
}
} catch (IOException exp) {
throw new ScriptException(exp);
}
return buf.toString();
}
Aggregations