List of usage examples for javax.script ScriptException getMessage
public String getMessage()
From source file:utybo.branchingstorytree.swing.impl.XSFClient.java
@Override public Object invokeScript(String resourceName, String function, XSFBridge bst, BranchingStory story, int line) throws BSTException { ScriptEngine scriptEngine = new ScriptEngineManager().getEngineByName("JavaScript"); SimpleBindings binds = new SimpleBindings(); binds.putAll(story.getRegistry().getAllInt()); binds.putAll(story.getRegistry().getAllString()); binds.put("bst", bst); scriptEngine.setBindings(binds, ScriptContext.ENGINE_SCOPE); try {/*from ww w. ja va 2 s . c o m*/ scriptEngine.eval(scripts.get(resourceName)); return scriptEngine.eval(function + "()"); } catch (ScriptException e) { throw new BSTException(line, "Script exception : " + e.getMessage(), story); } }
From source file:com.intuit.tank.tools.script.ScriptRunner.java
/** * //from w w w. jav a 2s .c o m * @param scriptName * @param script * @param engine * @param inputs * @param output * @return * @throws ScriptException */ public ScriptIOBean runScript(@Nullable String scriptName, @Nonnull String script, @Nonnull ScriptEngine engine, @Nonnull Map<String, Object> inputs, OutputLogger output) throws ScriptException { Reader reader = null; ScriptIOBean ioBean = null; try { reader = new StringReader(script); ioBean = new ScriptIOBean(inputs, output); engine.put("ioBean", ioBean); ioBean.println("Starting test..."); engine.eval(reader, engine.getContext()); ioBean.println("Finished test..."); } catch (ScriptException e) { throw new ScriptException(e.getMessage(), scriptName, e.getLineNumber(), e.getColumnNumber()); } finally { IOUtils.closeQuietly(reader); } return ioBean; }
From source file:org.rhq.scripting.python.PythonScriptEngineInitializer.java
@Override public String extractUserFriendlyErrorMessage(ScriptException e) { return e.getMessage(); }
From source file:gridgrid.Web.java
@RequestMapping(value = "/*", produces = MediaType.TEXT_HTML_VALUE) public String get(Model model, HttpServletRequest request) throws IOException { File file = new File("./hogan.xlsx"); load(file);/*from ww w . j ava2s.co m*/ CodeView codeView = map.get(request.getRequestURI()); try { codeView.runCode(); return codeView.getView(); } catch (ScriptException e) { return e.getMessage(); } }
From source file:com.asual.lesscss.compiler.NashornCompiler.java
public NashornCompiler(LessOptions options, ResourceLoader loader, URL less, URL env, URL engine, URL cssmin, URL sourceMap) throws IOException { ScriptEngineManager factory = new ScriptEngineManager(); ScriptEngine scriptEngine = factory.getEngineByName("nashorn"); try {/*from w w w.j ava 2 s. com*/ scriptEngine.eval(new InputStreamReader(sourceMap.openConnection().getInputStream())); scriptEngine.eval(new InputStreamReader(env.openConnection().getInputStream())); ScriptObjectMirror lessenv = (ScriptObjectMirror) scriptEngine.get("lessenv"); lessenv.put("charset", options.getCharset()); lessenv.put("css", options.isCss()); lessenv.put("lineNumbers", options.getLineNumbers()); lessenv.put("optimization", options.getOptimization()); lessenv.put("sourceMap", options.isSourceMap()); lessenv.put("sourceMapRootpath", options.getSourceMapRootpath()); lessenv.put("sourceMapBasepath", options.getSourceMapBasepath()); lessenv.put("sourceMapURL", options.getSourceMapUrl()); lessenv.put("loader", loader); lessenv.put("paths", options.getPaths()); scriptEngine.eval(new InputStreamReader(less.openConnection().getInputStream())); scriptEngine.eval(new InputStreamReader(cssmin.openConnection().getInputStream())); scriptEngine.eval(new InputStreamReader(engine.openConnection().getInputStream())); compile = (ScriptObjectMirror) scriptEngine.get("compile"); } catch (ScriptException e) { logger.error(e.getMessage(), e); } }
From source file:org.jahia.services.content.nodetypes.initializers.ScriptChoiceListInitializerImpl.java
public List<ChoiceListValue> getChoiceListValues(ExtendedPropertyDefinition epd, String param, List<ChoiceListValue> values, Locale locale, Map<String, Object> context) { if (param != null) { final String extension = Patterns.DOT.split(param)[1]; ScriptEngine byName;// w w w . ja v a 2 s .co m try { byName = scriptEngineUtils.scriptEngine(extension); } catch (ScriptException e) { logger.error(e.getMessage(), e); byName = null; } if (byName != null) { final Set<JahiaTemplatesPackage> forModule = ServicesRegistry.getInstance() .getJahiaTemplateManagerService().getModulesWithViewsForComponent( JCRContentUtils.replaceColon(epd.getDeclaringNodeType().getName())); final Bindings bindings = byName.getBindings(ScriptContext.ENGINE_SCOPE); bindings.put("values", values); for (JahiaTemplatesPackage template : forModule) { final Resource scriptPath = template .getResource(File.separator + "scripts" + File.separator + param); if (scriptPath != null && scriptPath.exists()) { Reader scriptContent = null; try { scriptContent = new InputStreamReader(scriptPath.getInputStream()); return (List<ChoiceListValue>) byName.eval(scriptContent, bindings); } catch (ScriptException e) { logger.error("Error while executing script " + scriptPath, e); } catch (IOException e) { logger.error(e.getMessage(), e); } finally { if (scriptContent != null) { IOUtils.closeQuietly(scriptContent); } } } } } } return Collections.emptyList(); }
From source file:de.pixida.logtest.engine.EmbeddedScript.java
private Object runAndGetResult() { LOG.trace("Running external script"); if (this.compiledScript == null) { if (this.exists()) { throw new RuntimeException("Trying to use script which was not yet compiled"); } else {//www . j a va 2 s . c om return null; } } Object result; try { result = this.compiledScript.eval(); } catch (final ScriptException se) { throw new ExecutionException("Error during script execution.\n" + se.getMessage()); } LOG.trace("External script finished with result: {}", result); return result; }
From source file:org.trafodion.rest.script.ScriptManager.java
public void runScript(ScriptContext ctx) { String scriptName;/* w w w .j a v a 2 s. c o m*/ if (ctx.getScriptName().length() == 0) scriptName = DEFAULT_SCRIPT_NAME; else if (!ctx.getScriptName().endsWith(".py")) scriptName = ctx.getScriptName() + PYTHON_SUFFIX; else scriptName = ctx.getScriptName(); try { ScriptEngine engine = manager.getEngineByName("python"); Bindings bindings = engine.createBindings(); bindings.put("scriptcontext", ctx); if (engine instanceof Compilable) { CompiledScript script = m.get(scriptName); if (script == null) { LOG.info("Compiling script " + scriptName); Compilable compilingEngine = (Compilable) engine; try { script = compilingEngine.compile(new FileReader(restHome + "/bin/scripts/" + scriptName)); } catch (Exception e) { LOG.warn(e.getMessage()); } m.put(scriptName, script); } script.eval(bindings); } else { try { engine.eval(new FileReader(restHome + "/bin/scripts/" + scriptName), bindings); } catch (Exception e) { LOG.warn(e.getMessage()); } } } catch (javax.script.ScriptException se) { LOG.warn(se.getMessage()); } }
From source file:de.perdoctus.synology.jdadapter.controller.JdAdapter.java
public void handleClassicRequest(final String jk, final String crypted, final HttpServletResponse resp) throws IOException { LOG.debug("Configuration: " + drClient.toString()); try {//w w w.jav a2 s.c o m final String key = extractKey(jk); final List<URI> targets = Decrypter.decryptDownloadUri(crypted, key); final List<URI> fixedTargets = fixURIs(targets); LOG.debug("Sending download URLs to Synology NAS. Number of URIs: " + targets.size()); for (URI target : fixedTargets) { drClient.addDownloadUrl(target); } resp.setStatus(HttpServletResponse.SC_OK); analyticsTracker.trackEvent(ANALYTICS_EVENT_CATEGORY, "Classic Request", "added targets", targets.size()); } catch (ScriptException ex) { LOG.error(ex.getMessage(), ex); resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Failed to evaluate script:\n" + ex.getMessage()); } catch (SynoException ex) { LOG.error(ex.getMessage(), ex); if (ex instanceof LoginException) { resp.sendError(HttpServletResponse.SC_UNAUTHORIZED, ex.getMessage()); } else { resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex.getMessage()); } } catch (URISyntaxException ex) { LOG.error("Decrypted URL seems to be corrupt.", ex); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex.getMessage()); } }
From source file:org.apache.tinkerpop.gremlin.python.jsr223.PythonProvider.java
@Override public GraphTraversalSource traversal(final Graph graph) { if ((Boolean) graph.configuration().getProperty("skipTest")) return graph.traversal(); //throw new VerificationException("This test current does not work with Gremlin-Python", EmptyTraversal.instance()); else {// w ww .ja v a2 s. c o m try { ScriptEngineCache.get("jython").eval( IMPORT_STATICS ? "statics.load_statics(globals())" : "statics.unload_statics(globals())"); } catch (final ScriptException e) { throw new IllegalStateException(e.getMessage(), e); } final GraphTraversalSource g = graph.traversal(); return g.withStrategies(new TranslationStrategy(g, new PythonGraphSONJavaTranslator<>( PythonTranslator.of("g", IMPORT_STATICS), JavaTranslator.of(g)))); } }