Skip to content

Commit

Permalink
Merge pull request spring-projects#74 from ghillert/INTSAMPLES-71
Browse files Browse the repository at this point in the history
INTSAMPLES-71 - Fix SFTP Outbound Sample
  • Loading branch information
ghillert committed Dec 4, 2012
2 parents 7c9ec6a + f4fcc22 commit 1dac2e5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
4 changes: 2 additions & 2 deletions basic/sftp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ As you can see, although the remote directory had 3 files we only received 2 sin

## OUTBOUND CHANNEL ADAPTER

To run the OUTBOUND CHANNEL ADAPTER sample execute the **SftpOutboundTransferSample** test. You will see that based on the configuration it will attempt to transfer this **readme.txt** file to a remote directory **remote-target-dir**. The output should look like this:
To run the OUTBOUND CHANNEL ADAPTER sample execute the **SftpOutboundTransferSample** test. You will see that based on the configuration it will attempt to transfer the **README.md** 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_foo'
Successfully transferred 'README.md' file to a remote location under the name 'README.md_foo'

NOTE: You can see that we are using *SpEL* via the **remote-filename-generator-expression** attribute to define the remote file name by simply appending **_foo** to the original file name.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* 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.
Expand All @@ -23,30 +23,44 @@
import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.util.Assert;

/**
*
* @author Oleg Zhurakousky
* @author Gunnar Hillert
*
*/
public class SftpOutboundTransferSample {

@Test
public void testOutbound() throws Exception{
ClassPathXmlApplicationContext ac =

final String sourceFileName = "README.md";
final String destinationFileName = sourceFileName +"_foo";
final String destinationFilePath = "remote-target-dir/" + destinationFileName;

final ClassPathXmlApplicationContext ac =
new ClassPathXmlApplicationContext("/META-INF/spring/integration/SftpOutboundTransferSample-context.xml", SftpOutboundTransferSample.class);
ac.start();
File file = new File("readme.txt");
if (file.exists()){
Message<File> message = MessageBuilder.withPayload(file).build();
MessageChannel inputChannel = ac.getBean("inputChannel", MessageChannel.class);
inputChannel.send(message);
Thread.sleep(2000);
}
if (new File("remote-target-dir/readme.txt_foo").exists()){
System.out.println("Successfully transfered 'readme.txt' file to a remote location under the name 'readme.txt_foo'");
}

final File file = new File(sourceFileName);

Assert.isTrue(file.exists(), String.format("File '%s' does not exist.", sourceFileName));

final Message<File> message = MessageBuilder.withPayload(file).build();
final MessageChannel inputChannel = ac.getBean("inputChannel", MessageChannel.class);

inputChannel.send(message);
Thread.sleep(2000);

Assert.isTrue(new File(destinationFilePath).exists(), String.format("File '%s' does not exist.", destinationFilePath));

System.out.println(String.format("Successfully transferred '%s' file to a " +
"remote location under the name '%s'", sourceFileName, destinationFileName));

ac.stop();

}

}

0 comments on commit 1dac2e5

Please sign in to comment.