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=