示例#1
0
 public boolean containsKey(Object key) {
   for (Resolver scriptResolver : scriptResolvers) {
     if (scriptResolver.containsKey(key)) {
       return true;
     }
   }
   return defaultBindings.containsKey(key);
 }
示例#2
0
  @Override
  public void handleAction(
      final Context context, final ActionRequest request, final Bindings handler)
      throws ResourceException {
    super.handleAction(context, request, handler);
    for (Map.Entry<String, String> entry : request.getAdditionalParameters().entrySet()) {
      if (handler.containsKey(entry.getKey())) {
        continue;
      }
      if (bindings != null) {
        bindings.put(entry.getKey(), entry.getValue());
      }
    }

    handler.put("request", request);
    handler.put("resources", configuration.get("resources").copy().getObject());
  }
示例#3
0
  @SuppressWarnings("rawtypes")
  // the caller is responsible for setting the task environment
  @Override
  protected Object evaluate(final ScriptEngine scriptEngine, final String script) {

    LOGGER.debug("evaluate called for {}", script);

    // Bindings bindings = new CustomEnvironmentBindings();
    // we can add any custom binding here if we override the EnvironmentBindings
    final Bindings bindings = new EnvironmentBindings(readContextNames, writeContextName);
    scriptEngine.setBindings(bindings, ScriptContext.ENGINE_SCOPE);

    if (!bindings.containsKey("task")) {
      LOGGER.warn("calling a script and no task in context, the script is [{}]", script);
    } else {
      LOGGER.info("got a task in the context >{}<", bindings.get("task"));
    }

    try {
      // we get a nullpointer exception if we have a comments only script, try to prevent this
      // by checking for a nullpointer clazz before calling eval on tne script engine:
      Class clazz = new GroovyClassLoader().parseClass(script);
      if (clazz == null) {
        LOGGER.debug("script parsed to null");
        return null;
      } else {
        final Object result = scriptEngine.eval(script);
        LOGGER.debug("script evaluated to {}", result);
        return result;
      }
    } catch (final Exception ex) {
      LOGGER.warn(
          "script error in script, the error is: {}, the script is: [{}], throwing error ",
          ex.getMessage(),
          script);
      throw new JbpmException("script evaluation error: " + ex.getMessage(), ex);
    }
  }