Upgrade to Spring Integration 6.0.0-RC1
* Also upgrade other deps to more actual * Fix failing tests due to changed API
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.samples.sftp;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
@@ -21,7 +22,8 @@ import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.apache.sshd.sftp.client.SftpClient;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
@@ -32,8 +34,6 @@ import org.springframework.integration.file.remote.session.SessionFactory;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.PollableChannel;
|
||||
|
||||
import com.jcraft.jsch.ChannelSftp.LsEntry;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Gary Russell
|
||||
@@ -42,10 +42,10 @@ import com.jcraft.jsch.ChannelSftp.LsEntry;
|
||||
public class SftpInboundReceiveSample {
|
||||
|
||||
@Test
|
||||
public void runDemo(){
|
||||
public void runDemo() {
|
||||
ConfigurableApplicationContext context =
|
||||
new ClassPathXmlApplicationContext("/META-INF/spring/integration/SftpInboundReceiveSample-context.xml", this.getClass());
|
||||
RemoteFileTemplate<LsEntry> template = null;
|
||||
RemoteFileTemplate<SftpClient.DirEntry> template = null;
|
||||
String file1 = "a.txt";
|
||||
String file2 = "b.txt";
|
||||
String file3 = "c.bar";
|
||||
@@ -54,8 +54,8 @@ public class SftpInboundReceiveSample {
|
||||
try {
|
||||
PollableChannel localFileChannel = context.getBean("receiveChannel", PollableChannel.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
SessionFactory<LsEntry> sessionFactory = context.getBean(CachingSessionFactory.class);
|
||||
template = new RemoteFileTemplate<LsEntry>(sessionFactory);
|
||||
SessionFactory<SftpClient.DirEntry> sessionFactory = context.getBean(CachingSessionFactory.class);
|
||||
template = new RemoteFileTemplate<>(sessionFactory);
|
||||
SftpTestUtils.createTestFiles(template, file1, file2, file3);
|
||||
|
||||
SourcePollingChannelAdapter adapter = context.getBean(SourcePollingChannelAdapter.class);
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.samples.sftp;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -21,7 +22,8 @@ import static org.junit.Assert.assertTrue;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.apache.sshd.sftp.client.SftpClient;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
@@ -29,23 +31,23 @@ import org.springframework.integration.file.remote.RemoteFileTemplate;
|
||||
import org.springframework.integration.file.remote.session.CachingSessionFactory;
|
||||
import org.springframework.integration.file.remote.session.SessionFactory;
|
||||
|
||||
import com.jcraft.jsch.ChannelSftp.LsEntry;
|
||||
|
||||
/**
|
||||
* Demonstrates use of the outbound gateway to use ls, get and rm.
|
||||
* Creates a temporary directory with 2 files; retrieves and removes them.
|
||||
*
|
||||
* @author Gary Russell
|
||||
*
|
||||
* @since 2.1
|
||||
*
|
||||
*/
|
||||
public class SftpOutboundGatewaySample {
|
||||
|
||||
@Test
|
||||
public void testLsGetRm() throws Exception {
|
||||
public void testLsGetRm() {
|
||||
ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(
|
||||
"classpath:/META-INF/spring/integration/SftpOutboundGatewaySample-context.xml");
|
||||
ToSftpFlowGateway toFtpFlow = ctx.getBean(ToSftpFlowGateway.class);
|
||||
RemoteFileTemplate<LsEntry> template = null;
|
||||
RemoteFileTemplate<SftpClient.DirEntry> template = null;
|
||||
String file1 = "1.ftptest";
|
||||
String file2 = "2.ftptest";
|
||||
File tmpDir = new File(System.getProperty("java.io.tmpdir"));
|
||||
@@ -56,8 +58,8 @@ public class SftpOutboundGatewaySample {
|
||||
new File(tmpDir, file2).delete();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
SessionFactory<LsEntry> sessionFactory = ctx.getBean(CachingSessionFactory.class);
|
||||
template = new RemoteFileTemplate<LsEntry>(sessionFactory);
|
||||
SessionFactory<SftpClient.DirEntry> sessionFactory = ctx.getBean(CachingSessionFactory.class);
|
||||
template = new RemoteFileTemplate<>(sessionFactory);
|
||||
SftpTestUtils.createTestFiles(template, file1, file2);
|
||||
|
||||
// execute the flow (ls, get, rm, aggregate results)
|
||||
@@ -80,6 +82,3 @@ public class SftpOutboundGatewaySample {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -18,7 +18,8 @@ package org.springframework.integration.samples.sftp;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.apache.sshd.sftp.client.SftpClient;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.file.remote.RemoteFileTemplate;
|
||||
@@ -29,8 +30,6 @@ import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.jcraft.jsch.ChannelSftp.LsEntry;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Oleg Zhurakousky
|
||||
@@ -41,17 +40,17 @@ import com.jcraft.jsch.ChannelSftp.LsEntry;
|
||||
public class SftpOutboundTransferSample {
|
||||
|
||||
@Test
|
||||
public void testOutbound() throws Exception{
|
||||
public void testOutbound() throws Exception {
|
||||
|
||||
final String sourceFileName = "README.md";
|
||||
final String destinationFileName = sourceFileName +"_foo";
|
||||
final String destinationFileName = sourceFileName + "_foo";
|
||||
|
||||
final ClassPathXmlApplicationContext ac =
|
||||
new ClassPathXmlApplicationContext("/META-INF/spring/integration/SftpOutboundTransferSample-context.xml",
|
||||
SftpOutboundTransferSample.class);
|
||||
new ClassPathXmlApplicationContext("/META-INF/spring/integration/SftpOutboundTransferSample-context.xml",
|
||||
SftpOutboundTransferSample.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
SessionFactory<LsEntry> sessionFactory = ac.getBean(CachingSessionFactory.class);
|
||||
RemoteFileTemplate<LsEntry> template = new RemoteFileTemplate<LsEntry>(sessionFactory);
|
||||
SessionFactory<SftpClient.DirEntry> sessionFactory = ac.getBean(CachingSessionFactory.class);
|
||||
RemoteFileTemplate<SftpClient.DirEntry> template = new RemoteFileTemplate<>(sessionFactory);
|
||||
SftpTestUtils.createTestFiles(template); // Just the directory
|
||||
|
||||
try {
|
||||
|
||||
@@ -22,14 +22,11 @@ import static org.hamcrest.Matchers.containsString;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.sshd.sftp.client.SftpClient;
|
||||
|
||||
import org.springframework.integration.file.remote.RemoteFileTemplate;
|
||||
import org.springframework.integration.file.remote.SessionCallback;
|
||||
|
||||
import com.jcraft.jsch.ChannelSftp;
|
||||
import com.jcraft.jsch.ChannelSftp.LsEntry;
|
||||
import com.jcraft.jsch.SftpATTRS;
|
||||
import com.jcraft.jsch.SftpException;
|
||||
|
||||
/**
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
@@ -39,10 +36,10 @@ import com.jcraft.jsch.SftpException;
|
||||
*/
|
||||
public class SftpTestUtils {
|
||||
|
||||
public static void createTestFiles(RemoteFileTemplate<LsEntry> template, final String... fileNames) {
|
||||
public static void createTestFiles(RemoteFileTemplate<SftpClient.DirEntry> template, final String... fileNames) {
|
||||
if (template != null) {
|
||||
final ByteArrayInputStream stream = new ByteArrayInputStream("foo".getBytes());
|
||||
template.execute((SessionCallback<LsEntry, Void>) session -> {
|
||||
template.execute((SessionCallback<SftpClient.DirEntry, Void>) session -> {
|
||||
try {
|
||||
session.mkdir("si.sftp.sample");
|
||||
}
|
||||
@@ -58,14 +55,15 @@ public class SftpTestUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static void cleanUp(RemoteFileTemplate<LsEntry> template, final String... fileNames) {
|
||||
public static void cleanUp(RemoteFileTemplate<SftpClient.DirEntry> template, final String... fileNames) {
|
||||
if (template != null) {
|
||||
template.execute((SessionCallback<LsEntry, Void>) session -> {
|
||||
template.execute((SessionCallback<SftpClient.DirEntry, Void>) session -> {
|
||||
for (int i = 0; i < fileNames.length; i++) {
|
||||
try {
|
||||
session.remove("si.sftp.sample/" + fileNames[i]);
|
||||
}
|
||||
catch (IOException e) {}
|
||||
catch (IOException e) {
|
||||
}
|
||||
}
|
||||
|
||||
// should be empty
|
||||
@@ -75,20 +73,20 @@ public class SftpTestUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean fileExists(RemoteFileTemplate<LsEntry> template, final String... fileNames) {
|
||||
public static boolean fileExists(RemoteFileTemplate<SftpClient.DirEntry> template, final String... fileNames) {
|
||||
if (template != null) {
|
||||
return template.execute(session -> {
|
||||
ChannelSftp channel = (ChannelSftp) session.getClientInstance();
|
||||
for (int i = 0; i < fileNames.length; i++) {
|
||||
SftpClient channel = (SftpClient) session.getClientInstance();
|
||||
for (String fileName : fileNames) {
|
||||
try {
|
||||
SftpATTRS stat = channel.stat("si.sftp.sample/" + fileNames[i]);
|
||||
var stat = channel.stat("si.sftp.sample/" + fileName);
|
||||
if (stat == null) {
|
||||
System.out.println("stat returned null for " + fileNames[i]);
|
||||
System.out.println("stat returned null for " + fileName);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (SftpException e) {
|
||||
System.out.println("Remote file not present: " + e.getMessage() + ": " + fileNames[i]);
|
||||
catch (IOException e) {
|
||||
System.out.println("Remote file not present: " + e.getMessage() + ": " + fileName);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user