[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
pull/1/merge
Dave Syer 12 years ago
parent 10c333ea10
commit 628a8c79aa

@ -4,10 +4,10 @@ package org.test
class Example implements CommandLineRunner { class Example implements CommandLineRunner {
@Autowired @Autowired
private MyService myService; private MyService myService
public void run(String... args) { void run(String... args) {
print "Hello " + this.myService.sayWorld(); print "Hello " + this.myService.sayWorld()
} }
} }
@ -15,8 +15,8 @@ class Example implements CommandLineRunner {
@Service @Service
class MyService { class MyService {
public String sayWorld() { String sayWorld() {
return "World!"; return "World!"
} }
} }

@ -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")
}
}

@ -40,6 +40,10 @@ public class CleanCommand extends OptionParsingCommand {
private OptionSpec<Void> allOption; private OptionSpec<Void> allOption;
private OptionSpec<Void> ivyOption;
private OptionSpec<Void> mvnOption;
public CleanCommand() { public CleanCommand() {
super("clean", super("clean",
"Clean up groovy grapes (useful if snapshots are needed and you need an update)"); "Clean up groovy grapes (useful if snapshots are needed and you need an update)");
@ -54,13 +58,24 @@ public class CleanCommand extends OptionParsingCommand {
protected OptionParser createOptionParser() { protected OptionParser createOptionParser() {
OptionParser parser = new OptionParser(); OptionParser parser = new OptionParser();
this.allOption = parser.accepts("all", "Clean all files (not just snapshots)"); this.allOption = parser.accepts("all", "Clean all files (not just snapshots)");
this.ivyOption = parser.accepts("ivy",
"Clean just ivy (grapes) cache. Default is on unless --maven is used.");
this.mvnOption = parser.accepts("maven",
"Clean just maven cache. Default is off.");
return parser; return parser;
} }
@Override @Override
protected void run(OptionSet options) throws Exception { protected void run(OptionSet options) throws Exception {
clean(options, getGrapesHome(options), Layout.IVY); if (!options.has(this.ivyOption)) {
clean(options, getMavenHome(options), Layout.MAVEN); clean(options, getGrapesHome(options), Layout.IVY);
}
if (options.has(this.mvnOption)) {
if (options.has(this.ivyOption)) {
clean(options, getGrapesHome(options), Layout.IVY);
}
clean(options, getMavenHome(options), Layout.MAVEN);
}
} }
private void clean(OptionSet options, File root, Layout layout) { private void clean(OptionSet options, File root, Layout layout) {

@ -60,7 +60,7 @@ public class SpringBootstrapCompilerAutoConfiguration extends CompilerAutoConfig
@Override @Override
public void applyImports(ImportCustomizer imports) { public void applyImports(ImportCustomizer imports) {
imports.addImports("javax.sql.DataSource", "javax.annotation.PostConstruct", imports.addImports("javax.sql.DataSource", "javax.annotation.PostConstruct",
"javax.annotation.PreDestroy", "javax.annotation.PreDestroy", "groovy.util.logging.Log",
"org.springframework.stereotype.Controller", "org.springframework.stereotype.Controller",
"org.springframework.stereotype.Service", "org.springframework.stereotype.Service",
"org.springframework.stereotype.Component", "org.springframework.stereotype.Component",

@ -58,6 +58,7 @@ public class SpringIntegrationCompilerAutoConfiguration extends CompilerAutoConf
@Override @Override
public void applyImports(ImportCustomizer imports) { public void applyImports(ImportCustomizer imports) {
imports.addImports("org.springframework.integration.Message", imports.addImports("org.springframework.integration.Message",
"org.springframework.integration.support.MessageBuilder",
"org.springframework.integration.MessageChannel", "org.springframework.integration.MessageChannel",
"org.springframework.integration.MessageHeaders", "org.springframework.integration.MessageHeaders",
"org.springframework.integration.annotation.MessageEndpoint", "org.springframework.integration.annotation.MessageEndpoint",

@ -57,7 +57,7 @@ if [ -f build.gradle ]; then
fi fi
mkdir -p "${TARGETDIR%/}" mkdir -p "${TARGETDIR%/}"
CLASSPATH="${SPRING_BIN}":"${TARGETDIR}" CLASSPATH="${CLASSPATH}":"${SPRING_BIN}":"${TARGETDIR}"
for f in "${SPRING_HOME}"/lib/*.jar; do for f in "${SPRING_HOME}"/lib/*.jar; do
CLASSPATH="${CLASSPATH}":$f CLASSPATH="${CLASSPATH}":$f

@ -5,3 +5,5 @@ log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n
log4j.category.org.springframework.bootstrap=DEBUG log4j.category.org.springframework.bootstrap=DEBUG
#log4j.category.org.springframework.integration.dsl=DEBUG
#log4j.category.org.springframework.amqp=DEBUG

@ -25,7 +25,7 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.integration</groupId> <groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-stream</artifactId> <artifactId>spring-integration-file</artifactId>
<version>${dependency.spring.integration.version}</version> <version>${dependency.spring.integration.version}</version>
</dependency> </dependency>
<dependency> <dependency>

@ -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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; 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.SpringApplication;
import org.springframework.bootstrap.context.annotation.EnableAutoConfiguration; 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 * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.bootstrap.sample.service; package org.springframework.bootstrap.sample.consumer;
import org.springframework.bootstrap.context.annotation.ConfigurationProperties; 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" <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration" 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 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"> http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<int:channel id="input"/> <int-file:inbound-channel-adapter channel="input" directory="target/input" filename-pattern="*">
<int:service-activator input-channel="input" ref="sampleEndpoint"/> <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> </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());
}
}

@ -28,7 +28,7 @@ import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.AuthenticationBuilder; import org.springframework.security.config.annotation.authentication.AuthenticationBuilder;
import org.springframework.security.config.annotation.web.EnableWebSecurity; import org.springframework.security.config.annotation.web.EnableWebSecurity;
import org.springframework.security.config.annotation.web.ExpressionUrlAuthorizations; import org.springframework.security.config.annotation.web.ExpressionUrlAuthorizations;
import org.springframework.security.config.annotation.web.HttpConfiguration; import org.springframework.security.config.annotation.web.HttpConfigurator;
import org.springframework.security.config.annotation.web.SpringSecurityFilterChainBuilder.IgnoredRequestRegistry; import org.springframework.security.config.annotation.web.SpringSecurityFilterChainBuilder.IgnoredRequestRegistry;
import org.springframework.security.config.annotation.web.WebSecurityConfiguration; import org.springframework.security.config.annotation.web.WebSecurityConfiguration;
import org.springframework.security.config.annotation.web.WebSecurityConfigurerAdapter; import org.springframework.security.config.annotation.web.WebSecurityConfigurerAdapter;
@ -64,7 +64,7 @@ public class SecurityAutoConfiguration {
} }
@Override @Override
protected void configure(HttpConfiguration http) throws Exception { protected void configure(HttpConfigurator http) throws Exception {
http.antMatcher("/**").httpBasic().and().anonymous().disable(); http.antMatcher("/**").httpBasic().and().anonymous().disable();
if (this.security.isRequireSsl()) { if (this.security.isRequireSsl()) {
http.requiresChannel().antMatchers("/**").requiresSecure(); http.requiresChannel().antMatchers("/**").requiresSecure();

@ -33,6 +33,6 @@ public interface CommandLineRunner {
* Callback used to run the bean. * Callback used to run the bean.
* @param args incoming main method arguments * @param args incoming main method arguments
*/ */
void run(String... args); void run(String... args) throws Exception;
} }

@ -423,7 +423,11 @@ public class SpringApplication {
.getBeansOfType(CommandLineRunner.class).values()); .getBeansOfType(CommandLineRunner.class).values());
AnnotationAwareOrderComparator.sort(runners); AnnotationAwareOrderComparator.sort(runners);
for (CommandLineRunner runner : runners) { for (CommandLineRunner runner : runners) {
runner.run(args); try {
runner.run(args);
} catch (Exception e) {
throw new IllegalStateException("Failed to execute CommandLineRunner", e);
}
} }
} }

Loading…
Cancel
Save