[bs-19] Medley of changes supporting integration apps
* Use file adapters in sample instead of internal flow * Add Exception to signature of CommandLineRunner for implementation convenience * Updates for Security snapshots
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package org.springframework.bootstrap.sample.service;
|
||||
package org.springframework.bootstrap.sample.consumer;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.springframework.bootstrap.sample.service;
|
||||
package org.springframework.bootstrap.sample.consumer;
|
||||
|
||||
import org.springframework.bootstrap.SpringApplication;
|
||||
import org.springframework.bootstrap.context.annotation.EnableAutoConfiguration;
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.springframework.bootstrap.sample.consumer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.integration.annotation.MessageEndpoint;
|
||||
import org.springframework.integration.annotation.ServiceActivator;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
@MessageEndpoint
|
||||
public class SampleEndpoint {
|
||||
|
||||
@Autowired
|
||||
private HelloWorldService helloWorldService;
|
||||
|
||||
@ServiceActivator
|
||||
public String hello(File input) throws Exception {
|
||||
FileInputStream in = new FileInputStream(input);
|
||||
String name = new String(StreamUtils.copyToByteArray(in));
|
||||
in.close();
|
||||
return this.helloWorldService.getHelloMessage(name);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.bootstrap.sample.service;
|
||||
package org.springframework.bootstrap.sample.consumer;
|
||||
|
||||
import org.springframework.bootstrap.context.annotation.ConfigurationProperties;
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
package org.springframework.bootstrap.sample.service;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.integration.annotation.MessageEndpoint;
|
||||
import org.springframework.integration.annotation.ServiceActivator;
|
||||
|
||||
@MessageEndpoint
|
||||
public class SampleEndpoint {
|
||||
|
||||
@Autowired
|
||||
private HelloWorldService helloWorldService;
|
||||
|
||||
@ServiceActivator
|
||||
public Map<String, String> hello(String input) {
|
||||
return Collections.singletonMap("message",
|
||||
this.helloWorldService.getHelloMessage(input));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,10 +2,19 @@
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-file="http://www.springframework.org/schema/integration/file"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/integration/file http://www.springframework.org/schema/integration/file/spring-integration-file.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<int:channel id="input"/>
|
||||
<int:service-activator input-channel="input" ref="sampleEndpoint"/>
|
||||
<int-file:inbound-channel-adapter channel="input" directory="target/input" filename-pattern="*">
|
||||
<int:poller fixed-rate="500"/>
|
||||
</int-file:inbound-channel-adapter>
|
||||
|
||||
<int:service-activator input-channel="input" ref="sampleEndpoint" output-channel="output"/>
|
||||
|
||||
<int:channel id="output"/>
|
||||
|
||||
<int-file:outbound-channel-adapter channel="output" directory="target/output"/>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<property name="LOG_PATTERN" value="[%d{yyyy-MM-dd HH:mm:ss.SSS}] - ${PID:-????} %5p [%t] --- %c{1}: %m%n"/>
|
||||
<property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-/tmp/}spring.log}"/>
|
||||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>${LOG_PATTERN}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
<appender name="FILE"
|
||||
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<encoder>
|
||||
<pattern>${LOG_PATTERN}</pattern>
|
||||
</encoder>
|
||||
<file>${LOG_FILE}</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
|
||||
<fileNamePattern>${LOG_FILE}.%i</fileNamePattern>
|
||||
</rollingPolicy>
|
||||
<triggeringPolicy
|
||||
class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
|
||||
<MaxFileSize>10MB</MaxFileSize>
|
||||
</triggeringPolicy>
|
||||
</appender>
|
||||
<logger name="org.springframework.integration.file" level="DEBUG" />
|
||||
<root level="INFO">
|
||||
<appender-ref ref="CONSOLE" />
|
||||
<appender-ref ref="FILE" />
|
||||
</root>
|
||||
</configuration>
|
||||
@@ -0,0 +1,74 @@
|
||||
package org.springframework.bootstrap.sample.consumer;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.springframework.bootstrap.SpringApplication;
|
||||
import org.springframework.bootstrap.sample.consumer.IntegrationBootstrapApplication;
|
||||
import org.springframework.bootstrap.sample.producer.ProducerApplication;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.core.io.DefaultResourceLoader;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.support.ResourcePatternUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Basic integration tests for service demo application.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class IntegrationBootstrapApplicationTests {
|
||||
|
||||
private static ConfigurableApplicationContext context;
|
||||
|
||||
@BeforeClass
|
||||
public static void start() throws Exception {
|
||||
context = (ConfigurableApplicationContext) SpringApplication
|
||||
.run(IntegrationBootstrapApplication.class);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void stop() {
|
||||
if (context != null) {
|
||||
context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVanillaExchange() throws Exception {
|
||||
SpringApplication.run(ProducerApplication.class, "World");
|
||||
String output = getOutput();
|
||||
assertTrue("Wrong output: " + output, output.contains("Hello World"));
|
||||
}
|
||||
|
||||
private String getOutput() throws Exception {
|
||||
Future<String> future = Executors.newSingleThreadExecutor().submit(
|
||||
new Callable<String>() {
|
||||
@Override
|
||||
public String call() throws Exception {
|
||||
Resource[] resources = new Resource[0];
|
||||
while (resources.length == 0) {
|
||||
Thread.sleep(200);
|
||||
resources = ResourcePatternUtils.getResourcePatternResolver(
|
||||
new DefaultResourceLoader()).getResources(
|
||||
"file:target/output/**");
|
||||
}
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (Resource resource : resources) {
|
||||
builder.append(new String(StreamUtils
|
||||
.copyToByteArray(resource.getInputStream())));
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
});
|
||||
return future.get(10, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.springframework.bootstrap.sample.producer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
import org.springframework.bootstrap.CommandLineRunner;
|
||||
import org.springframework.bootstrap.SpringApplication;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class ProducerApplication implements CommandLineRunner {
|
||||
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
new File("target/input").mkdirs();
|
||||
FileOutputStream stream = new FileOutputStream("target/input/data"+System.currentTimeMillis()+".txt");
|
||||
for (String arg : args) {
|
||||
stream.write(arg.getBytes());
|
||||
}
|
||||
stream.flush();
|
||||
stream.close();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
SpringApplication.run(ProducerApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
package org.springframework.bootstrap.sample.service;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.springframework.bootstrap.SpringApplication;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.core.MessagingTemplate;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Basic integration tests for service demo application.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class IntegrationBootstrapApplicationTests {
|
||||
|
||||
private static ConfigurableApplicationContext context;
|
||||
|
||||
@BeforeClass
|
||||
public static void start() throws Exception {
|
||||
Future<ConfigurableApplicationContext> future = Executors
|
||||
.newSingleThreadExecutor().submit(
|
||||
new Callable<ConfigurableApplicationContext>() {
|
||||
@Override
|
||||
public ConfigurableApplicationContext call() throws Exception {
|
||||
return (ConfigurableApplicationContext) SpringApplication
|
||||
.run(IntegrationBootstrapApplication.class);
|
||||
}
|
||||
});
|
||||
context = future.get(10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void stop() {
|
||||
if (context != null) {
|
||||
context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVanillaExchange() throws Exception {
|
||||
MessagingTemplate template = new MessagingTemplate();
|
||||
template.setChannelResolver(new BeanFactoryChannelResolver(context));
|
||||
Message<?> result = template.sendAndReceive("input",
|
||||
MessageBuilder.withPayload("Phil").build());
|
||||
assertEquals("{message=Hello Phil}", result.getPayload().toString());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user