INT-3162 Fix AbstractScriptExecutor Thread-Safety

JIRA: https://jira.springsource.org/browse/INT-3162
This commit is contained in:
Artem Bilan
2013-10-02 20:09:33 +03:00
committed by Gary Russell
parent a7a722a59e
commit 7b2ba3e0a3
3 changed files with 68 additions and 15 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
@@ -14,13 +14,14 @@ package org.springframework.integration.scripting.jsr223;
import java.util.Date;
import java.util.Map;
import java.util.Map.Entry;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.SimpleBindings;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.integration.scripting.ScriptExecutor;
import org.springframework.integration.scripting.ScriptingException;
import org.springframework.scripting.ScriptSource;
@@ -31,6 +32,7 @@ import org.springframework.util.Assert;
*
* @author David Turanski
* @author Mark Fisher
* @author Artem Bilan
* @since 2.1
*/
abstract class AbstractScriptExecutor implements ScriptExecutor {
@@ -66,18 +68,18 @@ abstract class AbstractScriptExecutor implements ScriptExecutor {
Object result = null;
try {
if (variables != null) {
for (Entry<String, Object> entry : variables.entrySet()) {
scriptEngine.put(entry.getKey(), entry.getValue());
}
}
String script = scriptSource.getScriptAsString();
Date start = new Date();
if (logger.isDebugEnabled()) {
logger.debug("executing script: " + script);
}
result = scriptEngine.eval(script);
if (variables != null) {
result = scriptEngine.eval(script, new SimpleBindings(variables));
}
else {
result = scriptEngine.eval(script);
}
result = postProcess(result, scriptEngine, script);