INT-3976: Remove an explicit scriptClassName

JIRA: https://jira.spring.io/browse/INT-3976

The class name in case of `StaticScriptSource` (for inline scripts) is required only for Groovy native engine.
Even if `GroovyScriptParser` provides an explicit `scriptClassName` option, we still can configure
`GroovyScriptExecutingMessageProcessor` with the `StaticScriptSource` from Java without the script class name.
Therefore the logic in the `GroovyScriptParser` isn't robust.

* Remove the `GroovyScriptParser` `scriptClassName` logic altogether
* Change the `GroovyScriptExecutingMessageProcessor` to rely on the Groovy native `scriptClassName` generation
in case of the `scriptSource` is provided without the class name option
* Fix the test for the actual generated script class name
This commit is contained in:
Artem Bilan
2016-03-30 17:10:10 -04:00
parent dc94b420ee
commit c97ac195a5
5 changed files with 24 additions and 52 deletions

View File

@@ -50,16 +50,11 @@ public abstract class AbstractScriptParser extends AbstractSingleBeanDefinitionP
return true;
}
@Override
protected abstract String getBeanClassName(Element element);
protected abstract String getScriptSourceClassName();
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
String scriptLocation = element.getAttribute(LOCATION_ATTRIBUTE);
String scriptText = DomUtils.getTextValue(element);
if (!(StringUtils.hasText(scriptLocation) ^ StringUtils.hasText(scriptText))) {
if (StringUtils.hasText(scriptLocation) == StringUtils.hasText(scriptText)) {
parserContext.getReaderContext().error(
"Either the 'location' attribute or inline script text must be provided, but not both.", element);
return;
@@ -80,12 +75,7 @@ public abstract class AbstractScriptParser extends AbstractSingleBeanDefinitionP
scriptLocation));
}
else {
if (getScriptSourceClassName() != null) {
builder.addConstructorArgValue(new StaticScriptSource(scriptText, getScriptSourceClassName()));
}
else {
builder.addConstructorArgValue(new StaticScriptSource(scriptText));
}
builder.addConstructorArgValue(new StaticScriptSource(scriptText));
}
BeanMetadataElement scriptVariableGeneratorDef = null;
@@ -150,7 +140,7 @@ public abstract class AbstractScriptParser extends AbstractSingleBeanDefinitionP
String variableName = childElement.getAttribute("name");
String variableValue = childElement.getAttribute("value");
String variableRef = childElement.getAttribute("ref");
if (!(StringUtils.hasText(variableValue) ^ StringUtils.hasText(variableRef))) {
if (StringUtils.hasText(variableValue) == StringUtils.hasText(variableRef)) {
parserContext.getReaderContext().error(
"Exactly one of the 'ref' attribute or 'value' attribute, " + " is required for element "
+ IntegrationNamespaceUtils.createElementDescription(element) + ".", element);

View File

@@ -24,11 +24,13 @@ import org.w3c.dom.Element;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.scripting.config.AbstractScriptParser;
import org.springframework.integration.scripting.jsr223.ScriptExecutingMessageProcessor;
import org.springframework.integration.scripting.jsr223.ScriptExecutorFactory;
import org.springframework.util.StringUtils;
/**
* @author David Turanski
* @author Artem Bilan
* @since 2.1
*/
public class ScriptParser extends AbstractScriptParser {
@@ -36,16 +38,8 @@ public class ScriptParser extends AbstractScriptParser {
private static final String LANGUAGE_ATTRIBUTE = "lang";
@Override
protected String getBeanClassName(Element element) {
return "org.springframework.integration.scripting.jsr223.ScriptExecutingMessageProcessor";
}
/* (non-Javadoc)
* @see org.springframework.integration.config.xml.AbstractScriptParser#getScriptSourceClassName()
*/
@Override
protected String getScriptSourceClassName() {
return null;
protected Class<?> getBeanClass(Element element) {
return ScriptExecutingMessageProcessor.class;
}
@Override
@@ -71,12 +65,6 @@ public class ScriptParser extends AbstractScriptParser {
builder.addConstructorArgValue(ScriptExecutorFactory.getScriptExecutor(language));
}
/**
* @param scriptLocation
* @param parserContext
* @param element
* @return the language
*/
private String getLanguageFromFileExtension(String scriptLocation, ParserContext parserContext, Element element) {
ScriptEngineManager engineManager = new ScriptEngineManager();
ScriptEngine engine = null;