Merge remote-tracking branch 'upstream/master' into 4.0.0-WIP
Conflicts: spring-integration-core/src/main/java/org/springframework/integration/handler/ExpressionEvaluatingMessageHandler.java spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyServiceActivatorTests.java Resolve.
This commit is contained in:
@@ -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.
|
||||
@@ -24,6 +24,10 @@ import org.springframework.messaging.Message;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
* A default {@link ScriptVariableGenerator} implementation; used by script processors.
|
||||
* The result of {@link #generateScriptVariables(Message)} is a {@link Map} of any provided {@code variables}
|
||||
* plus {@code payload} and {@code headers} from the {@code Message} argument.
|
||||
*
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Mark Fisher
|
||||
* @since 2.0.2
|
||||
@@ -53,7 +57,7 @@ public class DefaultScriptVariableGenerator implements ScriptVariableGenerator {
|
||||
if (!CollectionUtils.isEmpty(this.variableMap)) {
|
||||
for (Map.Entry<String, Object> entry : this.variableMap.entrySet()) {
|
||||
scriptVariables.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
return scriptVariables;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 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.
|
||||
@@ -26,6 +26,7 @@ import org.springframework.scripting.support.ResourceScriptSource;
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Artem Bilan
|
||||
* @since 2.0
|
||||
*/
|
||||
public class RefreshableResourceScriptSource implements ScriptSource {
|
||||
@@ -51,7 +52,10 @@ public class RefreshableResourceScriptSource implements ScriptSource {
|
||||
}
|
||||
|
||||
public String getScriptAsString() throws IOException {
|
||||
this.script = source.getScriptAsString();
|
||||
if (this.script == null || this.isModified()) {
|
||||
this.lastModifiedChecked.set(System.currentTimeMillis());
|
||||
this.script = source.getScriptAsString();
|
||||
}
|
||||
return this.script;
|
||||
}
|
||||
|
||||
@@ -60,15 +64,14 @@ public class RefreshableResourceScriptSource implements ScriptSource {
|
||||
}
|
||||
|
||||
public boolean isModified() {
|
||||
if (this.refreshDelay < 0) {
|
||||
return false;
|
||||
}
|
||||
long time = System.currentTimeMillis();
|
||||
if (this.refreshDelay == 0 || (time - this.lastModifiedChecked.get()) > this.refreshDelay) {
|
||||
this.lastModifiedChecked.set(time);
|
||||
return this.source.isModified();
|
||||
}
|
||||
return false;
|
||||
return this.refreshDelay >= 0 &&
|
||||
(System.currentTimeMillis() - this.lastModifiedChecked.get()) > this.refreshDelay &&
|
||||
this.source.isModified();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.source.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -21,6 +21,9 @@ import java.util.Map;
|
||||
import org.springframework.messaging.Message;
|
||||
|
||||
/**
|
||||
* Strategy interface to provide a {@link Map} of variables to the script execution context.
|
||||
* Variables may be extracted from the {@link Message} argument.
|
||||
*
|
||||
* @author Oleg Zhurakousky
|
||||
* @since 2.0.2
|
||||
*/
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
@@ -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;
|
||||
@@ -28,9 +29,10 @@ import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Base Class for {@link ScriptExecutor}
|
||||
*
|
||||
*
|
||||
* @author David Turanski
|
||||
* @author Mark Fisher
|
||||
* @author Artem Bilan
|
||||
* @since 2.1
|
||||
*/
|
||||
abstract class AbstractScriptExecutor implements ScriptExecutor {
|
||||
@@ -44,9 +46,9 @@ abstract class AbstractScriptExecutor implements ScriptExecutor {
|
||||
public AbstractScriptExecutor(String language) {
|
||||
Assert.hasText(language, "language must not be empty");
|
||||
this.language = language;
|
||||
|
||||
|
||||
scriptEngine = new ScriptEngineManager().getEngineByName(this.language);
|
||||
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
|
||||
if (scriptEngine == null) {
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user