Search in sources :

Example 1 with ScriptingException

use of org.springframework.integration.scripting.ScriptingException in project spring-integration by spring-projects.

the class AbstractScriptExecutor method executeScript.

@Override
public Object executeScript(ScriptSource scriptSource, Map<String, Object> variables) {
    Object result;
    try {
        String script = scriptSource.getScriptAsString();
        Date start = new Date();
        if (this.logger.isDebugEnabled()) {
            this.logger.debug("executing script: " + script);
        }
        Bindings bindings = null;
        if (variables != null && variables.size() > 0) {
            bindings = new SimpleBindings(variables);
            result = this.scriptEngine.eval(script, bindings);
        } else {
            result = this.scriptEngine.eval(script);
        }
        result = postProcess(result, this.scriptEngine, script, bindings);
        if (this.logger.isDebugEnabled()) {
            this.logger.debug("script executed in " + (new Date().getTime() - start.getTime()) + " ms");
        }
    } catch (Exception e) {
        throw new ScriptingException(e.getMessage(), e);
    }
    return result;
}
Also used : SimpleBindings(javax.script.SimpleBindings) SimpleBindings(javax.script.SimpleBindings) Bindings(javax.script.Bindings) Date(java.util.Date) ScriptingException(org.springframework.integration.scripting.ScriptingException) ScriptingException(org.springframework.integration.scripting.ScriptingException)

Aggregations

Date (java.util.Date)1 Bindings (javax.script.Bindings)1 SimpleBindings (javax.script.SimpleBindings)1 ScriptingException (org.springframework.integration.scripting.ScriptingException)1