INT-3091 Fix Concurrent (S)FTP Transfers
byte[] and String payloads were written to a temporary file. If the same message is transferred to two different destinations concurrently, one of the adapters could remove the temporary file while the other was using it. Don't use a temporary file for these payloads, simply use the payload byte[] [or a String.getBytes()] as the InputStream passed to the Session.write() method. Polishing Polishing - Add WARN For Missing File + Test JIRA: https://jira.springsource.org/browse/INT-3091
This commit is contained in:
committed by
Artem Bilan
parent
7b2ba3e0a3
commit
ae7bc5d4f7
@@ -17,16 +17,17 @@
|
||||
package org.springframework.integration.sftp.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
@@ -75,7 +76,6 @@ public class OutboundChannelAdapterParserTests {
|
||||
assertNotNull(TestUtils.getPropertyValue(handler, "temporaryDirectoryExpressionProcessor"));
|
||||
assertEquals(context.getBean("fileNameGenerator"), TestUtils.getPropertyValue(handler, "fileNameGenerator"));
|
||||
assertEquals("UTF-8", TestUtils.getPropertyValue(handler, "charset"));
|
||||
assertNotNull(TestUtils.getPropertyValue(handler, "temporaryDirectory"));
|
||||
CachingSessionFactory<?> sessionFactory = TestUtils.getPropertyValue(handler, "sessionFactory", CachingSessionFactory.class);
|
||||
DefaultSftpSessionFactory clientFactory = TestUtils.getPropertyValue(sessionFactory, "sessionFactory", DefaultSftpSessionFactory.class);
|
||||
assertEquals("localhost", TestUtils.getPropertyValue(clientFactory, "host"));
|
||||
@@ -108,7 +108,6 @@ public class OutboundChannelAdapterParserTests {
|
||||
String fileNameGeneratorExpression = (String) TestUtils.getPropertyValue(generator, "expression");
|
||||
assertEquals("payload.getName() + '-foo'", fileNameGeneratorExpression);
|
||||
assertEquals("UTF-8", TestUtils.getPropertyValue(handler, "charset"));
|
||||
assertNotNull(TestUtils.getPropertyValue(handler, "temporaryDirectory"));
|
||||
assertNull(TestUtils.getPropertyValue(handler, "temporaryDirectoryExpressionProcessor"));
|
||||
|
||||
}
|
||||
|
||||
@@ -108,8 +108,11 @@ public class SftpOutboundTests {
|
||||
handler.setBeanFactory(mock(BeanFactory.class));
|
||||
handler.afterPropertiesSet();
|
||||
|
||||
handler.handleMessage(new GenericMessage<String>("hello"));
|
||||
handler.handleMessage(new GenericMessage<String>("String data"));
|
||||
assertTrue(new File("remote-target-dir", "foo.txt").exists());
|
||||
byte[] inFile = FileCopyUtils.copyToByteArray(file);
|
||||
assertEquals("String data", new String(inFile));
|
||||
file.delete();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -128,8 +131,11 @@ public class SftpOutboundTests {
|
||||
handler.setBeanFactory(mock(BeanFactory.class));
|
||||
handler.afterPropertiesSet();
|
||||
|
||||
handler.handleMessage(new GenericMessage<byte[]>("hello".getBytes()));
|
||||
handler.handleMessage(new GenericMessage<byte[]>("byte[] data".getBytes()));
|
||||
assertTrue(new File("remote-target-dir", "foo.txt").exists());
|
||||
byte[] inFile = FileCopyUtils.copyToByteArray(file);
|
||||
assertEquals("byte[] data", new String(inFile));
|
||||
file.delete();
|
||||
}
|
||||
|
||||
@Test //INT-2275
|
||||
|
||||
Reference in New Issue
Block a user