List of usage examples for javax.script ScriptException getMessage
public String getMessage()
From source file:org.jahia.services.workflow.jbpm.JBPMMailProducer.java
protected void fillRecipients(Message email, Execution execution, JCRSessionWrapper session) throws MessagingException { try {//from w w w.j av a2 s . c o m // to AddressTemplate to = getTemplate().getTo(); if (to != null) { fillRecipients(to, email, Message.RecipientType.TO, execution, session); } // cc AddressTemplate cc = getTemplate().getCc(); if (cc != null) { fillRecipients(cc, email, Message.RecipientType.CC, execution, session); } // bcc AddressTemplate bcc = getTemplate().getBcc(); if (bcc != null) { fillRecipients(bcc, email, Message.RecipientType.BCC, execution, session); } } catch (ScriptException e) { logger.error(e.getMessage(), e); } catch (RepositoryException e) { logger.error(e.getMessage(), e); } }
From source file:org.jahia.services.workflow.jbpm.JBPMMailProducer.java
/** * Fills the <code>from</code> attribute of the given email. The sender addresses are an * optional element in the mail template. If absent, each mail server supplies the current * user's email address.//from w w w .j a va 2s .c om * * @see {@link InternetAddress#getLocalAddress(Session)} */ protected void fillFrom(Message email, Execution execution, JCRSessionWrapper session) throws MessagingException { try { AddressTemplate fromTemplate = getTemplate().getFrom(); // "from" attribute is optional if (fromTemplate == null) return; // resolve and parse addresses String addresses = fromTemplate.getAddresses(); if (addresses != null) { addresses = evaluateExpression(execution, addresses, session); // non-strict parsing applies to a list of mail addresses entered by a human email.addFrom(InternetAddress.parse(addresses, false)); } EnvironmentImpl environment = EnvironmentImpl.getCurrent(); IdentitySession identitySession = environment.get(IdentitySession.class); AddressResolver addressResolver = environment.get(AddressResolver.class); // resolve and tokenize users String userList = fromTemplate.getUsers(); if (userList != null) { String[] userIds = tokenizeActors(userList, execution, session); List<User> users = identitySession.findUsersById(userIds); email.addFrom(resolveAddresses(users, addressResolver)); } // resolve and tokenize groups String groupList = fromTemplate.getGroups(); if (groupList != null) { for (String groupId : tokenizeActors(groupList, execution, session)) { Group group = identitySession.findGroupById(groupId); email.addFrom(addressResolver.resolveAddresses(group)); } } } catch (ScriptException e) { logger.error(e.getMessage(), e); } catch (RepositoryException e) { logger.error(e.getMessage(), e); } }
From source file:org.graphwalker.machines.ExtendedFiniteStateMachine.java
/** * Executes an action, and returns any outcome as a string. * //w w w . j ava 2 s . c om * @param action * @return * @throws InvalidDataException is thrown if the data is not found in the data space */ public String execAction(String action) throws InvalidDataException { logger.debug("Will try to execute: " + action); Object res = null; if (jsEngine != null) { try { res = jsEngine.eval(action); } catch (ScriptException e) { throw new InvalidDataException( "The action: '" + action + "', does not evaluate correctly. Detail: " + e.getMessage()); } } else if (beanShellEngine != null) { try { res = beanShellEngine.eval(action); } catch (EvalError e) { throw new InvalidDataException( "The action: '" + action + "', does not evaluate correctly. Detail: " + e.getMessage()); } } return res.toString(); }
From source file:com.cubeia.ProtocolGeneratorMojo.java
private void generateCode(String lang, File protocolFile, File outputBaseDirectory, String packageName, boolean generateVisitors, String version, boolean failOnBadPacketOrder, String javascript_package_name) throws MojoExecutionException, MojoFailureException { if (append_language_to_output_base_dir) { outputBaseDirectory = appendLangToBaseDir(lang, outputBaseDirectory); getLog().info("Appended language '" + lang + "' to base dir, new base dir: " + outputBaseDirectory); }//w ww. ja v a 2s.c om ScriptEngineManager factory = new ScriptEngineManager(); // Create a JRuby engine. ScriptEngine engine = factory.getEngineByName("jruby"); // Evaluate JRuby code from string. InputStream scriptIn = getClass().getResourceAsStream(GENERATOR_WRAPPER_SCRIPT); if (scriptIn == null) { new MojoExecutionException( "unable to find code generator script resource: " + GENERATOR_WRAPPER_SCRIPT); } Object[] args = new Object[] { protocolFile.getPath(), lang, outputBaseDirectory.getPath(), packageName, generateVisitors ? "true" : null, version, failOnBadPacketOrder ? "true" : null, javascript_package_name }; InputStreamReader scriptReader = new InputStreamReader(scriptIn); try { engine.eval(scriptReader); Invocable invocableEngine = (Invocable) engine; invocableEngine.invokeFunction("generate_code", args); } catch (ScriptException e) { throw new MojoFailureException("code generation error: " + e.toString()); } catch (NoSuchMethodException e) { throw new MojoExecutionException("error calling code generator script: " + e.getMessage()); } }
From source file:com.intuit.tank.tools.script.ScriptFilterRunner.java
private void runScript() { String text = scriptEditorTA.getText(); if (tankScript == null) { JOptionPane.showMessageDialog(this, "You must select a Tank XML file.", "Data Needed", JOptionPane.INFORMATION_MESSAGE); } else if (StringUtils.isEmpty(text)) { JOptionPane.showMessageDialog(this, "You need to enter your script.", "Data Needed", JOptionPane.INFORMATION_MESSAGE); } else {//from w w w.j a v a 2s . c o m try { Map<String, Object> inputs = new HashMap<String, Object>(); inputs.put("script", tankScript); runner.runScript(text, ((ConfiguredLanguage) languageSelector.getSelectedItem()).getEngine(), inputs, output); } catch (ScriptException e) { output.append("Error executing script:\n"); output.append(e.getMessage() + "\n"); JOptionPane.showMessageDialog(this, e.getMessage(), "Error executing Script", JOptionPane.ERROR_MESSAGE); } } }
From source file:com.seajas.search.contender.service.modifier.FeedModifierService.java
/** * Test a given feed modifier chain by its (feed) modifier ID. * /*from ww w . jav a 2 s .c o m*/ * @param id * @param uri * @param encodingOverride * @param userAgent * @throws Exception * @return List<String, Boolean> */ public Map<String, Boolean> testModifier(Integer id, URI uri, String encodingOverride, String userAgent) throws Exception { WebResolverSettings settings = new WebResolverSettings(); settings.setMaximumContentLength(maximumContentLength); settings.setUserAgent(userAgent); Map<String, Boolean> result = new HashMap<String, Boolean>(); logger.info("Testing feed modifier with ID " + id + " and URI " + uri); try { Modifier modifier = modifierCache.getFeedModifierById(id); if (!Pattern.matches(modifier.getUrlExpression(), uri.toString())) throw new Exception("The given testing feed URI is not covered by the modifier expression"); Reader reader = getContent(uri, encodingOverride, userAgent, null); if (reader != null) { // Run it through the modifier for (ModifierFilter filter : modifier.getFilters()) { StringBuffer current = new StringBuffer(), updated = new StringBuffer(); reader = readerToBuffer(current, reader, false); reader = modifierFilterProcessor.process(filter, reader); reader = readerToBuffer(updated, reader, false); result.put("Filter_" + filter.getId(), !current.toString().equals(updated.toString())); reader.close(); } for (ModifierScript script : modifier.getScripts()) { StringBuffer current = new StringBuffer(), updated = new StringBuffer(); reader = readerToBuffer(current, reader, false); reader = modifierScriptProcessor.process(script, extractAndClose(reader), uri, settings, false); reader = readerToBuffer(updated, reader, false); result.put("Script_" + script.getId(), !current.toString().equals(updated.toString())); reader.close(); } } else throw new Exception("Could not retrieve the result feed content"); } catch (ScriptException e) { throw new Exception("Could not test the given feed: " + e.getMessage(), e); } catch (IOException e) { throw new Exception("Could not test the given feed: " + e.getMessage(), e); } return result; }
From source file:org.forgerock.openidm.servlet.internal.ServletConnectionFactory.java
/** * Create a Filter from the filter configuration. * * @param config/*from w ww . j a va 2s .c o m*/ * the configuration describing a single filter. * @return a Filter * @throws org.forgerock.json.JsonValueException * TODO. */ private Filter newFilter(JsonValue config) throws JsonValueException, ScriptException { FilterCondition filterCondition = null; final Pair<JsonPointer, ScriptEntry> condition = getScript(config.get("condition")); final Pair<JsonPointer, ScriptEntry> onRequest = getScript(config.get("onRequest")); final Pair<JsonPointer, ScriptEntry> onResponse = getScript(config.get("onResponse")); final Pair<JsonPointer, ScriptEntry> onFailure = getScript(config.get("onFailure")); // Require at least one of the following if (null == onRequest && null == onResponse && null == onFailure) { return null; } // Check for condition on pattern Pattern pattern = config.get("pattern").asPattern(); if (null != pattern) { filterCondition = Filters.matchResourcePath(pattern); } // Check for condition on type final EnumSet<RequestType> requestTypes = EnumSet.noneOf(RequestType.class); for (JsonValue method : config.get("methods").expect(List.class)) { requestTypes.add(method.asEnum(RequestType.class)); } if (!requestTypes.isEmpty()) { filterCondition = (null == filterCondition) ? Filters.matchRequestType(requestTypes) : Filters.and(filterCondition, Filters.matchRequestType(requestTypes)); } // Create the filter Filter filter = (null == filterCondition) ? new ScriptedFilter(onRequest, onResponse, onFailure) : Filters.conditionalFilter(filterCondition, new ScriptedFilter(onRequest, onResponse, onFailure)); // Check for a condition script if (null != condition) { FilterCondition conditionFilterCondition = new FilterCondition() { @Override public boolean matches(final Context context, final Request request) { try { final Script script = condition.getValue().getScript(context); script.put("request", request); script.put("context", context); return (Boolean) script.eval(); } catch (ScriptException e) { logger.warn("Failed to evaluate filter condition: ", e.getMessage(), e); } return false; } }; filter = Filters.conditionalFilter(conditionFilterCondition, filter); } return filter; }
From source file:org.openadaptor.auxil.processor.script.ScriptProcessor.java
/** * Initialise the script engine.//from www . java2 s . co m * <br> * This will create a script engine, and compile the supplied * script is compilation is possible, and enabled. * @throws ValidationException */ private void initialise() throws ValidationException { log.info("Initialising script engine for language: " + language); log.debug("Compile flag: " + compile); scriptEngine = createScriptEngine(); if (compile && scriptEngine instanceof Compilable) { Compilable compilableScriptEngine = (Compilable) scriptEngine; try { if (script != null) { log.debug("Compiling script: " + script); compiledScript = compilableScriptEngine.compile(script); } else { log.debug("Compiling script from file: " + scriptFilename); compiledScript = compilableScriptEngine.compile(new FileReader(scriptFilename)); } log.info("Script compiled successfully"); } catch (ScriptException e) { String failMsg = "Failed to compile script, " + e.getMessage() + " line " + e.getLineNumber() + " col " + e.getColumnNumber(); log.warn(failMsg); throw new ValidationException(failMsg, e, this); } catch (FileNotFoundException e) { String failMsg = "Failed to compile script, " + e.getMessage(); log.warn(failMsg); throw new ValidationException(failMsg, e, this); } } //Apply binding to allow scripts to access logging scriptEngine.put(logBinding, log); //Apply extra bindings, if any. applyBindings(scriptEngine, additionalBindings); }
From source file:org.openadaptor.auxil.processor.script.ScriptProcessor.java
/** * Process a data item.//from w ww .j a v a2 s . c om * It will bind the data using the configured databinding, to * make it available to the script. * * The bound object will be returned in a single Element Object[] * <br> * Note: If compilation is not possible, and the script is contained in a * file, then the file will be read each time a datum is being processed. This * should be avoided for obvious reasons :-) */ protected Object[] doProcess(Object data) { if (data == null) { //conform to IDataProcessor contract. throw new NullRecordException("Null record not permitted"); } //Clone it if possible. //data=ReflectionUtils.clone(data); data = cloner.clone(data); try { scriptEngine.put(metadataBinding, metadata); scriptEngine.put(dataBinding, data); if (compiledScript != null) { lastResult = compiledScript.eval(); } else { if (script != null) { lastResult = scriptEngine.eval(script); } else { lastResult = scriptEngine.eval(new FileReader(scriptFilename)); } } data = scriptEngine.get(dataBinding); if (data == null) { data = new Object[] {}; } else { if (boxReturnedArrays || (!(data instanceof Object[]))) { data = new Object[] { data }; //Wrap it in an Object array. } } return (Object[]) data; } catch (ScriptException e) { log.debug("Script cause: " + e.getCause()); throw new ProcessingException("failed to execute script, " + e.getMessage() + " line " + e.getLineNumber() + " col " + e.getColumnNumber(), e, this); } catch (FileNotFoundException e) { throw new ConnectionException("failed to load script file, " + e.getMessage() + scriptFilename, e, this); } }