[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 snapshotspull/1/merge
parent
10c333ea10
commit
628a8c79aa
@ -1,20 +0,0 @@
|
||||
package org.test
|
||||
|
||||
@Grab("org.springframework.bootstrap:spring-bootstrap-service:0.0.1-SNAPSHOT")
|
||||
@Grab("org.springframework.integration:spring-integration-dsl-groovy-amqp:1.0.0.M1")
|
||||
|
||||
@Component
|
||||
@EnableIntegrationPatterns
|
||||
class SpringIntegrationExample implements CommandLineRunner {
|
||||
|
||||
@Bean
|
||||
MessageFlow flow(ApplicationContext context) {
|
||||
def builder = new IntegrationBuilder(context)
|
||||
builder.messageFlow { transform {"Hello, $it!"} }
|
||||
}
|
||||
|
||||
@Override
|
||||
void run(String... args) {
|
||||
print flow().sendAndReceive("World")
|
||||
}
|
||||
}
|
@ -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;
|
2
spring-bootstrap-samples/spring-bootstrap-integration-sample/src/main/java/org/springframework/bootstrap/sample/service/IntegrationBootstrapApplication.java → spring-bootstrap-samples/spring-bootstrap-integration-sample/src/main/java/org/springframework/bootstrap/sample/consumer/IntegrationBootstrapApplication.java
2
spring-bootstrap-samples/spring-bootstrap-integration-sample/src/main/java/org/springframework/bootstrap/sample/service/IntegrationBootstrapApplication.java → spring-bootstrap-samples/spring-bootstrap-integration-sample/src/main/java/org/springframework/bootstrap/sample/consumer/IntegrationBootstrapApplication.java
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue