Author: davsclaus Date: Fri Mar 4 12:24:51 2011 New Revision: 1077904 URL: http://svn.apache.org/viewvc?rev=1077904&view=rev Log: CAMEL-3749: Fixed issue with SFTP producer using temp file name and writing with no leading path causing NPE in JCraft SFTP library.
Added: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpProduceTempFileTest.java - copied, changed from r1077837, camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpSimpleProduceTest.java Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpSimpleProduceTest.java Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java?rev=1077904&r1=1077903&r2=1077904&view=diff ============================================================================== --- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java (original) +++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java Fri Mar 4 12:24:51 2011 @@ -696,7 +696,7 @@ public class SftpOperations implements R String directory = FileUtil.onlyPath(name); if (directory == null) { // assume current dir if no path could be extracted - directory = ""; + directory = "."; } String onlyName = FileUtil.stripPath(name); Copied: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpProduceTempFileTest.java (from r1077837, camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpSimpleProduceTest.java) URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpProduceTempFileTest.java?p2=camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpProduceTempFileTest.java&p1=camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpSimpleProduceTest.java&r1=1077837&r2=1077904&rev=1077904&view=diff ============================================================================== --- camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpSimpleProduceTest.java (original) +++ camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpProduceTempFileTest.java Fri Mar 4 12:24:51 2011 @@ -19,6 +19,7 @@ package org.apache.camel.component.file. import java.io.File; import org.apache.camel.Exchange; +import org.apache.camel.util.FileUtil; import org.junit.Ignore; import org.junit.Test; @@ -26,7 +27,7 @@ import org.junit.Test; * @version */ @Ignore("Disabled due CI servers fails on full build running with these tests") -public class SftpSimpleProduceTest extends SftpServerTestSupport { +public class SftpProduceTempFileTest extends SftpServerTestSupport { @Override public boolean isUseRouteBuilder() { @@ -34,12 +35,13 @@ public class SftpSimpleProduceTest exten } @Test - public void testSftpSimpleProduce() throws Exception { + public void testSftpTempFile() throws Exception { if (!canTest()) { return; } - template.sendBodyAndHeader("sftp://localhost:" + getPort() + "/" + FTP_ROOT_DIR + "?username=admin&password=admin", "Hello World", Exchange.FILE_NAME, "hello.txt"); + template.sendBodyAndHeader("sftp://localhost:" + getPort() + "/" + FTP_ROOT_DIR + + "?username=admin&password=admin&tempFileName=temp-${file:name}", "Hello World", Exchange.FILE_NAME, "hello.txt"); File file = new File(FTP_ROOT_DIR + "/hello.txt").getAbsoluteFile(); assertTrue("File should exist: " + file, file.exists()); @@ -47,29 +49,20 @@ public class SftpSimpleProduceTest exten } @Test - public void testSftpSimpleSubPathProduce() throws Exception { + public void testSftpTempFileNoStartingPath() throws Exception { if (!canTest()) { return; } - template.sendBodyAndHeader("sftp://localhost:" + getPort() + "/" + FTP_ROOT_DIR + "/mysub?username=admin&password=admin", "Bye World", Exchange.FILE_NAME, "bye.txt"); + template.sendBodyAndHeader("sftp://localhost:" + getPort() + + "/?username=admin&password=admin&tempFileName=temp-${file:name}", "Hello World", Exchange.FILE_NAME, "hello.txt"); - File file = new File(FTP_ROOT_DIR + "/mysub/bye.txt").getAbsoluteFile(); + File file = new File("./hello.txt").getAbsoluteFile(); assertTrue("File should exist: " + file, file.exists()); - assertEquals("Bye World", context.getTypeConverter().convertTo(String.class, file)); - } - - @Test - public void testSftpSimpleTwoSubPathProduce() throws Exception { - if (!canTest()) { - return; - } - - template.sendBodyAndHeader("sftp://localhost:" + getPort() + "/" + FTP_ROOT_DIR + "/mysub/myother?username=admin&password=admin", "Farewell World", Exchange.FILE_NAME, "farewell.txt"); + assertEquals("Hello World", context.getTypeConverter().convertTo(String.class, file)); - File file = new File(FTP_ROOT_DIR + "/mysub/myother/farewell.txt").getAbsoluteFile(); - assertTrue("File should exist: " + file, file.exists()); - assertEquals("Farewell World", context.getTypeConverter().convertTo(String.class, file)); + // delete file when we are done testing + FileUtil.deleteFile(file); } } Modified: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpSimpleProduceTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpSimpleProduceTest.java?rev=1077904&r1=1077903&r2=1077904&view=diff ============================================================================== --- camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpSimpleProduceTest.java (original) +++ camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/SftpSimpleProduceTest.java Fri Mar 4 12:24:51 2011 @@ -25,7 +25,6 @@ import org.junit.Test; /** * @version */ -@Ignore("Disabled due CI servers fails on full build running with these tests") public class SftpSimpleProduceTest extends SftpServerTestSupport { @Override