Java Code Examples for javax.script.ScriptException#toString()

The following examples show how to use javax.script.ScriptException#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractScriptingProcessor.java    From datacollector with Apache License 2.0 6 votes vote down vote up
private void runScript(List<ScriptRecord> records, ScriptingProcessorOutput out) throws StageException {
  try {
    runScript(createProcessBindings(records, out));
  } catch (ScriptException ex) {
    switch (processingMode) {
      case RECORD:
        errorRecordHandler.onError(
            new OnRecordErrorException(
                getScriptObjectFactory().getRecord(records.get(0)),
                Errors.SCRIPTING_05,
                ex.toString(),
                ex
            )
        );
        break;
      case BATCH:
        throw new StageException(Errors.SCRIPTING_06, ex.toString(), ex);
      default:
        throw new IllegalStateException(
            Utils.format("Unknown OnError value '{}'", getContext().getOnErrorRecord(), ex)
        );
    }
  }
}
 
Example 2
Source File: ScriptCommand.java    From ClientBase with MIT License 5 votes vote down vote up
@Override
public void run(String alias, String[] args) {
    if (args.length < 1) {
        throw new CommandException("Usage: ." + alias + " <new/eval> [<script>]");
    }
    if (args[0].equalsIgnoreCase("new")) {
        ClientBase.INSTANCE.scriptManager.newScript();
        ChatUtils.send("New script created.");
    }
    if (args.length >= 2 && args[0].equalsIgnoreCase("eval")) {
        StringBuilder builder = new StringBuilder();

        for (int i = 1; i < args.length; i++) {
            builder.append(args[i]);

            if (i != args.length - 1) {
                builder.append(" ");
            }
        }

        try {
            ChatUtils.info("Result: " + ClientBase.INSTANCE.scriptManager.eval(builder.toString()));
        } catch (ScriptException e) {
            throw new CommandException(e.toString());
        }
    }
}
 
Example 3
Source File: AbstractScriptingSource.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@Override
public void produce(Map<String, String> lastOffsets, int maxBatchSize) throws StageException {
  try {
    runScript(createBindings(lastOffsets, maxBatchSize));
  } catch (ScriptException e) {
    throw new StageException(Errors.SCRIPTING_10, e.toString());
  }
}