use of org.springframework.integration.scripting.RefreshableResourceScriptSource in project spring-integration by spring-projects.
the class DslScriptExecutingMessageProcessor method afterPropertiesSet.
@Override
public void afterPropertiesSet() throws Exception {
if (StringUtils.hasText(this.location)) {
this.script = this.applicationContext.getResource(this.location);
}
ScriptSource scriptSource = new RefreshableResourceScriptSource(this.script, this.refreshCheckDelay);
if (!StringUtils.hasText(this.lang)) {
String filename = this.script.getFilename();
int index = filename.lastIndexOf(".") + 1;
if (index < 1) {
throw new BeanCreationException("'lang' isn't provided and there is 'file extension' for script " + "resource: " + this.script);
}
this.lang = filename.substring(index);
}
if (this.applicationContext.containsBean(ScriptExecutingProcessorFactory.BEAN_NAME)) {
ScriptExecutingProcessorFactory processorFactory = this.applicationContext.getBean(ScriptExecutingProcessorFactory.BEAN_NAME, ScriptExecutingProcessorFactory.class);
this.delegate = processorFactory.createMessageProcessor(this.lang, scriptSource, this.variableGenerator);
} else {
this.delegate = new ScriptExecutingMessageProcessor(scriptSource, this.variableGenerator, ScriptExecutorFactory.getScriptExecutor(this.lang));
}
this.delegate.setBeanFactory(this.applicationContext);
this.delegate.setBeanClassLoader(this.applicationContext.getClassLoader());
}
use of org.springframework.integration.scripting.RefreshableResourceScriptSource in project spring-integration by spring-projects.
the class GroovyScriptExecutingMessageProcessorTests method testRefreshableScriptExecutionWithAlwaysRefresh.
@Test
public void testRefreshableScriptExecutionWithAlwaysRefresh() throws Exception {
String script = "return \"payload is $payload, header is $headers.testHeader\"";
Message<?> message = MessageBuilder.withPayload("foo").setHeader("testHeader", "bar").build();
TestResource resource = new TestResource(script, "simpleTest");
ScriptSource scriptSource = new RefreshableResourceScriptSource(resource, 0);
MessageProcessor<Object> processor = new GroovyScriptExecutingMessageProcessor(scriptSource);
// process with the first script
Object result = processor.processMessage(message);
assertEquals("payload is foo, header is bar", result.toString());
// change script, but since refresh-delay is less then 0 we should still se old script executing
resource.setScript("return \"payload is $payload\"");
// process and see assert that the old script is used
result = processor.processMessage(message);
assertEquals("payload is foo", result.toString());
resource.setScript("return \"payload is 'hello'\"");
// process and see assert that the old script is used
result = processor.processMessage(message);
assertEquals("payload is 'hello'", result.toString());
}
use of org.springframework.integration.scripting.RefreshableResourceScriptSource in project spring-integration by spring-projects.
the class RefreshableResourceScriptSourceTests method testIsModifiedInfiniteDelay.
@Test
public void testIsModifiedInfiniteDelay() throws Exception {
RefreshableResourceScriptSource source = new RefreshableResourceScriptSource(new ByteArrayResource("foo".getBytes()) {
@Override
public long lastModified() throws IOException {
return System.currentTimeMillis();
}
}, -1);
assertEquals(false, source.isModified());
assertEquals("foo", source.getScriptAsString());
}
use of org.springframework.integration.scripting.RefreshableResourceScriptSource in project spring-integration by spring-projects.
the class RefreshableResourceScriptSourceTests method testGetScriptAsString.
@Test
public void testGetScriptAsString() throws Exception {
RefreshableResourceScriptSource source = new RefreshableResourceScriptSource(new ByteArrayResource("foo".getBytes()), 1000);
assertEquals("foo", source.getScriptAsString());
}
use of org.springframework.integration.scripting.RefreshableResourceScriptSource in project spring-integration by spring-projects.
the class RefreshableResourceScriptSourceTests method testIsModifiedZeroDelay.
@Test
public void testIsModifiedZeroDelay() throws Exception {
RefreshableResourceScriptSource source = new RefreshableResourceScriptSource(new ByteArrayResource("foo".getBytes()) {
@Override
public long lastModified() throws IOException {
return System.currentTimeMillis();
}
}, 0);
Thread.sleep(100L);
assertEquals(true, source.isModified());
assertEquals("foo", source.getScriptAsString());
}
Aggregations