List of usage examples for javax.script ScriptException getMessage
public String getMessage()
From source file:com.espertech.esper.epl.script.ExprNodeScriptEvalJSR223.java
public Object evaluate(EventBean[] eventsPerStream, boolean isNewData, ExprEvaluatorContext context) { Bindings bindings = executable.getEngine().createBindings(); bindings.put(ExprNodeScript.CONTEXT_BINDING_NAME, context.getAgentInstanceScriptContext()); for (int i = 0; i < names.length; i++) { bindings.put(names[i], parameters[i].evaluate(eventsPerStream, isNewData, context)); }//w w w .ja v a 2 s .co m try { Object result = executable.eval(bindings); if (coercer != null) { return coercer.coerceBoxed((Number) result); } return result; } catch (ScriptException e) { String message = "Unexpected exception executing script '" + scriptName + "' for statement '" + statementName + "' : " + e.getMessage(); log.error(message, e); throw new EPException(message, e); } }
From source file:org.apache.tinkerpop.gremlin.hadoop.structure.io.script.ScriptRecordReader.java
@Override public boolean nextKeyValue() throws IOException { while (true) { if (!this.lineRecordReader.nextKeyValue()) return false; try {/*w w w. ja v a 2 s. c om*/ final Bindings bindings = this.engine.createBindings(); final StarGraph graph = StarGraph.open(); final ScriptElementFactory factory = new ScriptElementFactory(graph); bindings.put(GRAPH, graph); bindings.put(LINE, this.lineRecordReader.getCurrentValue().toString()); bindings.put(FACTORY, factory); final StarGraph.StarVertex sv = (StarGraph.StarVertex) engine.eval(this.parse, bindings); if (sv != null) { final Optional<StarGraph.StarVertex> vertex = sv.applyGraphFilter(this.graphFilter); if (vertex.isPresent()) { this.vertexWritable.set(vertex.get()); return true; } } } catch (final ScriptException e) { throw new IOException(e.getMessage(), e); } } }
From source file:org.ngrinder.operation.cotroller.ScriptConsoleController.java
/** * Run the given script. The run result is stored in "result" of the given model. * * @param script script/* w w w .j a v a 2 s .co m*/ * @param model model * @return operation/script_console */ @RequestMapping("") public String run(@RequestParam(value = "script", defaultValue = "") String script, Model model) { if (StringUtils.isNotBlank(script)) { ScriptEngine engine = new ScriptEngineManager().getEngineByName("Groovy"); engine.put("applicationContext", this.applicationContext); engine.put("agentManager", this.agentManager); engine.put("agentManagerService", this.agentManagerService); engine.put("regionService", this.regionService); engine.put("consoleManager", this.consoleManager); engine.put("userService", this.userService); engine.put("perfTestService", this.perfTestService); engine.put("tagService", this.tagService); engine.put("fileEntryService", this.fileEntryService); engine.put("config", getConfig()); engine.put("pluginManager", this.pluginManager); engine.put("cacheManager", this.cacheManager); engine.put("user", getCurrentUser()); final StringWriter out = new StringWriter(); PrintWriter writer = new PrintWriter(out); engine.getContext().setWriter(writer); engine.getContext().setErrorWriter(writer); try { Object result = engine.eval(script); result = out.toString() + "\n" + ObjectUtils.defaultIfNull(result, ""); model.addAttribute("result", result); } catch (ScriptException e) { model.addAttribute("result", out.toString() + "\n" + e.getMessage()); } } model.addAttribute("script", script); return "operation/script_console"; }
From source file:org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngineCompileStaticTest.java
@Test public void shouldCompileStaticWithExtension() throws Exception { // with no type checking extension this should pass final CompileStaticCustomizerProvider providerNoExtension = new CompileStaticCustomizerProvider(); try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerNoExtension)) { assertEquals(255, scriptEngine.eval("def c = new java.awt.Color(255, 255, 255); c.red")); }// w w w . java2s . co m final CompileStaticCustomizerProvider providerWithExtension = new CompileStaticCustomizerProvider( PrecompiledExtensions.PreventColorUsageExtension.class.getName()); try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerWithExtension)) { scriptEngine.eval("def c = new java.awt.Color(255, 255, 255); c.red"); fail("Should have failed type checking"); } catch (ScriptException se) { assertEquals(MultipleCompilationErrorsException.class, se.getCause().getClass()); assertThat(se.getMessage(), containsString("Method call is not allowed!")); } }
From source file:org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngineTypeCheckedTest.java
@Test public void shouldTypeCheckWithExtension() throws Exception { // with no type checking extension this should pass final TypeCheckedCustomizerProvider providerNoExtension = new TypeCheckedCustomizerProvider(); try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerNoExtension)) { assertEquals(255, scriptEngine.eval("def c = new java.awt.Color(255, 255, 255); c.red")); }//from w w w . ja v a 2s. com final CompileStaticCustomizerProvider providerWithExtension = new CompileStaticCustomizerProvider( PrecompiledExtensions.PreventColorUsageExtension.class.getName()); try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerWithExtension)) { scriptEngine.eval("def c = new java.awt.Color(255, 255, 255); c.red"); fail("Should have failed type checking"); } catch (ScriptException se) { assertEquals(MultipleCompilationErrorsException.class, se.getCause().getClass()); assertThat(se.getMessage(), containsString("Method call is not allowed!")); } }
From source file:org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngineCompileStaticTest.java
@Test public void shouldCompileStaticWithMultipleExtension() throws Exception { // with no type checking extension this should pass final CompileStaticCustomizerProvider providerNoExtension = new CompileStaticCustomizerProvider(); try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerNoExtension)) { assertEquals(255, scriptEngine.eval("def c = new java.awt.Color(255, 255, 255); c.red")); assertEquals(1l, scriptEngine.eval("def c = new java.util.concurrent.CountDownLatch(1); c.count")); }/*from w w w. ja va 2s . co m*/ final CompileStaticCustomizerProvider providerWithExtension = new CompileStaticCustomizerProvider( PrecompiledExtensions.PreventColorUsageExtension.class.getName() + "," + PrecompiledExtensions.PreventCountDownLatchUsageExtension.class.getName()); try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerWithExtension)) { scriptEngine.eval("def c = new java.awt.Color(255, 255, 255); c.red"); fail("Should have failed type checking"); } catch (ScriptException se) { assertEquals(MultipleCompilationErrorsException.class, se.getCause().getClass()); assertThat(se.getMessage(), containsString("Method call is not allowed!")); } try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerWithExtension)) { scriptEngine.eval("def c = new java.util.concurrent.CountDownLatch(1); c.count"); fail("Should have failed type checking"); } catch (ScriptException se) { assertEquals(MultipleCompilationErrorsException.class, se.getCause().getClass()); assertThat(se.getMessage(), containsString("Method call is not allowed!")); } }
From source file:org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngineTypeCheckedTest.java
@Test public void shouldTypeCheckWithMultipleExtension() throws Exception { // with no type checking extension this should pass final TypeCheckedCustomizerProvider providerNoExtension = new TypeCheckedCustomizerProvider(); try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerNoExtension)) { assertEquals(255, scriptEngine.eval("def c = new java.awt.Color(255, 255, 255); c.red")); assertEquals(1l, scriptEngine.eval("def c = new java.util.concurrent.CountDownLatch(1); c.count")); }/*from w ww .j a v a 2s.c om*/ final TypeCheckedCustomizerProvider providerWithExtension = new TypeCheckedCustomizerProvider( PrecompiledExtensions.PreventColorUsageExtension.class.getName() + "," + PrecompiledExtensions.PreventCountDownLatchUsageExtension.class.getName()); try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerWithExtension)) { scriptEngine.eval("def c = new java.awt.Color(255, 255, 255); c.red"); fail("Should have failed type checking"); } catch (ScriptException se) { assertEquals(MultipleCompilationErrorsException.class, se.getCause().getClass()); assertThat(se.getMessage(), containsString("Method call is not allowed!")); } try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerWithExtension)) { scriptEngine.eval("def c = new java.util.concurrent.CountDownLatch(1); c.count"); fail("Should have failed type checking"); } catch (ScriptException se) { assertEquals(MultipleCompilationErrorsException.class, se.getCause().getClass()); assertThat(se.getMessage(), containsString("Method call is not allowed!")); } }
From source file:org.archive.modules.deciderules.ScriptedDecideRule.java
@Override public DecideResult innerDecide(CrawlURI uri) { // depending on previous configuration, engine may // be local to this thread or shared ScriptEngine engine = getEngine(); synchronized (engine) { // synchronization is harmless for local thread engine, // necessary for shared engine try {//from ww w . j a v a 2s .c o m engine.put("object", uri); engine.put("appCtx", appCtx); return (DecideResult) engine.eval("decisionFor(object)"); } catch (ScriptException e) { logger.log(Level.WARNING, e.getMessage(), e); return DecideResult.NONE; } finally { engine.put("object", null); engine.put("appCtx", null); } } }
From source file:org.archive.modules.ScriptedProcessor.java
@Override protected void innerProcess(CrawlURI curi) { // depending on previous configuration, engine may // be local to this thread or shared ScriptEngine engine = getEngine(); synchronized (engine) { // synchronization is harmless for local thread engine, // necessary for shared engine engine.put("curi", curi); engine.put("appCtx", appCtx); try {/*w w w . java 2s . co m*/ engine.eval("process(curi)"); } catch (ScriptException e) { logger.log(Level.WARNING, e.getMessage(), e); } finally { engine.put("curi", null); engine.put("appCtx", null); } } }
From source file:org.openscore.lang.runtime.bindings.ScriptEvaluator.java
public Serializable evalExpr(String expr, Map<String, ? extends Serializable> context) { ScriptContext scriptContext = new SimpleScriptContext(); for (Map.Entry<String, ? extends Serializable> entry : context.entrySet()) { scriptContext.setAttribute(entry.getKey(), entry.getValue(), ScriptContext.ENGINE_SCOPE); }//from w w w . j a v a 2 s .c om if (scriptContext.getAttribute(TRUE) == null) scriptContext.setAttribute(TRUE, Boolean.TRUE, ScriptContext.ENGINE_SCOPE); if (scriptContext.getAttribute(FALSE) == null) scriptContext.setAttribute(FALSE, Boolean.FALSE, ScriptContext.ENGINE_SCOPE); try { return (Serializable) engine.eval(expr, scriptContext); } catch (ScriptException e) { ScriptException scriptException = new ScriptException(e); throw new RuntimeException("Error in running script expression or variable reference, for expression: '" + expr + "', Script exception is: \n" + scriptException.getMessage(), scriptException); } }