From 8544307d066cc700874ecaa747de55232125763d Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Thu, 18 Nov 2010 11:12:35 -0500 Subject: [PATCH] INTSAMPLES-15 added FTP sample --- basic/ftp/.classpath | 8 +++ basic/ftp/.gitignore | 2 + basic/ftp/.project | 23 +++++++ .../com.springsource.sts.config.flow.prefs | 4 ++ .../ftp/.settings/org.eclipse.jdt.core.prefs | 13 ++++ .../ftp/.settings/org.maven.ide.eclipse.prefs | 9 +++ basic/ftp/pom.xml | 63 +++++++++++++++++++ basic/ftp/readme.txt | 26 ++++++++ basic/ftp/remote-source-dir/a.txt | 1 + basic/ftp/remote-source-dir/b.txt | 0 basic/ftp/remote-source-dir/foo.bar | 0 .../ftp/FtpInboundChannelAdapterSample.java | 39 ++++++++++++ .../ftp/FtpOutboundChannelAdapterSample.java | 49 +++++++++++++++ ...FtpInboundChannelAdapterSample-context.xml | 34 ++++++++++ ...tpOutboundChannelAdapterSample-context.xml | 27 ++++++++ basic/ftp/src/test/resources/log4j.properties | 8 +++ basic/ftp/src/test/resources/user.properties | 2 + .../com.springsource.sts.config.flow.prefs | 3 + basic/helloworld/.springBeans | 3 +- .../META-INF/spring/integration/delay.xml | 18 ++++++ .../samples/helloworld/DelayerTest.java | 15 +++++ .../src/test/resources/log4j.properties | 9 +++ .../com.springsource.sts.config.flow.prefs | 6 +- .../SftpInboundReceiveSample-context.xml | 2 +- .../SftpOutboundTransferSample-context.xml | 2 +- 25 files changed, 360 insertions(+), 6 deletions(-) create mode 100644 basic/ftp/.classpath create mode 100644 basic/ftp/.gitignore create mode 100644 basic/ftp/.project create mode 100644 basic/ftp/.settings/com.springsource.sts.config.flow.prefs create mode 100644 basic/ftp/.settings/org.eclipse.jdt.core.prefs create mode 100644 basic/ftp/.settings/org.maven.ide.eclipse.prefs create mode 100644 basic/ftp/pom.xml create mode 100644 basic/ftp/readme.txt create mode 100644 basic/ftp/remote-source-dir/a.txt create mode 100644 basic/ftp/remote-source-dir/b.txt create mode 100644 basic/ftp/remote-source-dir/foo.bar create mode 100644 basic/ftp/src/test/java/org/springframework/integration/samples/ftp/FtpInboundChannelAdapterSample.java create mode 100644 basic/ftp/src/test/java/org/springframework/integration/samples/ftp/FtpOutboundChannelAdapterSample.java create mode 100644 basic/ftp/src/test/resources/META-INF/spring/integration/FtpInboundChannelAdapterSample-context.xml create mode 100644 basic/ftp/src/test/resources/META-INF/spring/integration/FtpOutboundChannelAdapterSample-context.xml create mode 100644 basic/ftp/src/test/resources/log4j.properties create mode 100644 basic/ftp/src/test/resources/user.properties create mode 100644 basic/helloworld/.settings/com.springsource.sts.config.flow.prefs create mode 100644 basic/helloworld/src/main/resources/META-INF/spring/integration/delay.xml create mode 100644 basic/helloworld/src/test/java/org/springframework/integration/samples/helloworld/DelayerTest.java create mode 100644 basic/helloworld/src/test/resources/log4j.properties diff --git a/basic/ftp/.classpath b/basic/ftp/.classpath new file mode 100644 index 00000000..caf88e10 --- /dev/null +++ b/basic/ftp/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/basic/ftp/.gitignore b/basic/ftp/.gitignore new file mode 100644 index 00000000..d9b707b8 --- /dev/null +++ b/basic/ftp/.gitignore @@ -0,0 +1,2 @@ +/local-target-dir +/target diff --git a/basic/ftp/.project b/basic/ftp/.project new file mode 100644 index 00000000..6ab1f1ed --- /dev/null +++ b/basic/ftp/.project @@ -0,0 +1,23 @@ + + + ftp + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.maven.ide.eclipse.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.maven.ide.eclipse.maven2Nature + + diff --git a/basic/ftp/.settings/com.springsource.sts.config.flow.prefs b/basic/ftp/.settings/com.springsource.sts.config.flow.prefs new file mode 100644 index 00000000..7902a13d --- /dev/null +++ b/basic/ftp/.settings/com.springsource.sts.config.flow.prefs @@ -0,0 +1,4 @@ +#Thu Nov 18 11:03:40 EST 2010 +//com.springsource.sts.config.flow.coordinates\:http\://www.springframework.org/schema/integration\:/ftp/src/test/resources/META-INF/spring/integration/FtpInboundChannelAdapterSample-context.xml=\n\n\n\n\n\n\n\n\n\n +//com.springsource.sts.config.flow.coordinates\:http\://www.springframework.org/schema/integration\:/ftp/src/test/resources/META-INF/spring/integration/FtpOutboundChannelAdapterSample-context.xml=\n\n\n\n\n\n\n\n\n\n +eclipse.preferences.version=1 diff --git a/basic/ftp/.settings/org.eclipse.jdt.core.prefs b/basic/ftp/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..a585be21 --- /dev/null +++ b/basic/ftp/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,13 @@ +#Thu Nov 18 10:16:38 EST 2010 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/basic/ftp/.settings/org.maven.ide.eclipse.prefs b/basic/ftp/.settings/org.maven.ide.eclipse.prefs new file mode 100644 index 00000000..31a57887 --- /dev/null +++ b/basic/ftp/.settings/org.maven.ide.eclipse.prefs @@ -0,0 +1,9 @@ +#Thu Nov 18 10:15:23 EST 2010 +activeProfiles= +eclipse.preferences.version=1 +fullBuildGoals=process-test-resources +includeModules=false +resolveWorkspaceProjects=true +resourceFilterGoals=process-resources resources\:testResources +skipCompilerPlugin=true +version=1 diff --git a/basic/ftp/pom.xml b/basic/ftp/pom.xml new file mode 100644 index 00000000..490ba6bd --- /dev/null +++ b/basic/ftp/pom.xml @@ -0,0 +1,63 @@ + + 4.0.0 + org.springframework.integration.samples + ftp + 2.0.0 + FTP Demo + jar + + 2.0.0.BUILD-SNAPSHOT + 1.2.16 + 4.7 + + + + org.springframework.integration + spring-integration-ftp + ${spring.integration.version} + + + log4j + log4j + ${log4j.version} + + + + junit + junit + ${junit.version} + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.5 + 1.5 + -Xlint:all + true + false + + + + + + + repository.springframework.maven.release + Spring Framework Maven Release Repository + http://maven.springframework.org/release + + + repository.springframework.maven.milestone + Spring Framework Maven Milestone Repository + http://maven.springframework.org/milestone + + + repository.springframework.maven.snapshot + Spring Framework Maven Snapshot Repository + http://maven.springframework.org/snapshot + + + \ No newline at end of file diff --git a/basic/ftp/readme.txt b/basic/ftp/readme.txt new file mode 100644 index 00000000..5c18cf70 --- /dev/null +++ b/basic/ftp/readme.txt @@ -0,0 +1,26 @@ +This example demonstrates the following aspects of the FTP support available with Spring Integration: +1. FTP Inbound Channel Adapter (transfers files from remote to local directory) +2. FTP Outbound Channel Adapter (transfers files from local to the remote directory) + + #### INBOUND CHANNEL ADAPTER #### + +To run INBOUND CHANNEL ADAPTER sample execute FtpInboundChannelAdapterSample test. You will see that based on configuration it +will access sample remote directory which contains 3 files and will attempt to transfer them to a local directory which +will be generated. Once copied the files will be sent as a payload of the message to a channel. +The output should look like this: +===== +Received first file message: [Payload=local-dir/a.txt][Headers={timestamp=1290066001349, id=9dca686a-cfd4-4d96-a1a7-761feb005e43}] +Received second file message: [Payload=local-dir/b.txt][Headers={timestamp=1290066001650, id=d33a475d-fa71-4c5b-b73e-3147969f1c6f}] +Received nothing else +===== + +As you can see, although the remote directory had 3 files we only received 2 since we were filtering only the files that end with 'txt'. + +#### OUTBOUND CHANNEL ADAPTER #### + +To run OUTBOUND CHANNEL ADAPTER sample execute FtpOutboundChannelAdapterSample test. You will see that based on configuration it +will attempt to transfer this 'readme.txt' file to a remote directory 'remote-target-dir' +The output should look like this: +===== +Successfully transfered 'readme.txt' file to a remote location under the name 'readme.txt' +===== diff --git a/basic/ftp/remote-source-dir/a.txt b/basic/ftp/remote-source-dir/a.txt new file mode 100644 index 00000000..8c7e5a66 --- /dev/null +++ b/basic/ftp/remote-source-dir/a.txt @@ -0,0 +1 @@ +A \ No newline at end of file diff --git a/basic/ftp/remote-source-dir/b.txt b/basic/ftp/remote-source-dir/b.txt new file mode 100644 index 00000000..e69de29b diff --git a/basic/ftp/remote-source-dir/foo.bar b/basic/ftp/remote-source-dir/foo.bar new file mode 100644 index 00000000..e69de29b diff --git a/basic/ftp/src/test/java/org/springframework/integration/samples/ftp/FtpInboundChannelAdapterSample.java b/basic/ftp/src/test/java/org/springframework/integration/samples/ftp/FtpInboundChannelAdapterSample.java new file mode 100644 index 00000000..a657e445 --- /dev/null +++ b/basic/ftp/src/test/java/org/springframework/integration/samples/ftp/FtpInboundChannelAdapterSample.java @@ -0,0 +1,39 @@ +/* + * 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.ftp; + +import org.junit.Test; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.integration.core.PollableChannel; + +/** + * @author Oleg Zhurakousky + * + */ +public class FtpInboundChannelAdapterSample { + + @Test + public void runDemo() throws Exception{ + ApplicationContext ac = + new ClassPathXmlApplicationContext("META-INF/spring/integration/FtpInboundChannelAdapterSample-context.xml"); + PollableChannel ftpChannel = ac.getBean("ftpChannel", PollableChannel.class); + System.out.println("Received first file message: " + ftpChannel.receive(5000)); + System.out.println("Received scond file message: " + ftpChannel.receive(5000)); + System.out.println("Received nothing else: " + ftpChannel.receive(2000)); + } +} diff --git a/basic/ftp/src/test/java/org/springframework/integration/samples/ftp/FtpOutboundChannelAdapterSample.java b/basic/ftp/src/test/java/org/springframework/integration/samples/ftp/FtpOutboundChannelAdapterSample.java new file mode 100644 index 00000000..4836f5ca --- /dev/null +++ b/basic/ftp/src/test/java/org/springframework/integration/samples/ftp/FtpOutboundChannelAdapterSample.java @@ -0,0 +1,49 @@ +/* + * 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.ftp; + +import java.io.File; + +import org.junit.Test; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.integration.Message; +import org.springframework.integration.MessageChannel; +import org.springframework.integration.support.MessageBuilder; + +/** + * @author Oleg Zhurakousky + * + */ +public class FtpOutboundChannelAdapterSample { + + @Test + public void runDemo() throws Exception{ + ApplicationContext ac = + new ClassPathXmlApplicationContext("META-INF/spring/integration/FtpOutboundChannelAdapterSample-context.xml"); + MessageChannel ftpChannel = ac.getBean("ftpChannel", MessageChannel.class); + File file = new File("readme.txt"); + if (file.exists()){ + Message message = MessageBuilder.withPayload(file).build(); + ftpChannel.send(message); + Thread.sleep(2000); + } + if (new File("remote-target-dir/readme.txt").exists()){ + System.out.println("Successfully transfered 'readme.txt' file to a remote location under the name 'readme.txt'"); + } + } +} diff --git a/basic/ftp/src/test/resources/META-INF/spring/integration/FtpInboundChannelAdapterSample-context.xml b/basic/ftp/src/test/resources/META-INF/spring/integration/FtpInboundChannelAdapterSample-context.xml new file mode 100644 index 00000000..e7fbb889 --- /dev/null +++ b/basic/ftp/src/test/resources/META-INF/spring/integration/FtpInboundChannelAdapterSample-context.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/basic/ftp/src/test/resources/META-INF/spring/integration/FtpOutboundChannelAdapterSample-context.xml b/basic/ftp/src/test/resources/META-INF/spring/integration/FtpOutboundChannelAdapterSample-context.xml new file mode 100644 index 00000000..68dd9e7a --- /dev/null +++ b/basic/ftp/src/test/resources/META-INF/spring/integration/FtpOutboundChannelAdapterSample-context.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + diff --git a/basic/ftp/src/test/resources/log4j.properties b/basic/ftp/src/test/resources/log4j.properties new file mode 100644 index 00000000..c4672eb7 --- /dev/null +++ b/basic/ftp/src/test/resources/log4j.properties @@ -0,0 +1,8 @@ +log4j.rootCategory=WARN, stdout + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %t %c{2}:%L - %m%n + +log4j.category.org.springframework=WARN +log4j.category.org.springframework.integration=DEBUG diff --git a/basic/ftp/src/test/resources/user.properties b/basic/ftp/src/test/resources/user.properties new file mode 100644 index 00000000..5c164817 --- /dev/null +++ b/basic/ftp/src/test/resources/user.properties @@ -0,0 +1,2 @@ +user= +password= \ No newline at end of file diff --git a/basic/helloworld/.settings/com.springsource.sts.config.flow.prefs b/basic/helloworld/.settings/com.springsource.sts.config.flow.prefs new file mode 100644 index 00000000..cd4d1f4e --- /dev/null +++ b/basic/helloworld/.settings/com.springsource.sts.config.flow.prefs @@ -0,0 +1,3 @@ +#Thu Nov 18 09:56:50 EST 2010 +//com.springsource.sts.config.flow.coordinates\:http\://www.springframework.org/schema/integration\:/helloworld/src/main/resources/META-INF/spring/integration/delay.xml=\n\n\n\n\n\n\n\n\n\n +eclipse.preferences.version=1 diff --git a/basic/helloworld/.springBeans b/basic/helloworld/.springBeans index 15608f30..ef93bb0e 100644 --- a/basic/helloworld/.springBeans +++ b/basic/helloworld/.springBeans @@ -1,12 +1,13 @@ 1 - + + src/main/resources/META-INF/spring/integration/delay.xml diff --git a/basic/helloworld/src/main/resources/META-INF/spring/integration/delay.xml b/basic/helloworld/src/main/resources/META-INF/spring/integration/delay.xml new file mode 100644 index 00000000..3eb8f2a7 --- /dev/null +++ b/basic/helloworld/src/main/resources/META-INF/spring/integration/delay.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + diff --git a/basic/helloworld/src/test/java/org/springframework/integration/samples/helloworld/DelayerTest.java b/basic/helloworld/src/test/java/org/springframework/integration/samples/helloworld/DelayerTest.java new file mode 100644 index 00000000..71b98e59 --- /dev/null +++ b/basic/helloworld/src/test/java/org/springframework/integration/samples/helloworld/DelayerTest.java @@ -0,0 +1,15 @@ +package org.springframework.integration.samples.helloworld; + +import org.springframework.context.support.ClassPathXmlApplicationContext; + +public class DelayerTest { + + /** + * @param args + */ + public static void main(String[] args) throws Exception{ + new ClassPathXmlApplicationContext("META-INF/spring/integration/delay.xml"); + System.in.read(); + } + +} diff --git a/basic/helloworld/src/test/resources/log4j.properties b/basic/helloworld/src/test/resources/log4j.properties new file mode 100644 index 00000000..eb601e8e --- /dev/null +++ b/basic/helloworld/src/test/resources/log4j.properties @@ -0,0 +1,9 @@ +log4j.rootCategory=WARN, stdout + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %t %c{2}:%L - %m%n + +#log4j.category.org.springframework=WARN +#log4j.category.org.springframework.integration.sftp=TRACE +log4j.category.org.springframework=TRACE diff --git a/basic/sftp/.settings/com.springsource.sts.config.flow.prefs b/basic/sftp/.settings/com.springsource.sts.config.flow.prefs index 3371fee7..f684bb84 100644 --- a/basic/sftp/.settings/com.springsource.sts.config.flow.prefs +++ b/basic/sftp/.settings/com.springsource.sts.config.flow.prefs @@ -1,5 +1,5 @@ -#Thu Nov 18 08:44:54 EST 2010 +#Thu Nov 18 10:25:46 EST 2010 //com.springsource.sts.config.flow.coordinates\:http\://www.springframework.org/schema/integration\:/sftp/src/main/resources/META-INF/spring/integration/SftpInboundReceiveSample-context.xml=\n\n\n\n\n\n\n\n\n\n -//com.springsource.sts.config.flow.coordinates\:http\://www.springframework.org/schema/integration\:/sftp/src/test/resources/META-INF/spring/integration/SftpInboundReceiveSample-context.xml=\n\n\n\n\n\n\n\n\n\n -//com.springsource.sts.config.flow.coordinates\:http\://www.springframework.org/schema/integration\:/sftp/src/test/resources/META-INF/spring/integration/SftpOutboundTransferSample-context.xml=\n\n\n\n\n\n\n\n\n\n +//com.springsource.sts.config.flow.coordinates\:http\://www.springframework.org/schema/integration\:/sftp/src/test/resources/META-INF/spring/integration/SftpInboundReceiveSample-context.xml=\n\n\n\n\n\n\n\n\n\n +//com.springsource.sts.config.flow.coordinates\:http\://www.springframework.org/schema/integration\:/sftp/src/test/resources/META-INF/spring/integration/SftpOutboundTransferSample-context.xml=\n\n\n\n\n\n\n\n\n\n eclipse.preferences.version=1 diff --git a/basic/sftp/src/test/resources/META-INF/spring/integration/SftpInboundReceiveSample-context.xml b/basic/sftp/src/test/resources/META-INF/spring/integration/SftpInboundReceiveSample-context.xml index 3cd6ac05..98495e7c 100644 --- a/basic/sftp/src/test/resources/META-INF/spring/integration/SftpInboundReceiveSample-context.xml +++ b/basic/sftp/src/test/resources/META-INF/spring/integration/SftpInboundReceiveSample-context.xml @@ -25,7 +25,7 @@ channel="receiveChannel" session-factory="sftpSessionFactory" local-directory="file:local-dir" - remote-directory="/Users/ozhurakousky/workspace-sts-2.3.3.M2/si/samples/basic/sftp/remote-source-dir" + remote-directory="<>" auto-create-directories="true" auto-delete-remote-files-on-sync="false" filename-pattern=".*\.txt$"> diff --git a/basic/sftp/src/test/resources/META-INF/spring/integration/SftpOutboundTransferSample-context.xml b/basic/sftp/src/test/resources/META-INF/spring/integration/SftpOutboundTransferSample-context.xml index 21b72981..9e755957 100644 --- a/basic/sftp/src/test/resources/META-INF/spring/integration/SftpOutboundTransferSample-context.xml +++ b/basic/sftp/src/test/resources/META-INF/spring/integration/SftpOutboundTransferSample-context.xml @@ -25,6 +25,6 @@ session-factory="sftpSessionFactory" channel="inputChannel" remote-filename-generator-expression="payload.getName() + '_foo'" - remote-directory="/Users/ozhurakousky/workspace-sts-2.3.3.M2/si/samples/basic/sftp/remote-target-dir"/> + remote-directory=""/>