From 0e5723722341db2262eaa38a0d42bfb678cb7dfe Mon Sep 17 00:00:00 2001 From: lunk djedi Date: Sat, 17 Feb 2018 21:01:21 -0500 Subject: [PATCH 1/5] Helloworld --- annotations/helloworld/README.md | 39 +++++ annotations/helloworld/pom.xml | 164 ++++++++++++++++++ .../samples/helloworld/HelloConfig.java | 46 +++++ .../samples/helloworld/HelloService.java | 33 ++++ .../samples/helloworld/HelloWorldApp.java | 54 ++++++ .../samples/helloworld/PollerApp.java | 37 ++++ .../samples/helloworld/PollerConfig.java | 77 ++++++++ .../META-INF/spring/integration/delay.xml | 18 ++ .../helloworld/src/main/resources/log4j2.xml | 16 ++ 9 files changed, 484 insertions(+) create mode 100644 annotations/helloworld/README.md create mode 100644 annotations/helloworld/pom.xml create mode 100644 annotations/helloworld/src/main/java/org/springframework/integration/samples/helloworld/HelloConfig.java create mode 100644 annotations/helloworld/src/main/java/org/springframework/integration/samples/helloworld/HelloService.java create mode 100644 annotations/helloworld/src/main/java/org/springframework/integration/samples/helloworld/HelloWorldApp.java create mode 100644 annotations/helloworld/src/main/java/org/springframework/integration/samples/helloworld/PollerApp.java create mode 100644 annotations/helloworld/src/main/java/org/springframework/integration/samples/helloworld/PollerConfig.java create mode 100644 annotations/helloworld/src/main/resources/META-INF/spring/integration/delay.xml create mode 100644 annotations/helloworld/src/main/resources/log4j2.xml diff --git a/annotations/helloworld/README.md b/annotations/helloworld/README.md new file mode 100644 index 000000000..15ea72dc7 --- /dev/null +++ b/annotations/helloworld/README.md @@ -0,0 +1,39 @@ +Hello World Sample +================== + +This is an obvious place to get started. This sample project contains 2 basic sample applications: + +* Hello World +* Poller Application + +## Hello World + +The Hello World application demonstrates a simple message flow represented by the diagram below: + + Message -> Channel -> ServiceActivator -> QueueChannel + +To run the sample simply execute **HelloWorldApp** in package **org.springframework.integration.samples.helloworld**. +You can also execute that class using the [Gradle](http://www.gradle.org): + + $ gradlew :helloworld:runHelloWorldApp + +You should see the following output: + + INFO : org.springframework.integration.samples.helloworld.HelloWorldApp - ==> HelloWorldDemo: Hello World + +## Poller Application + +This simple application will print out the current system time twice every 20 seconds. + +More specifically, an **Inbound Channel Adapter** polls for the current system time 2 times every 20 seconds (20000 milliseconds). The resulting message contains as payload the time in milliseconds and the message is sent to a **Logging Channel Adapter**, which will print the time to the command prompt. + +To run the sample simply execute **PollerApp** in package **org.springframework.integration.samples.helloworld**. +You can also execute that class using the [Gradle](http://www.gradle.org): + + $ gradlew :helloworld:runPollerApp + +You should see output like the following: + + INFO : org.springframework.integration.samples.helloworld - 1328892135471 + INFO : org.springframework.integration.samples.helloworld - 1328892135524 + diff --git a/annotations/helloworld/pom.xml b/annotations/helloworld/pom.xml new file mode 100644 index 000000000..dd545c90e --- /dev/null +++ b/annotations/helloworld/pom.xml @@ -0,0 +1,164 @@ + + + 4.0.0 + org.springframework.integration.samples + helloworld + 5.0.0.BUILD-SNAPSHOT + Hello World Sample + Hello World Sample + http://projects.spring.io/spring-integration + + SpringIO + https://spring.io + + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + + garyrussell + Gary Russell + grussell@pivotal.io + + project lead + + + + markfisher + Mark Fisher + mfisher@pivotal.io + + project founder and lead emeritus + + + + ghillert + Gunnar Hillert + ghillert@pivotal.io + + + abilan + Artem Bilan + abilan@pivotal.io + + + + scm:git:scm:git:git://github.com/spring-projects/spring-integration-samples.git + scm:git:scm:git:ssh://git@github.com:spring-projects/spring-integration-samples.git + https://github.com/spring-projects/spring-integration-samples + + + + org.springframework.integration + spring-integration-core + compile + + + jackson-module-kotlin + com.fasterxml.jackson.module + + + + + org.apache.logging.log4j + log4j-core + 2.7 + compile + + + jackson-module-kotlin + com.fasterxml.jackson.module + + + + + junit + junit + 4.12 + test + + + jackson-module-kotlin + com.fasterxml.jackson.module + + + * + org.hamcrest + + + + + org.hamcrest + hamcrest-all + 1.3 + test + + + jackson-module-kotlin + com.fasterxml.jackson.module + + + + + org.mockito + mockito-core + 2.10.0 + test + + + jackson-module-kotlin + com.fasterxml.jackson.module + + + * + org.hamcrest + + + + + org.springframework + spring-test + test + + + jackson-module-kotlin + com.fasterxml.jackson.module + + + + + + + repo.spring.io.milestone + Spring Framework Maven Milestone Repository + https://repo.spring.io/libs-milestone + + + repo.spring.io.snapshot + Spring Framework Maven Snapshot Repository + https://repo.spring.io/libs-snapshot + + + + + + org.springframework.integration + spring-integration-bom + 5.0.0.M7 + import + pom + + + org.springframework + spring-framework-bom + 5.0.0.RC4 + import + pom + + + + diff --git a/annotations/helloworld/src/main/java/org/springframework/integration/samples/helloworld/HelloConfig.java b/annotations/helloworld/src/main/java/org/springframework/integration/samples/helloworld/HelloConfig.java new file mode 100644 index 000000000..e3a48a931 --- /dev/null +++ b/annotations/helloworld/src/main/java/org/springframework/integration/samples/helloworld/HelloConfig.java @@ -0,0 +1,46 @@ +package org.springframework.integration.samples.helloworld; + +import java.util.Map; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.integration.annotation.IntegrationComponentScan; +import org.springframework.integration.config.EnableIntegration; +import org.springframework.integration.dsl.IntegrationFlow; +import org.springframework.integration.dsl.IntegrationFlows; +import org.springframework.integration.dsl.channel.MessageChannels; +import org.springframework.integration.handler.GenericHandler; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.PollableChannel; + +@Configuration +@EnableIntegration +@IntegrationComponentScan +@ComponentScan +public class HelloConfig { + + @Bean + public PollableChannel outputChannel() { + return MessageChannels.queue(10).get(); + } + + @Bean + public MessageChannel inputChannel() { + return MessageChannels.direct().get(); + } + + @Bean + public IntegrationFlow helloFlow(final HelloService helloService) { + return IntegrationFlows + .from(inputChannel()) + .handle(new GenericHandler() { + public Object handle(String arg0, Map arg1) { + return helloService.sayHello(arg0); + } + }) + .channel(outputChannel()) + .get(); + } + +} diff --git a/annotations/helloworld/src/main/java/org/springframework/integration/samples/helloworld/HelloService.java b/annotations/helloworld/src/main/java/org/springframework/integration/samples/helloworld/HelloService.java new file mode 100644 index 000000000..27078b85a --- /dev/null +++ b/annotations/helloworld/src/main/java/org/springframework/integration/samples/helloworld/HelloService.java @@ -0,0 +1,33 @@ +/* + * Copyright 2002-2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.integration.samples.helloworld; + +import org.springframework.stereotype.Service; + +/** + * Simple POJO to be referenced from a Service Activator. + * + * @author Mark Fisher + */ +@Service +public class HelloService { + + public String sayHello(String name) { + return "Hello " + name; + } + +} diff --git a/annotations/helloworld/src/main/java/org/springframework/integration/samples/helloworld/HelloWorldApp.java b/annotations/helloworld/src/main/java/org/springframework/integration/samples/helloworld/HelloWorldApp.java new file mode 100644 index 000000000..5752253ee --- /dev/null +++ b/annotations/helloworld/src/main/java/org/springframework/integration/samples/helloworld/HelloWorldApp.java @@ -0,0 +1,54 @@ +/* + * Copyright 2002-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.integration.samples.helloworld; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.PollableChannel; +import org.springframework.messaging.support.GenericMessage; + +/** + * Demonstrates a basic Message Endpoint that simply prepends a greeting + * ("Hello ") to an inbound String payload from a Message. This is a very + * low-level example, using Message Channels directly for both input and + * output. Notice that the output channel has a queue sub-element. It is + * therefore a PollableChannel and its consumers must invoke receive() as + * demonstrated below. + *

+ * View the configuration of the channels and the endpoint (a <service-activator/> + * element) in 'helloWorldDemo.xml' within this same package. + * + * @author Mark Fisher + * @author Oleg Zhurakousky + * @author Gary Russell + */ +public class HelloWorldApp { + + private static Log logger = LogFactory.getLog(HelloWorldApp.class); + + public static void main(String[] args) { + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(HelloConfig.class); + MessageChannel inputChannel = context.getBean("inputChannel", MessageChannel.class); + PollableChannel outputChannel = context.getBean("outputChannel", PollableChannel.class); + inputChannel.send(new GenericMessage("World")); + logger.info("==> HelloWorldDemo: " + outputChannel.receive(0).getPayload()); + context.close(); + } + +} diff --git a/annotations/helloworld/src/main/java/org/springframework/integration/samples/helloworld/PollerApp.java b/annotations/helloworld/src/main/java/org/springframework/integration/samples/helloworld/PollerApp.java new file mode 100644 index 000000000..edeae3031 --- /dev/null +++ b/annotations/helloworld/src/main/java/org/springframework/integration/samples/helloworld/PollerApp.java @@ -0,0 +1,37 @@ +/* + * Copyright 2002-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.integration.samples.helloworld; + +import org.springframework.context.annotation.AnnotationConfigApplicationContext; + +public class PollerApp { + + /** + * Simple application that polls the current system time 2 times every + * 20 seconds (20000 milliseconds). + * + * The resulting message contains the time in milliseconds and the message + * is routed to a Logging Channel Adapter which will print the time to the + * command prompt. + * + * @param args Not used. + */ + @SuppressWarnings("resource") + public static void main(String[] args) throws Exception{ + new AnnotationConfigApplicationContext(PollerConfig.class); + } + +} diff --git a/annotations/helloworld/src/main/java/org/springframework/integration/samples/helloworld/PollerConfig.java b/annotations/helloworld/src/main/java/org/springframework/integration/samples/helloworld/PollerConfig.java new file mode 100644 index 000000000..21ba2d678 --- /dev/null +++ b/annotations/helloworld/src/main/java/org/springframework/integration/samples/helloworld/PollerConfig.java @@ -0,0 +1,77 @@ +package org.springframework.integration.samples.helloworld; + +import java.util.Map; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.integration.annotation.InboundChannelAdapter; +import org.springframework.integration.annotation.IntegrationComponentScan; +import org.springframework.integration.annotation.Poller; +import org.springframework.integration.config.EnableIntegration; +import org.springframework.integration.core.MessageSource; +import org.springframework.integration.dsl.IntegrationFlow; +import org.springframework.integration.dsl.IntegrationFlows; +import org.springframework.integration.dsl.channel.MessageChannels; +import org.springframework.integration.handler.GenericHandler; +import org.springframework.integration.scheduling.PollerMetadata; +import org.springframework.integration.support.MessageBuilder; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageChannel; +import org.springframework.scheduling.support.PeriodicTrigger; + +/** + * + * + * + * + * + * + * + * + */ +@Configuration +@EnableIntegration +@IntegrationComponentScan +@ComponentScan +public class PollerConfig { + + @Bean + public MessageChannel logger() { + return MessageChannels.direct().get(); + } + + @Bean(name = PollerMetadata.DEFAULT_POLLER) + public PollerMetadata defaultPoller() { + PollerMetadata pollerMetadata = new PollerMetadata(); + pollerMetadata.setTrigger(new PeriodicTrigger(20000)); + pollerMetadata.setMaxMessagesPerPoll(2); + return pollerMetadata; + } + + @InboundChannelAdapter(value = "logger", poller = @Poller(PollerMetadata.DEFAULT_POLLER)) + public MessageSource inbound() { + MessageSource source = new MessageSource() { + public Message receive() { + return MessageBuilder.withPayload(System.currentTimeMillis()).build(); + } + }; + return source; + } + + @Bean + public IntegrationFlow systemTimeFlow(MessageChannel logger) { + return IntegrationFlows + .from(logger) + .handle(new GenericHandler() { + public Long handle(Long payload, Map headers) { + System.out.println(payload); + return null; + } + }) + .get(); + } + +} diff --git a/annotations/helloworld/src/main/resources/META-INF/spring/integration/delay.xml b/annotations/helloworld/src/main/resources/META-INF/spring/integration/delay.xml new file mode 100644 index 000000000..2e650f8e0 --- /dev/null +++ b/annotations/helloworld/src/main/resources/META-INF/spring/integration/delay.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + diff --git a/annotations/helloworld/src/main/resources/log4j2.xml b/annotations/helloworld/src/main/resources/log4j2.xml new file mode 100644 index 000000000..6241eb502 --- /dev/null +++ b/annotations/helloworld/src/main/resources/log4j2.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + From e2d7c98b9538d8e9fbced9b986bb3ff76ef972fb Mon Sep 17 00:00:00 2001 From: lunk djedi Date: Sat, 17 Feb 2018 23:52:34 -0500 Subject: [PATCH 2/5] basic Poller App --- annotations/{ => basic}/helloworld/README.md | 0 annotations/{ => basic}/helloworld/pom.xml | 0 .../samples/helloworld/HelloConfig.java | 14 +++++--------- .../samples/helloworld/HelloService.java | 0 .../samples/helloworld/HelloWorldApp.java | 0 .../samples/helloworld/PollerApp.java | 0 .../samples/helloworld/PollerConfig.java | 19 +++++++------------ .../helloworld/src/main/resources/log4j2.xml | 4 ++-- .../META-INF/spring/integration/delay.xml | 18 ------------------ 9 files changed, 14 insertions(+), 41 deletions(-) rename annotations/{ => basic}/helloworld/README.md (100%) rename annotations/{ => basic}/helloworld/pom.xml (100%) rename annotations/{ => basic}/helloworld/src/main/java/org/springframework/integration/samples/helloworld/HelloConfig.java (78%) rename annotations/{ => basic}/helloworld/src/main/java/org/springframework/integration/samples/helloworld/HelloService.java (100%) rename annotations/{ => basic}/helloworld/src/main/java/org/springframework/integration/samples/helloworld/HelloWorldApp.java (100%) rename annotations/{ => basic}/helloworld/src/main/java/org/springframework/integration/samples/helloworld/PollerApp.java (100%) rename annotations/{ => basic}/helloworld/src/main/java/org/springframework/integration/samples/helloworld/PollerConfig.java (82%) rename annotations/{ => basic}/helloworld/src/main/resources/log4j2.xml (81%) delete mode 100644 annotations/helloworld/src/main/resources/META-INF/spring/integration/delay.xml diff --git a/annotations/helloworld/README.md b/annotations/basic/helloworld/README.md similarity index 100% rename from annotations/helloworld/README.md rename to annotations/basic/helloworld/README.md diff --git a/annotations/helloworld/pom.xml b/annotations/basic/helloworld/pom.xml similarity index 100% rename from annotations/helloworld/pom.xml rename to annotations/basic/helloworld/pom.xml diff --git a/annotations/helloworld/src/main/java/org/springframework/integration/samples/helloworld/HelloConfig.java b/annotations/basic/helloworld/src/main/java/org/springframework/integration/samples/helloworld/HelloConfig.java similarity index 78% rename from annotations/helloworld/src/main/java/org/springframework/integration/samples/helloworld/HelloConfig.java rename to annotations/basic/helloworld/src/main/java/org/springframework/integration/samples/helloworld/HelloConfig.java index e3a48a931..c7433009d 100644 --- a/annotations/helloworld/src/main/java/org/springframework/integration/samples/helloworld/HelloConfig.java +++ b/annotations/basic/helloworld/src/main/java/org/springframework/integration/samples/helloworld/HelloConfig.java @@ -32,15 +32,11 @@ public MessageChannel inputChannel() { @Bean public IntegrationFlow helloFlow(final HelloService helloService) { - return IntegrationFlows - .from(inputChannel()) - .handle(new GenericHandler() { - public Object handle(String arg0, Map arg1) { - return helloService.sayHello(arg0); - } - }) - .channel(outputChannel()) - .get(); + return IntegrationFlows.from(inputChannel()).handle(new GenericHandler() { + public Object handle(String arg0, Map arg1) { + return helloService.sayHello(arg0); + } + }).channel(outputChannel()).get(); } } diff --git a/annotations/helloworld/src/main/java/org/springframework/integration/samples/helloworld/HelloService.java b/annotations/basic/helloworld/src/main/java/org/springframework/integration/samples/helloworld/HelloService.java similarity index 100% rename from annotations/helloworld/src/main/java/org/springframework/integration/samples/helloworld/HelloService.java rename to annotations/basic/helloworld/src/main/java/org/springframework/integration/samples/helloworld/HelloService.java diff --git a/annotations/helloworld/src/main/java/org/springframework/integration/samples/helloworld/HelloWorldApp.java b/annotations/basic/helloworld/src/main/java/org/springframework/integration/samples/helloworld/HelloWorldApp.java similarity index 100% rename from annotations/helloworld/src/main/java/org/springframework/integration/samples/helloworld/HelloWorldApp.java rename to annotations/basic/helloworld/src/main/java/org/springframework/integration/samples/helloworld/HelloWorldApp.java diff --git a/annotations/helloworld/src/main/java/org/springframework/integration/samples/helloworld/PollerApp.java b/annotations/basic/helloworld/src/main/java/org/springframework/integration/samples/helloworld/PollerApp.java similarity index 100% rename from annotations/helloworld/src/main/java/org/springframework/integration/samples/helloworld/PollerApp.java rename to annotations/basic/helloworld/src/main/java/org/springframework/integration/samples/helloworld/PollerApp.java diff --git a/annotations/helloworld/src/main/java/org/springframework/integration/samples/helloworld/PollerConfig.java b/annotations/basic/helloworld/src/main/java/org/springframework/integration/samples/helloworld/PollerConfig.java similarity index 82% rename from annotations/helloworld/src/main/java/org/springframework/integration/samples/helloworld/PollerConfig.java rename to annotations/basic/helloworld/src/main/java/org/springframework/integration/samples/helloworld/PollerConfig.java index 21ba2d678..e642a1a96 100644 --- a/annotations/helloworld/src/main/java/org/springframework/integration/samples/helloworld/PollerConfig.java +++ b/annotations/basic/helloworld/src/main/java/org/springframework/integration/samples/helloworld/PollerConfig.java @@ -1,9 +1,6 @@ package org.springframework.integration.samples.helloworld; -import java.util.Map; - import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.integration.annotation.InboundChannelAdapter; import org.springframework.integration.annotation.IntegrationComponentScan; @@ -13,7 +10,8 @@ import org.springframework.integration.dsl.IntegrationFlow; import org.springframework.integration.dsl.IntegrationFlows; import org.springframework.integration.dsl.channel.MessageChannels; -import org.springframework.integration.handler.GenericHandler; +import org.springframework.integration.handler.LoggingHandler; +import org.springframework.integration.handler.LoggingHandler.Level; import org.springframework.integration.scheduling.PollerMetadata; import org.springframework.integration.support.MessageBuilder; import org.springframework.messaging.Message; @@ -35,7 +33,6 @@ @Configuration @EnableIntegration @IntegrationComponentScan -@ComponentScan public class PollerConfig { @Bean @@ -51,7 +48,8 @@ public PollerMetadata defaultPoller() { return pollerMetadata; } - @InboundChannelAdapter(value = "logger", poller = @Poller(PollerMetadata.DEFAULT_POLLER)) + @Bean + @InboundChannelAdapter(channel="logger", poller = @Poller(PollerMetadata.DEFAULT_POLLER)) public MessageSource inbound() { MessageSource source = new MessageSource() { public Message receive() { @@ -63,14 +61,11 @@ public Message receive() { @Bean public IntegrationFlow systemTimeFlow(MessageChannel logger) { + LoggingHandler loggingHandler = new LoggingHandler(Level.INFO); + loggingHandler.setLoggerName("org.springframework.integration.samples.helloworld"); return IntegrationFlows .from(logger) - .handle(new GenericHandler() { - public Long handle(Long payload, Map headers) { - System.out.println(payload); - return null; - } - }) + .handle(loggingHandler) .get(); } diff --git a/annotations/helloworld/src/main/resources/log4j2.xml b/annotations/basic/helloworld/src/main/resources/log4j2.xml similarity index 81% rename from annotations/helloworld/src/main/resources/log4j2.xml rename to annotations/basic/helloworld/src/main/resources/log4j2.xml index 6241eb502..d3292d47a 100644 --- a/annotations/helloworld/src/main/resources/log4j2.xml +++ b/annotations/basic/helloworld/src/main/resources/log4j2.xml @@ -1,5 +1,5 @@ - + @@ -10,7 +10,7 @@ - + diff --git a/annotations/helloworld/src/main/resources/META-INF/spring/integration/delay.xml b/annotations/helloworld/src/main/resources/META-INF/spring/integration/delay.xml deleted file mode 100644 index 2e650f8e0..000000000 --- a/annotations/helloworld/src/main/resources/META-INF/spring/integration/delay.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - From 06d3ca755c567839698616adbe0c38e4954e85f1 Mon Sep 17 00:00:00 2001 From: lunk djedi Date: Sun, 18 Feb 2018 11:42:53 -0500 Subject: [PATCH 3/5] Starting Basic File --- annotations/basic/file/README.md | 18 ++ annotations/basic/file/input/file_0.txt | 1 + annotations/basic/file/input/file_1.txt | 1 + annotations/basic/file/input/file_2.txt | 1 + annotations/basic/file/input/file_3.txt | 1 + annotations/basic/file/input/file_4.txt | 1 + annotations/basic/file/pom.xml | 164 ++++++++++++++++++ .../samples/filecopy/BinaryConfig.java | 119 +++++++++++++ .../samples/filecopy/FileCopyDemoCommon.java | 45 +++++ .../integration/samples/filecopy/Handler.java | 44 +++++ .../integration/fileCopyDemo-binary.xml | 32 ++++ .../spring/integration/fileCopyDemo-file.xml | 30 ++++ .../spring/integration/fileCopyDemo-text.xml | 33 ++++ .../samples/filecopy/BinaryFileCopyTest.java | 41 +++++ .../filecopy/FileBasedFileCopyTest.java | 38 ++++ .../samples/filecopy/TextFileCopyTest.java | 40 +++++ .../basic/file/src/test/resources/log4j2.xml | 16 ++ 17 files changed, 625 insertions(+) create mode 100644 annotations/basic/file/README.md create mode 100644 annotations/basic/file/input/file_0.txt create mode 100644 annotations/basic/file/input/file_1.txt create mode 100644 annotations/basic/file/input/file_2.txt create mode 100644 annotations/basic/file/input/file_3.txt create mode 100644 annotations/basic/file/input/file_4.txt create mode 100644 annotations/basic/file/pom.xml create mode 100644 annotations/basic/file/src/main/java/org/springframework/integration/samples/filecopy/BinaryConfig.java create mode 100644 annotations/basic/file/src/main/java/org/springframework/integration/samples/filecopy/FileCopyDemoCommon.java create mode 100644 annotations/basic/file/src/main/java/org/springframework/integration/samples/filecopy/Handler.java create mode 100644 annotations/basic/file/src/main/resources/META-INF/spring/integration/fileCopyDemo-binary.xml create mode 100644 annotations/basic/file/src/main/resources/META-INF/spring/integration/fileCopyDemo-file.xml create mode 100644 annotations/basic/file/src/main/resources/META-INF/spring/integration/fileCopyDemo-text.xml create mode 100644 annotations/basic/file/src/test/java/org/springframework/integration/samples/filecopy/BinaryFileCopyTest.java create mode 100644 annotations/basic/file/src/test/java/org/springframework/integration/samples/filecopy/FileBasedFileCopyTest.java create mode 100644 annotations/basic/file/src/test/java/org/springframework/integration/samples/filecopy/TextFileCopyTest.java create mode 100644 annotations/basic/file/src/test/resources/log4j2.xml diff --git a/annotations/basic/file/README.md b/annotations/basic/file/README.md new file mode 100644 index 000000000..9f112fbce --- /dev/null +++ b/annotations/basic/file/README.md @@ -0,0 +1,18 @@ +File Sample +=========== + +This example demonstrates the following aspects of the File operations support available with Spring Integration: + +1. File Inbound Channel Adapter +2. File Outbound Channel Adapter +3. File-to-Bytes Transformer + +Furthermore, a Poller is used as well. + +The use case is a simple file copy, but implemented in 3 basic flavors: + +1. Binary file copy +2. Text file copy +3. Simple file copy + +To run the samples simply execute the 3 test cases located in the **org.springframework.integration.samples.filecopy** package. \ No newline at end of file diff --git a/annotations/basic/file/input/file_0.txt b/annotations/basic/file/input/file_0.txt new file mode 100644 index 000000000..a3f6e274e --- /dev/null +++ b/annotations/basic/file/input/file_0.txt @@ -0,0 +1 @@ +hello 0 \ No newline at end of file diff --git a/annotations/basic/file/input/file_1.txt b/annotations/basic/file/input/file_1.txt new file mode 100644 index 000000000..a4f3ad55f --- /dev/null +++ b/annotations/basic/file/input/file_1.txt @@ -0,0 +1 @@ +hello 1 \ No newline at end of file diff --git a/annotations/basic/file/input/file_2.txt b/annotations/basic/file/input/file_2.txt new file mode 100644 index 000000000..b20684db6 --- /dev/null +++ b/annotations/basic/file/input/file_2.txt @@ -0,0 +1 @@ +hello 2 \ No newline at end of file diff --git a/annotations/basic/file/input/file_3.txt b/annotations/basic/file/input/file_3.txt new file mode 100644 index 000000000..7059d70f8 --- /dev/null +++ b/annotations/basic/file/input/file_3.txt @@ -0,0 +1 @@ +hello 3 \ No newline at end of file diff --git a/annotations/basic/file/input/file_4.txt b/annotations/basic/file/input/file_4.txt new file mode 100644 index 000000000..cd1c078e0 --- /dev/null +++ b/annotations/basic/file/input/file_4.txt @@ -0,0 +1 @@ +hello 4 \ No newline at end of file diff --git a/annotations/basic/file/pom.xml b/annotations/basic/file/pom.xml new file mode 100644 index 000000000..c46de86af --- /dev/null +++ b/annotations/basic/file/pom.xml @@ -0,0 +1,164 @@ + + + 4.0.0 + org.springframework.integration.samples + file + 5.0.0.BUILD-SNAPSHOT + File Copy Basic Sample + File Copy Basic Sample + http://projects.spring.io/spring-integration + + SpringIO + https://spring.io + + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + + garyrussell + Gary Russell + grussell@pivotal.io + + project lead + + + + markfisher + Mark Fisher + mfisher@pivotal.io + + project founder and lead emeritus + + + + ghillert + Gunnar Hillert + ghillert@pivotal.io + + + abilan + Artem Bilan + abilan@pivotal.io + + + + scm:git:scm:git:git://github.com/spring-projects/spring-integration-samples.git + scm:git:scm:git:ssh://git@github.com:spring-projects/spring-integration-samples.git + https://github.com/spring-projects/spring-integration-samples + + + + org.springframework.integration + spring-integration-file + compile + + + jackson-module-kotlin + com.fasterxml.jackson.module + + + + + org.apache.logging.log4j + log4j-core + 2.7 + compile + + + jackson-module-kotlin + com.fasterxml.jackson.module + + + + + junit + junit + 4.12 + test + + + jackson-module-kotlin + com.fasterxml.jackson.module + + + * + org.hamcrest + + + + + org.hamcrest + hamcrest-all + 1.3 + test + + + jackson-module-kotlin + com.fasterxml.jackson.module + + + + + org.mockito + mockito-core + 2.10.0 + test + + + jackson-module-kotlin + com.fasterxml.jackson.module + + + * + org.hamcrest + + + + + org.springframework + spring-test + test + + + jackson-module-kotlin + com.fasterxml.jackson.module + + + + + + + repo.spring.io.milestone + Spring Framework Maven Milestone Repository + https://repo.spring.io/libs-milestone + + + repo.spring.io.snapshot + Spring Framework Maven Snapshot Repository + https://repo.spring.io/libs-snapshot + + + + + + org.springframework.integration + spring-integration-bom + 5.0.0.M7 + import + pom + + + org.springframework + spring-framework-bom + 5.0.0.RC4 + import + pom + + + + diff --git a/annotations/basic/file/src/main/java/org/springframework/integration/samples/filecopy/BinaryConfig.java b/annotations/basic/file/src/main/java/org/springframework/integration/samples/filecopy/BinaryConfig.java new file mode 100644 index 000000000..538b49c67 --- /dev/null +++ b/annotations/basic/file/src/main/java/org/springframework/integration/samples/filecopy/BinaryConfig.java @@ -0,0 +1,119 @@ +package org.springframework.integration.samples.filecopy; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.Map; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; +import org.springframework.context.annotation.PropertySources; +import org.springframework.integration.annotation.InboundChannelAdapter; +import org.springframework.integration.core.MessageSource; +import org.springframework.integration.dsl.IntegrationFlow; +import org.springframework.integration.dsl.IntegrationFlows; +import org.springframework.integration.dsl.channel.MessageChannels; +import org.springframework.integration.file.FileReadingMessageSource; +import org.springframework.integration.file.FileWritingMessageHandler; +import org.springframework.integration.handler.GenericHandler; +import org.springframework.integration.scheduling.PollerMetadata; +import org.springframework.integration.transformer.GenericTransformer; +import org.springframework.messaging.MessageChannel; +import org.springframework.scheduling.support.PeriodicTrigger; + +/** + * + + + + + + + + * + */ +@Configuration +public class BinaryConfig { + + @Value("${java.io.tmpdir}") + private String tmpDir; + + /** + * + */ + @Bean + @InboundChannelAdapter + public MessageSource filesIn() { + FileReadingMessageSource source = new FileReadingMessageSource(); + source.setDirectory(new File(tmpDir + "/spring-integration-samples/input")); + return source; + } + + /** + * + */ + @Bean + public MessageChannel bytes() { + return MessageChannels.direct().get(); + } + + /** + * + * + * + * + */ + @Bean + public IntegrationFlow copyFlow(@Autowired final Handler handler) { + return IntegrationFlows.from("filesIn") + .transform(new GenericTransformer() { + public byte[] transform(File source) { + try { + return Files.readAllBytes(source.toPath()); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + }).handle(new GenericHandler() { + public Object handle(byte[] payload, Map headers) { + return handler.handleBytes(payload); + } + }).handle(new GenericHandler(){ + + public Object handle(byte[] payload, Map headers) { + FileWritingMessageHandler handler = new FileWritingMessageHandler(new File(tmpDir + "/spring-integration-samples/output")); + handler.setDeleteSourceFiles(true); + handler.start(); + return handler; + } + + }).get(); + } + + /** + * + */ + @Bean + public Handler handler() { + return new Handler(); + } + + /** + * + */ + @Bean(name = PollerMetadata.DEFAULT_POLLER) + public PollerMetadata defaultPoller() { + PollerMetadata pollerMetadata = new PollerMetadata(); + pollerMetadata.setTrigger(new PeriodicTrigger(1000)); + return pollerMetadata; + } +} diff --git a/annotations/basic/file/src/main/java/org/springframework/integration/samples/filecopy/FileCopyDemoCommon.java b/annotations/basic/file/src/main/java/org/springframework/integration/samples/filecopy/FileCopyDemoCommon.java new file mode 100644 index 000000000..627c5b276 --- /dev/null +++ b/annotations/basic/file/src/main/java/org/springframework/integration/samples/filecopy/FileCopyDemoCommon.java @@ -0,0 +1,45 @@ +/* + * Copyright 2002-2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.integration.samples.filecopy; + +import java.io.File; + +import org.springframework.beans.DirectFieldAccessor; +import org.springframework.context.ApplicationContext; +import org.springframework.expression.common.LiteralExpression; +import org.springframework.integration.file.FileReadingMessageSource; +import org.springframework.integration.file.FileWritingMessageHandler; + +/** + * Displays the names of the input and output directories. + * + * @author Marius Bogoevici + * @author Mark Fisher + * @author Gary Russell + */ +public class FileCopyDemoCommon { + + public static void displayDirectories(ApplicationContext context) { + File inDir = (File) new DirectFieldAccessor(context.getBean(FileReadingMessageSource.class)).getPropertyValue("directory"); + LiteralExpression expression = (LiteralExpression) new DirectFieldAccessor(context.getBean(FileWritingMessageHandler.class)).getPropertyValue("destinationDirectoryExpression"); + File outDir = new File(expression.getValue()); + System.out.println("Input directory is: " + inDir.getAbsolutePath()); + System.out.println("Output directory is: " + outDir.getAbsolutePath()); + System.out.println("==================================================="); + } + +} diff --git a/annotations/basic/file/src/main/java/org/springframework/integration/samples/filecopy/Handler.java b/annotations/basic/file/src/main/java/org/springframework/integration/samples/filecopy/Handler.java new file mode 100644 index 000000000..8fb30246c --- /dev/null +++ b/annotations/basic/file/src/main/java/org/springframework/integration/samples/filecopy/Handler.java @@ -0,0 +1,44 @@ +/* + * Copyright 2002-2010 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.integration.samples.filecopy; + +import java.io.File; + +/** + * A class providing several handling methods for different types of payloads. + * + * @author Mark Fisher + * @author Marius Bogoevici + */ +public class Handler { + + public String handleString(String input) { + System.out.println("Copying text: " + input); + return input.toUpperCase(); + } + + public File handleFile(File input) { + System.out.println("Copying file: " + input.getAbsolutePath()); + return input; + } + + public byte[] handleBytes(byte[] input) { + System.out.println("Copying " + input.length + " bytes ..."); + return new String(input).toUpperCase().getBytes(); + } + +} diff --git a/annotations/basic/file/src/main/resources/META-INF/spring/integration/fileCopyDemo-binary.xml b/annotations/basic/file/src/main/resources/META-INF/spring/integration/fileCopyDemo-binary.xml new file mode 100644 index 000000000..0bbe7a295 --- /dev/null +++ b/annotations/basic/file/src/main/resources/META-INF/spring/integration/fileCopyDemo-binary.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/annotations/basic/file/src/main/resources/META-INF/spring/integration/fileCopyDemo-file.xml b/annotations/basic/file/src/main/resources/META-INF/spring/integration/fileCopyDemo-file.xml new file mode 100644 index 000000000..64d7d7ab4 --- /dev/null +++ b/annotations/basic/file/src/main/resources/META-INF/spring/integration/fileCopyDemo-file.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + diff --git a/annotations/basic/file/src/main/resources/META-INF/spring/integration/fileCopyDemo-text.xml b/annotations/basic/file/src/main/resources/META-INF/spring/integration/fileCopyDemo-text.xml new file mode 100644 index 000000000..0ad635a7e --- /dev/null +++ b/annotations/basic/file/src/main/resources/META-INF/spring/integration/fileCopyDemo-text.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/annotations/basic/file/src/test/java/org/springframework/integration/samples/filecopy/BinaryFileCopyTest.java b/annotations/basic/file/src/test/java/org/springframework/integration/samples/filecopy/BinaryFileCopyTest.java new file mode 100644 index 000000000..3ace08790 --- /dev/null +++ b/annotations/basic/file/src/test/java/org/springframework/integration/samples/filecopy/BinaryFileCopyTest.java @@ -0,0 +1,41 @@ +/* + * Copyright 2002-2010 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.integration.samples.filecopy; + +import org.junit.Test; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; + +/** + * Demonstrating the file copy scenario using binary file source and target. + * See the 'fileCopyDemo-binary.xml' configuration file for details. Notice + * that the transformer is configured to delete the source File after it + * extracts the content as a byte array. + * + * @author Marius Bogoevici + */ +public class BinaryFileCopyTest { + + @Test + public void testBinaryCopy() throws Exception{ + ApplicationContext context = //new ClassPathXmlApplicationContext("/META-INF/spring/integration/fileCopyDemo-binary.xml", BinaryFileCopyTest.class); + new AnnotationConfigApplicationContext(BinaryConfig.class); + FileCopyDemoCommon.displayDirectories(context); + Thread.sleep(60000); + } + +} diff --git a/annotations/basic/file/src/test/java/org/springframework/integration/samples/filecopy/FileBasedFileCopyTest.java b/annotations/basic/file/src/test/java/org/springframework/integration/samples/filecopy/FileBasedFileCopyTest.java new file mode 100644 index 000000000..e123eb085 --- /dev/null +++ b/annotations/basic/file/src/test/java/org/springframework/integration/samples/filecopy/FileBasedFileCopyTest.java @@ -0,0 +1,38 @@ +/* + * Copyright 2002-2010 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.integration.samples.filecopy; + +import org.junit.Test; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * Demonstrating the file copy scenario using file-based source and target. + * See the 'fileCopyDemo-file.xml' configuration file for details. + * + * @author Marius Bogoevici + */ +public class FileBasedFileCopyTest { + + @Test + public void testFileBasedCopy() throws Exception{ + ApplicationContext context = new ClassPathXmlApplicationContext("/META-INF/spring/integration/fileCopyDemo-file.xml", FileBasedFileCopyTest.class); + FileCopyDemoCommon.displayDirectories(context); + Thread.sleep(5000); + } + +} diff --git a/annotations/basic/file/src/test/java/org/springframework/integration/samples/filecopy/TextFileCopyTest.java b/annotations/basic/file/src/test/java/org/springframework/integration/samples/filecopy/TextFileCopyTest.java new file mode 100644 index 000000000..2ff35e688 --- /dev/null +++ b/annotations/basic/file/src/test/java/org/springframework/integration/samples/filecopy/TextFileCopyTest.java @@ -0,0 +1,40 @@ +/* + * Copyright 2002-2010 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.integration.samples.filecopy; + +import org.junit.Test; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * Demonstrating the file copy scenario using text-based source and target. + * See the 'fileCopyDemo-text.xml' configuration file for details. + * + * @author Mark Fisher + * @author Marius Bogoevici + */ +public class TextFileCopyTest { + + @Test + public void testTextBasedCopy() throws Exception{ + ApplicationContext context = new ClassPathXmlApplicationContext("/META-INF/spring/integration/fileCopyDemo-text.xml", TextFileCopyTest.class); + FileCopyDemoCommon.displayDirectories(context); + Thread.sleep(5000); + } + +} + diff --git a/annotations/basic/file/src/test/resources/log4j2.xml b/annotations/basic/file/src/test/resources/log4j2.xml new file mode 100644 index 000000000..6241eb502 --- /dev/null +++ b/annotations/basic/file/src/test/resources/log4j2.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + From f064210c3d7e6459c9c804a944b56484b12f855c Mon Sep 17 00:00:00 2001 From: lunk djedi Date: Mon, 19 Feb 2018 14:29:55 -0500 Subject: [PATCH 4/5] Refactored Poller example to separate package to limit @ComponentScan scope. --- .../samples/{helloworld => systemtime}/PollerApp.java | 2 +- .../samples/{helloworld => systemtime}/PollerConfig.java | 4 ++-- annotations/basic/helloworld/src/main/resources/log4j2.xml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) rename annotations/basic/helloworld/src/main/java/org/springframework/integration/samples/{helloworld => systemtime}/PollerApp.java (95%) rename annotations/basic/helloworld/src/main/java/org/springframework/integration/samples/{helloworld => systemtime}/PollerConfig.java (94%) diff --git a/annotations/basic/helloworld/src/main/java/org/springframework/integration/samples/helloworld/PollerApp.java b/annotations/basic/helloworld/src/main/java/org/springframework/integration/samples/systemtime/PollerApp.java similarity index 95% rename from annotations/basic/helloworld/src/main/java/org/springframework/integration/samples/helloworld/PollerApp.java rename to annotations/basic/helloworld/src/main/java/org/springframework/integration/samples/systemtime/PollerApp.java index edeae3031..52a2e4a4a 100644 --- a/annotations/basic/helloworld/src/main/java/org/springframework/integration/samples/helloworld/PollerApp.java +++ b/annotations/basic/helloworld/src/main/java/org/springframework/integration/samples/systemtime/PollerApp.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.integration.samples.helloworld; +package org.springframework.integration.samples.systemtime; import org.springframework.context.annotation.AnnotationConfigApplicationContext; diff --git a/annotations/basic/helloworld/src/main/java/org/springframework/integration/samples/helloworld/PollerConfig.java b/annotations/basic/helloworld/src/main/java/org/springframework/integration/samples/systemtime/PollerConfig.java similarity index 94% rename from annotations/basic/helloworld/src/main/java/org/springframework/integration/samples/helloworld/PollerConfig.java rename to annotations/basic/helloworld/src/main/java/org/springframework/integration/samples/systemtime/PollerConfig.java index e642a1a96..822dfcbf4 100644 --- a/annotations/basic/helloworld/src/main/java/org/springframework/integration/samples/helloworld/PollerConfig.java +++ b/annotations/basic/helloworld/src/main/java/org/springframework/integration/samples/systemtime/PollerConfig.java @@ -1,4 +1,4 @@ -package org.springframework.integration.samples.helloworld; +package org.springframework.integration.samples.systemtime; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -62,7 +62,7 @@ public Message receive() { @Bean public IntegrationFlow systemTimeFlow(MessageChannel logger) { LoggingHandler loggingHandler = new LoggingHandler(Level.INFO); - loggingHandler.setLoggerName("org.springframework.integration.samples.helloworld"); + loggingHandler.setLoggerName("org.springframework.integration.samples.systemtime"); return IntegrationFlows .from(logger) .handle(loggingHandler) diff --git a/annotations/basic/helloworld/src/main/resources/log4j2.xml b/annotations/basic/helloworld/src/main/resources/log4j2.xml index d3292d47a..cfeafeb3e 100644 --- a/annotations/basic/helloworld/src/main/resources/log4j2.xml +++ b/annotations/basic/helloworld/src/main/resources/log4j2.xml @@ -10,7 +10,7 @@ - + From 6aa9fbef0df097dc87d6df6ad9f5c08efd63e6ee Mon Sep 17 00:00:00 2001 From: lunk djedi Date: Mon, 19 Feb 2018 14:31:32 -0500 Subject: [PATCH 5/5] Removing file example --- annotations/basic/file/README.md | 18 -- annotations/basic/file/input/file_0.txt | 1 - annotations/basic/file/input/file_1.txt | 1 - annotations/basic/file/input/file_2.txt | 1 - annotations/basic/file/input/file_3.txt | 1 - annotations/basic/file/input/file_4.txt | 1 - annotations/basic/file/pom.xml | 164 ------------------ .../samples/filecopy/BinaryConfig.java | 119 ------------- .../samples/filecopy/FileCopyDemoCommon.java | 45 ----- .../integration/samples/filecopy/Handler.java | 44 ----- .../integration/fileCopyDemo-binary.xml | 32 ---- .../spring/integration/fileCopyDemo-file.xml | 30 ---- .../spring/integration/fileCopyDemo-text.xml | 33 ---- .../samples/filecopy/BinaryFileCopyTest.java | 41 ----- .../filecopy/FileBasedFileCopyTest.java | 38 ---- .../samples/filecopy/TextFileCopyTest.java | 40 ----- .../basic/file/src/test/resources/log4j2.xml | 16 -- 17 files changed, 625 deletions(-) delete mode 100644 annotations/basic/file/README.md delete mode 100644 annotations/basic/file/input/file_0.txt delete mode 100644 annotations/basic/file/input/file_1.txt delete mode 100644 annotations/basic/file/input/file_2.txt delete mode 100644 annotations/basic/file/input/file_3.txt delete mode 100644 annotations/basic/file/input/file_4.txt delete mode 100644 annotations/basic/file/pom.xml delete mode 100644 annotations/basic/file/src/main/java/org/springframework/integration/samples/filecopy/BinaryConfig.java delete mode 100644 annotations/basic/file/src/main/java/org/springframework/integration/samples/filecopy/FileCopyDemoCommon.java delete mode 100644 annotations/basic/file/src/main/java/org/springframework/integration/samples/filecopy/Handler.java delete mode 100644 annotations/basic/file/src/main/resources/META-INF/spring/integration/fileCopyDemo-binary.xml delete mode 100644 annotations/basic/file/src/main/resources/META-INF/spring/integration/fileCopyDemo-file.xml delete mode 100644 annotations/basic/file/src/main/resources/META-INF/spring/integration/fileCopyDemo-text.xml delete mode 100644 annotations/basic/file/src/test/java/org/springframework/integration/samples/filecopy/BinaryFileCopyTest.java delete mode 100644 annotations/basic/file/src/test/java/org/springframework/integration/samples/filecopy/FileBasedFileCopyTest.java delete mode 100644 annotations/basic/file/src/test/java/org/springframework/integration/samples/filecopy/TextFileCopyTest.java delete mode 100644 annotations/basic/file/src/test/resources/log4j2.xml diff --git a/annotations/basic/file/README.md b/annotations/basic/file/README.md deleted file mode 100644 index 9f112fbce..000000000 --- a/annotations/basic/file/README.md +++ /dev/null @@ -1,18 +0,0 @@ -File Sample -=========== - -This example demonstrates the following aspects of the File operations support available with Spring Integration: - -1. File Inbound Channel Adapter -2. File Outbound Channel Adapter -3. File-to-Bytes Transformer - -Furthermore, a Poller is used as well. - -The use case is a simple file copy, but implemented in 3 basic flavors: - -1. Binary file copy -2. Text file copy -3. Simple file copy - -To run the samples simply execute the 3 test cases located in the **org.springframework.integration.samples.filecopy** package. \ No newline at end of file diff --git a/annotations/basic/file/input/file_0.txt b/annotations/basic/file/input/file_0.txt deleted file mode 100644 index a3f6e274e..000000000 --- a/annotations/basic/file/input/file_0.txt +++ /dev/null @@ -1 +0,0 @@ -hello 0 \ No newline at end of file diff --git a/annotations/basic/file/input/file_1.txt b/annotations/basic/file/input/file_1.txt deleted file mode 100644 index a4f3ad55f..000000000 --- a/annotations/basic/file/input/file_1.txt +++ /dev/null @@ -1 +0,0 @@ -hello 1 \ No newline at end of file diff --git a/annotations/basic/file/input/file_2.txt b/annotations/basic/file/input/file_2.txt deleted file mode 100644 index b20684db6..000000000 --- a/annotations/basic/file/input/file_2.txt +++ /dev/null @@ -1 +0,0 @@ -hello 2 \ No newline at end of file diff --git a/annotations/basic/file/input/file_3.txt b/annotations/basic/file/input/file_3.txt deleted file mode 100644 index 7059d70f8..000000000 --- a/annotations/basic/file/input/file_3.txt +++ /dev/null @@ -1 +0,0 @@ -hello 3 \ No newline at end of file diff --git a/annotations/basic/file/input/file_4.txt b/annotations/basic/file/input/file_4.txt deleted file mode 100644 index cd1c078e0..000000000 --- a/annotations/basic/file/input/file_4.txt +++ /dev/null @@ -1 +0,0 @@ -hello 4 \ No newline at end of file diff --git a/annotations/basic/file/pom.xml b/annotations/basic/file/pom.xml deleted file mode 100644 index c46de86af..000000000 --- a/annotations/basic/file/pom.xml +++ /dev/null @@ -1,164 +0,0 @@ - - - 4.0.0 - org.springframework.integration.samples - file - 5.0.0.BUILD-SNAPSHOT - File Copy Basic Sample - File Copy Basic Sample - http://projects.spring.io/spring-integration - - SpringIO - https://spring.io - - - - The Apache Software License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - repo - - - - - garyrussell - Gary Russell - grussell@pivotal.io - - project lead - - - - markfisher - Mark Fisher - mfisher@pivotal.io - - project founder and lead emeritus - - - - ghillert - Gunnar Hillert - ghillert@pivotal.io - - - abilan - Artem Bilan - abilan@pivotal.io - - - - scm:git:scm:git:git://github.com/spring-projects/spring-integration-samples.git - scm:git:scm:git:ssh://git@github.com:spring-projects/spring-integration-samples.git - https://github.com/spring-projects/spring-integration-samples - - - - org.springframework.integration - spring-integration-file - compile - - - jackson-module-kotlin - com.fasterxml.jackson.module - - - - - org.apache.logging.log4j - log4j-core - 2.7 - compile - - - jackson-module-kotlin - com.fasterxml.jackson.module - - - - - junit - junit - 4.12 - test - - - jackson-module-kotlin - com.fasterxml.jackson.module - - - * - org.hamcrest - - - - - org.hamcrest - hamcrest-all - 1.3 - test - - - jackson-module-kotlin - com.fasterxml.jackson.module - - - - - org.mockito - mockito-core - 2.10.0 - test - - - jackson-module-kotlin - com.fasterxml.jackson.module - - - * - org.hamcrest - - - - - org.springframework - spring-test - test - - - jackson-module-kotlin - com.fasterxml.jackson.module - - - - - - - repo.spring.io.milestone - Spring Framework Maven Milestone Repository - https://repo.spring.io/libs-milestone - - - repo.spring.io.snapshot - Spring Framework Maven Snapshot Repository - https://repo.spring.io/libs-snapshot - - - - - - org.springframework.integration - spring-integration-bom - 5.0.0.M7 - import - pom - - - org.springframework - spring-framework-bom - 5.0.0.RC4 - import - pom - - - - diff --git a/annotations/basic/file/src/main/java/org/springframework/integration/samples/filecopy/BinaryConfig.java b/annotations/basic/file/src/main/java/org/springframework/integration/samples/filecopy/BinaryConfig.java deleted file mode 100644 index 538b49c67..000000000 --- a/annotations/basic/file/src/main/java/org/springframework/integration/samples/filecopy/BinaryConfig.java +++ /dev/null @@ -1,119 +0,0 @@ -package org.springframework.integration.samples.filecopy; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.util.Map; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.PropertySource; -import org.springframework.context.annotation.PropertySources; -import org.springframework.integration.annotation.InboundChannelAdapter; -import org.springframework.integration.core.MessageSource; -import org.springframework.integration.dsl.IntegrationFlow; -import org.springframework.integration.dsl.IntegrationFlows; -import org.springframework.integration.dsl.channel.MessageChannels; -import org.springframework.integration.file.FileReadingMessageSource; -import org.springframework.integration.file.FileWritingMessageHandler; -import org.springframework.integration.handler.GenericHandler; -import org.springframework.integration.scheduling.PollerMetadata; -import org.springframework.integration.transformer.GenericTransformer; -import org.springframework.messaging.MessageChannel; -import org.springframework.scheduling.support.PeriodicTrigger; - -/** - * - - - - - - - - * - */ -@Configuration -public class BinaryConfig { - - @Value("${java.io.tmpdir}") - private String tmpDir; - - /** - * - */ - @Bean - @InboundChannelAdapter - public MessageSource filesIn() { - FileReadingMessageSource source = new FileReadingMessageSource(); - source.setDirectory(new File(tmpDir + "/spring-integration-samples/input")); - return source; - } - - /** - * - */ - @Bean - public MessageChannel bytes() { - return MessageChannels.direct().get(); - } - - /** - * - * - * - * - */ - @Bean - public IntegrationFlow copyFlow(@Autowired final Handler handler) { - return IntegrationFlows.from("filesIn") - .transform(new GenericTransformer() { - public byte[] transform(File source) { - try { - return Files.readAllBytes(source.toPath()); - } catch (IOException e) { - e.printStackTrace(); - } - return null; - } - }).handle(new GenericHandler() { - public Object handle(byte[] payload, Map headers) { - return handler.handleBytes(payload); - } - }).handle(new GenericHandler(){ - - public Object handle(byte[] payload, Map headers) { - FileWritingMessageHandler handler = new FileWritingMessageHandler(new File(tmpDir + "/spring-integration-samples/output")); - handler.setDeleteSourceFiles(true); - handler.start(); - return handler; - } - - }).get(); - } - - /** - * - */ - @Bean - public Handler handler() { - return new Handler(); - } - - /** - * - */ - @Bean(name = PollerMetadata.DEFAULT_POLLER) - public PollerMetadata defaultPoller() { - PollerMetadata pollerMetadata = new PollerMetadata(); - pollerMetadata.setTrigger(new PeriodicTrigger(1000)); - return pollerMetadata; - } -} diff --git a/annotations/basic/file/src/main/java/org/springframework/integration/samples/filecopy/FileCopyDemoCommon.java b/annotations/basic/file/src/main/java/org/springframework/integration/samples/filecopy/FileCopyDemoCommon.java deleted file mode 100644 index 627c5b276..000000000 --- a/annotations/basic/file/src/main/java/org/springframework/integration/samples/filecopy/FileCopyDemoCommon.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2002-2012 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.samples.filecopy; - -import java.io.File; - -import org.springframework.beans.DirectFieldAccessor; -import org.springframework.context.ApplicationContext; -import org.springframework.expression.common.LiteralExpression; -import org.springframework.integration.file.FileReadingMessageSource; -import org.springframework.integration.file.FileWritingMessageHandler; - -/** - * Displays the names of the input and output directories. - * - * @author Marius Bogoevici - * @author Mark Fisher - * @author Gary Russell - */ -public class FileCopyDemoCommon { - - public static void displayDirectories(ApplicationContext context) { - File inDir = (File) new DirectFieldAccessor(context.getBean(FileReadingMessageSource.class)).getPropertyValue("directory"); - LiteralExpression expression = (LiteralExpression) new DirectFieldAccessor(context.getBean(FileWritingMessageHandler.class)).getPropertyValue("destinationDirectoryExpression"); - File outDir = new File(expression.getValue()); - System.out.println("Input directory is: " + inDir.getAbsolutePath()); - System.out.println("Output directory is: " + outDir.getAbsolutePath()); - System.out.println("==================================================="); - } - -} diff --git a/annotations/basic/file/src/main/java/org/springframework/integration/samples/filecopy/Handler.java b/annotations/basic/file/src/main/java/org/springframework/integration/samples/filecopy/Handler.java deleted file mode 100644 index 8fb30246c..000000000 --- a/annotations/basic/file/src/main/java/org/springframework/integration/samples/filecopy/Handler.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2002-2010 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.samples.filecopy; - -import java.io.File; - -/** - * A class providing several handling methods for different types of payloads. - * - * @author Mark Fisher - * @author Marius Bogoevici - */ -public class Handler { - - public String handleString(String input) { - System.out.println("Copying text: " + input); - return input.toUpperCase(); - } - - public File handleFile(File input) { - System.out.println("Copying file: " + input.getAbsolutePath()); - return input; - } - - public byte[] handleBytes(byte[] input) { - System.out.println("Copying " + input.length + " bytes ..."); - return new String(input).toUpperCase().getBytes(); - } - -} diff --git a/annotations/basic/file/src/main/resources/META-INF/spring/integration/fileCopyDemo-binary.xml b/annotations/basic/file/src/main/resources/META-INF/spring/integration/fileCopyDemo-binary.xml deleted file mode 100644 index 0bbe7a295..000000000 --- a/annotations/basic/file/src/main/resources/META-INF/spring/integration/fileCopyDemo-binary.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/annotations/basic/file/src/main/resources/META-INF/spring/integration/fileCopyDemo-file.xml b/annotations/basic/file/src/main/resources/META-INF/spring/integration/fileCopyDemo-file.xml deleted file mode 100644 index 64d7d7ab4..000000000 --- a/annotations/basic/file/src/main/resources/META-INF/spring/integration/fileCopyDemo-file.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/annotations/basic/file/src/main/resources/META-INF/spring/integration/fileCopyDemo-text.xml b/annotations/basic/file/src/main/resources/META-INF/spring/integration/fileCopyDemo-text.xml deleted file mode 100644 index 0ad635a7e..000000000 --- a/annotations/basic/file/src/main/resources/META-INF/spring/integration/fileCopyDemo-text.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/annotations/basic/file/src/test/java/org/springframework/integration/samples/filecopy/BinaryFileCopyTest.java b/annotations/basic/file/src/test/java/org/springframework/integration/samples/filecopy/BinaryFileCopyTest.java deleted file mode 100644 index 3ace08790..000000000 --- a/annotations/basic/file/src/test/java/org/springframework/integration/samples/filecopy/BinaryFileCopyTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2002-2010 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.samples.filecopy; - -import org.junit.Test; -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; - -/** - * Demonstrating the file copy scenario using binary file source and target. - * See the 'fileCopyDemo-binary.xml' configuration file for details. Notice - * that the transformer is configured to delete the source File after it - * extracts the content as a byte array. - * - * @author Marius Bogoevici - */ -public class BinaryFileCopyTest { - - @Test - public void testBinaryCopy() throws Exception{ - ApplicationContext context = //new ClassPathXmlApplicationContext("/META-INF/spring/integration/fileCopyDemo-binary.xml", BinaryFileCopyTest.class); - new AnnotationConfigApplicationContext(BinaryConfig.class); - FileCopyDemoCommon.displayDirectories(context); - Thread.sleep(60000); - } - -} diff --git a/annotations/basic/file/src/test/java/org/springframework/integration/samples/filecopy/FileBasedFileCopyTest.java b/annotations/basic/file/src/test/java/org/springframework/integration/samples/filecopy/FileBasedFileCopyTest.java deleted file mode 100644 index e123eb085..000000000 --- a/annotations/basic/file/src/test/java/org/springframework/integration/samples/filecopy/FileBasedFileCopyTest.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2002-2010 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.samples.filecopy; - -import org.junit.Test; -import org.springframework.context.ApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; - -/** - * Demonstrating the file copy scenario using file-based source and target. - * See the 'fileCopyDemo-file.xml' configuration file for details. - * - * @author Marius Bogoevici - */ -public class FileBasedFileCopyTest { - - @Test - public void testFileBasedCopy() throws Exception{ - ApplicationContext context = new ClassPathXmlApplicationContext("/META-INF/spring/integration/fileCopyDemo-file.xml", FileBasedFileCopyTest.class); - FileCopyDemoCommon.displayDirectories(context); - Thread.sleep(5000); - } - -} diff --git a/annotations/basic/file/src/test/java/org/springframework/integration/samples/filecopy/TextFileCopyTest.java b/annotations/basic/file/src/test/java/org/springframework/integration/samples/filecopy/TextFileCopyTest.java deleted file mode 100644 index 2ff35e688..000000000 --- a/annotations/basic/file/src/test/java/org/springframework/integration/samples/filecopy/TextFileCopyTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2002-2010 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.samples.filecopy; - -import org.junit.Test; -import org.springframework.context.ApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; - -/** - * Demonstrating the file copy scenario using text-based source and target. - * See the 'fileCopyDemo-text.xml' configuration file for details. - * - * @author Mark Fisher - * @author Marius Bogoevici - */ -public class TextFileCopyTest { - - @Test - public void testTextBasedCopy() throws Exception{ - ApplicationContext context = new ClassPathXmlApplicationContext("/META-INF/spring/integration/fileCopyDemo-text.xml", TextFileCopyTest.class); - FileCopyDemoCommon.displayDirectories(context); - Thread.sleep(5000); - } - -} - diff --git a/annotations/basic/file/src/test/resources/log4j2.xml b/annotations/basic/file/src/test/resources/log4j2.xml deleted file mode 100644 index 6241eb502..000000000 --- a/annotations/basic/file/src/test/resources/log4j2.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - -