+ Const.CR + jse.toString(); cr = new CheckResult( CheckResultInterface.TYPE_RESULT_ERROR, error_message, stepMeta ); remarks.add( cr );
@Override public String processLine(String line) { try { mWriter.getBuffer().setLength(0); mScriptEngine.eval(line, mScriptContext); mWriter.flush(); if (mWriter.getBuffer().length() != 0) return mWriter.toString(); else return ""; } catch (ScriptException e) { return e.toString(); } }
/** * Uses the user provided query to process and return a JSON columnar format of the data. * * @param data The data from the REST call. * @param function The function name to invoke. * @param query The Query object being run. * @return The String JSON response of the call, null if exception (query is failed). */ String convertToColumnarJSON(String data, String function, Query query) { try { log.info("Evaluating query using Javascript function: {}\n{}", function, query.value); evaluator.eval(query.value); Invocable invocable = (Invocable) evaluator; String columnarJSON = (String) invocable.invokeFunction(function, data); log.info("Processed response using query into JSON: {}", columnarJSON); return columnarJSON; } catch (ScriptException se) { log.error("Exception while processing input Javascript", se); query.setFailure(se.toString()); query.addMessage(se.toString()); } catch (NoSuchMethodException nsme) { log.error("Method {} not found in {}\n{}", function, query.value, nsme); query.setFailure(nsme.toString()); } return null; }
final String excMessage = e.toString(); final int pos = excMessage.indexOf("<Unknown Source>#"); if (pos > -1) {
@Override public Collection<Record> process(ProcessContext context, Collection<Record> records) { // check if we need initialization if (datastoreClientService == null) { init(context); } List<Record> outputRecords = new ArrayList<>(records); for (final Map.Entry<String, String> entry : dynamicTagValuesMap.entrySet()) { try { sandbox.eval(entry.getValue()); Record cached = (Record) sandbox.get("record_" + entry.getKey()); if (cached.hasField(FieldDictionary.RECORD_VALUE)) outputRecords.add(cached); } catch (ScriptException e) { Record errorRecord = new StandardRecord(RecordDictionary.ERROR) .setId(entry.getKey()) .addError("ScriptException", e.getMessage()); // outputRecords.add(errorRecord); logger.error(e.toString()); } } return outputRecords; } }
/** * Converts the String columnar JSON data into a Map of column names to List of column values. Internal use only. * * @param columnarData The String columnar JSON data. * @param query The Query object being run. * @return The Map version of the JSON data, null if exception (query is failed). */ Map<String, List<TypedObject>> convertToMap(String columnarData, Query query) { try { log.info("Converting processed JSON into a map..."); // Type erasure will make this not enough if the JSON parses into a map but with the wrong keys, values. Map<String, List<Object>> result = (Map<String, List<Object>>) evaluator.eval(String.format(JSON_TO_MAP_FORMAT, columnarData)); // But this will catch it. Map<String, List<TypedObject>> typed = type(result); log.info("Conversion complete!"); return typed; } catch (ScriptException se) { log.error("Could not convert the processed JSON to the required format", se); query.setFailure("Invalid JSON (try a linter): " + columnarData); query.addMessage(se.toString()); } catch (ClassCastException cce) { log.error("The returned JSON is not in the map of columns format", cce); query.setFailure("Your extracted JSON is not in a map of columns format: " + columnarData); query.addMessage(cce.toString()); } return null; }
engine.eval(is); } catch (ScriptException x) { throw (IOException) new IOException(x.toString()).initCause(x); } finally { is.close();
.addError("ScriptException", e.getMessage()); logger.error(e.toString());
( params.containsKey("dstBean") && ((IBean)params.get("dstBean")).getMainIdentifier() != null ? "id=" + ((IBean)params.get("dstBean")).getMainIdentifier() : "unknown id !")) + "\nReason: " + e.toString()); LOGGER.debug(e.toString(), e); throw new LscServiceException (e); } catch (RuntimeException e) {
} catch (Exception ignored) { String errorDesc = "Script error while running scenario:" + e.toString() + ", script content is at " + diagname; e.printStackTrace(); logger.error(errorDesc, e);
LOGGER.error("Error in script scripts/command/" + event.getScript() + ": " + e.toString()); e.printStackTrace();
.addError("ScriptException", e.getMessage()); logger.error(e.toString());