INTSAMPLES-15 added FTP sample

This commit is contained in:
Oleg Zhurakousky
2010-11-18 11:12:35 -05:00
parent 45f865e34f
commit 8544307d06
25 changed files with 360 additions and 6 deletions

8
basic/ftp/.classpath Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

2
basic/ftp/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
/local-target-dir
/target

23
basic/ftp/.project Normal file
View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ftp</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.maven.ide.eclipse.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.maven.ide.eclipse.maven2Nature</nature>
</natures>
</projectDescription>

View File

@@ -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=<?xml version\="1.0" encoding\="UTF-8"?>\n<graph>\n<element clazz\="InboundChannelAdapterModelElement" type\="inbound-channel-adapter">\n<structure end\="1682" endstart\="1648" start\="1334" startend\="1611"/>\n<bounds height\="112" width\="116" x\="19" y\="17"/>\n</element>\n<element clazz\="ChannelModelElement" type\="channel">\n<structure end\="1749" endstart\="1735" start\="1689" startend\="1718"/>\n<bounds height\="112" width\="116" x\="155" y\="83"/>\n</element>\n</graph>
//com.springsource.sts.config.flow.coordinates\:http\://www.springframework.org/schema/integration\:/ftp/src/test/resources/META-INF/spring/integration/FtpOutboundChannelAdapterSample-context.xml=<?xml version\="1.0" encoding\="UTF-8"?>\n<graph>\n<element clazz\="ChannelModelElement" type\="channel">\n<structure end\="1363" endstart\="1363" start\="1333" startend\="1363"/>\n<bounds height\="112" width\="116" x\="19" y\="17"/>\n</element>\n<element clazz\="OutboundChannelAdapterModelElement" type\="outbound-channel-adapter">\n<structure end\="1482" endstart\="1482" start\="1366" startend\="1482"/>\n<bounds height\="112" width\="116" x\="155" y\="17"/>\n</element>\n</graph>
eclipse.preferences.version=1

View File

@@ -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

View File

@@ -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

63
basic/ftp/pom.xml Normal file
View File

@@ -0,0 +1,63 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.integration.samples</groupId>
<artifactId>ftp</artifactId>
<version>2.0.0</version>
<name>FTP Demo</name>
<packaging>jar</packaging>
<properties>
<spring.integration.version>2.0.0.BUILD-SNAPSHOT</spring.integration.version>
<log4j.version>1.2.16</log4j.version>
<junit.version>4.7</junit.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-ftp</artifactId>
<version>${spring.integration.version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<!-- test-scoped dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>false</showDeprecation>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>repository.springframework.maven.release</id>
<name>Spring Framework Maven Release Repository</name>
<url>http://maven.springframework.org/release</url>
</repository>
<repository>
<id>repository.springframework.maven.milestone</id>
<name>Spring Framework Maven Milestone Repository</name>
<url>http://maven.springframework.org/milestone</url>
</repository>
<repository>
<id>repository.springframework.maven.snapshot</id>
<name>Spring Framework Maven Snapshot Repository</name>
<url>http://maven.springframework.org/snapshot</url>
</repository>
</repositories>
</project>

26
basic/ftp/readme.txt Normal file
View File

@@ -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'
=====

View File

@@ -0,0 +1 @@
A

View File

View File

View File

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

View File

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

View File

@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-ftp="http://www.springframework.org/schema/integration/ftp"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/integration/ftp http://www.springframework.org/schema/integration/ftp/spring-integration-ftp-2.0.xsd">
<context:property-placeholder location="classpath:user.properties"/>
<bean id="ftpClientFactory" class="org.springframework.integration.ftp.client.DefaultFtpClientFactory">
<property name="host" value="localhost"/>
<property name="username" value="${user}"/>
<property name="password" value="${password}"/>
<property name="remoteWorkingDirectory" value="<SPECIFY REMOTE DIRECTORY (e.g., /{workspace}/samples/basic/ftp/remote-source-dir)"/>
</bean>
<int-ftp:inbound-channel-adapter id="ftpInbound"
channel="ftpChannel"
client-factory="ftpClientFactory"
filename-pattern=".*\.txt$"
auto-create-directories="true"
auto-delete-remote-files-on-sync="false"
local-working-directory="file:local-target-dir">
<int:poller fixed-rate="1000"/>
</int-ftp:inbound-channel-adapter>
<int:channel id="ftpChannel">
<int:queue/>
</int:channel>
</beans>

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-ftp="http://www.springframework.org/schema/integration/ftp"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/integration/ftp http://www.springframework.org/schema/integration/ftp/spring-integration-ftp-2.0.xsd">
<context:property-placeholder location="classpath:user.properties"/>
<bean id="ftpClientFactory" class="org.springframework.integration.ftp.client.DefaultFtpClientFactory">
<property name="host" value="localhost"/>
<property name="username" value="${user}"/>
<property name="password" value="${password}"/>
<property name="remoteWorkingDirectory" value="<SPECIFY REMOTE DIRECTORY (e.g., /{workspace}/samples/basic/ftp/remote-target-dir)"/>
</bean>
<int:channel id="ftpChannel"/>
<int-ftp:outbound-channel-adapter id="ftpOutbound"
channel="ftpChannel"
client-factory="ftpClientFactory"/>
</beans>

View File

@@ -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

View File

@@ -0,0 +1,2 @@
user=
password=

View File

@@ -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=<?xml version\="1.0" encoding\="UTF-8"?>\n<graph>\n<element clazz\="InboundChannelAdapterModelElement" type\="inbound-channel-adapter">\n<structure end\="839" endstart\="809" start\="645" startend\="744"/>\n<bounds height\="112" width\="116" x\="19" y\="17"/>\n</element>\n<element clazz\="LoggingChannelAdapterModelElement" type\="logging-channel-adapter">\n<structure end\="885" endstart\="885" start\="843" startend\="885"/>\n<bounds height\="112" width\="116" x\="19" y\="149"/>\n</element>\n</graph>
eclipse.preferences.version=1

View File

@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<beansProjectDescription>
<version>1</version>
<pluginVersion><![CDATA[2.3.3.201007151000-M2]]></pluginVersion>
<pluginVersion><![CDATA[2.5.0.201010221000-RELEASE]]></pluginVersion>
<configSuffixes>
<configSuffix><![CDATA[xml]]></configSuffix>
</configSuffixes>
<enableImports><![CDATA[false]]></enableImports>
<configs>
<config>src/main/resources/META-INF/spring/integration/delay.xml</config>
</configs>
<configSets>
</configSets>

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:task="http://www.springframework.org/schema/task">
<int:inbound-channel-adapter expression="T(java.lang.System).currentTimeMillis()" channel="logger">
<int:poller fixed-delay="20000" max-messages-per-poll="2" />
</int:inbound-channel-adapter>
<int:logging-channel-adapter id="logger"/>
<task:executor id="executor" queue-capacity="20" pool-size="5-20"/>
</beans>

View File

@@ -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();
}
}

View File

@@ -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

View File

@@ -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=<?xml version\="1.0" encoding\="UTF-8"?>\n<graph>\n<element clazz\="InboundChannelAdapterModelElement" type\="inbound-channel-adapter">\n<structure end\="1954" endstart\="1919" start\="1487" startend\="1857"/>\n<bounds height\="112" width\="116" x\="19" y\="17"/>\n</element>\n<element clazz\="ChannelModelElement" type\="channel">\n<structure end\="2022" endstart\="2008" start\="1958" startend\="1991"/>\n<bounds height\="112" width\="116" x\="155" y\="17"/>\n</element>\n</graph>
//com.springsource.sts.config.flow.coordinates\:http\://www.springframework.org/schema/integration\:/sftp/src/test/resources/META-INF/spring/integration/SftpInboundReceiveSample-context.xml=<?xml version\="1.0" encoding\="UTF-8"?>\n<graph>\n<element clazz\="InboundChannelAdapterModelElement" type\="inbound-channel-adapter">\n<structure end\="1961" endstart\="1926" start\="1487" startend\="1864"/>\n<bounds height\="112" width\="116" x\="19" y\="17"/>\n</element>\n<element clazz\="ChannelModelElement" type\="channel">\n<structure end\="2029" endstart\="2015" start\="1965" startend\="1998"/>\n<bounds height\="112" width\="116" x\="155" y\="17"/>\n</element>\n</graph>
//com.springsource.sts.config.flow.coordinates\:http\://www.springframework.org/schema/integration\:/sftp/src/test/resources/META-INF/spring/integration/SftpOutboundTransferSample-context.xml=<?xml version\="1.0" encoding\="UTF-8"?>\n<graph>\n<element clazz\="ChannelModelElement" type\="channel">\n<structure end\="1355" endstart\="1355" start\="1323" startend\="1355"/>\n<bounds height\="112" width\="116" x\="19" y\="17"/>\n</element>\n<element clazz\="OutboundChannelAdapterModelElement" type\="outbound-channel-adapter">\n<structure end\="1664" endstart\="1664" start\="1359" startend\="1664"/>\n<bounds height\="112" width\="116" x\="155" y\="17"/>\n</element>\n</graph>
//com.springsource.sts.config.flow.coordinates\:http\://www.springframework.org/schema/integration\:/sftp/src/test/resources/META-INF/spring/integration/SftpInboundReceiveSample-context.xml=<?xml version\="1.0" encoding\="UTF-8"?>\n<graph>\n<element clazz\="InboundChannelAdapterModelElement" type\="inbound-channel-adapter">\n<structure end\="1965" endstart\="1930" start\="1487" startend\="1868"/>\n<bounds height\="112" width\="116" x\="19" y\="17"/>\n</element>\n<element clazz\="ChannelModelElement" type\="channel">\n<structure end\="2033" endstart\="2019" start\="1969" startend\="2002"/>\n<bounds height\="112" width\="116" x\="155" y\="17"/>\n</element>\n</graph>
//com.springsource.sts.config.flow.coordinates\:http\://www.springframework.org/schema/integration\:/sftp/src/test/resources/META-INF/spring/integration/SftpOutboundTransferSample-context.xml=<?xml version\="1.0" encoding\="UTF-8"?>\n<graph>\n<element clazz\="ChannelModelElement" type\="channel">\n<structure end\="1355" endstart\="1355" start\="1323" startend\="1355"/>\n<bounds height\="112" width\="116" x\="19" y\="17"/>\n</element>\n<element clazz\="OutboundChannelAdapterModelElement" type\="outbound-channel-adapter">\n<structure end\="1666" endstart\="1666" start\="1359" startend\="1666"/>\n<bounds height\="112" width\="116" x\="155" y\="17"/>\n</element>\n</graph>
eclipse.preferences.version=1

View File

@@ -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="<<SPECIFY REMOTE DIRECTORY (e.g., /{workspace}/samples/basic/sftp/remote-target-dir)>>"
auto-create-directories="true"
auto-delete-remote-files-on-sync="false"
filename-pattern=".*\.txt$">

View File

@@ -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="<SPECIFY REMOTE DIRECTORY (e.g., /{workspace}/samples/basic/sftp/remote-target-dir)>"/>
</beans>