camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1373769 - in /camel/branches/camel-2.10.x: ./ camel-core/src/main/java/org/apache/camel/component/file/ camel-core/src/test/java/org/apache/camel/component/file/ components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/ co...
Date Thu, 16 Aug 2012 09:32:42 GMT
Author: davsclaus
Date: Thu Aug 16 09:32:41 2012
New Revision: 1373769

URL: http://svn.apache.org/viewvc?rev=1373769&view=rev
Log:
CAMEL-5407: Added option allowNullBody to ftp producer to allow writing empty files easier.

Added:
    camel/branches/camel-2.10.x/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerAllowNullBodyFileAlreadyExistTest.java
      - copied unchanged from r1373763, camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerAllowNullBodyFileAlreadyExistTest.java
    camel/branches/camel-2.10.x/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerAllowNullBodyTest.java
      - copied unchanged from r1373763, camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerAllowNullBodyTest.java
Modified:
    camel/branches/camel-2.10.x/   (props changed)
    camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java
    camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/component/file/FileProducerAllowNullBodyFileAlreadyExistsTest.java
    camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/component/file/FileProducerAllowNullBodyTest.java
    camel/branches/camel-2.10.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
    camel/branches/camel-2.10.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java

Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
  Merged /camel/trunk:r1373763

Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java?rev=1373769&r1=1373768&r2=1373769&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java
(original)
+++ camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java
Thu Aug 16 09:32:41 2012
@@ -175,7 +175,7 @@ public class FileOperations implements G
         // Do an explicit test for a null body and decide what to do
         if (exchange.getIn().getBody() == null) {
             if (endpoint.isAllowNullBody()) {
-                LOG.trace("The in message of exchange body was null.");
+                LOG.trace("Writing empty file.");
                 try {
                     writeFileEmptyBody(file);
                     return true;
@@ -183,7 +183,7 @@ public class FileOperations implements G
                     throw new GenericFileOperationFailedException("Cannot store file: " +
file, e);
                 }
             } else {
-                throw new GenericFileOperationFailedException("Cannot write null body to
file.");
+                throw new GenericFileOperationFailedException("Cannot write null body to
file: " + file);
             }
         }
 
@@ -348,9 +348,10 @@ public class FileOperations implements G
      */
     private void writeFileEmptyBody(File target) throws IOException {
         if (!target.exists()) {
+            LOG.debug("Creating new empty file: {}", target);
             target.createNewFile();
         } else if (endpoint.getFileExist() == GenericFileExist.Override) {
-            LOG.trace("Truncating file as it already exists and endpoint set to Override
file.");
+            LOG.debug("Truncating existing file: {}", target);
             FileChannel out = new FileOutputStream(target).getChannel();
             try {
                 out.truncate(0);

Modified: camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/component/file/FileProducerAllowNullBodyFileAlreadyExistsTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/component/file/FileProducerAllowNullBodyFileAlreadyExistsTest.java?rev=1373769&r1=1373768&r2=1373769&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/component/file/FileProducerAllowNullBodyFileAlreadyExistsTest.java
(original)
+++ camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/component/file/FileProducerAllowNullBodyFileAlreadyExistsTest.java
Thu Aug 16 09:32:41 2012
@@ -27,6 +27,7 @@ import org.apache.camel.component.mock.M
  * If the fileExist option is set to Override the file's contents will be empty
  */
 public class FileProducerAllowNullBodyFileAlreadyExistsTest extends ContextTestSupport {
+
     @Override
     protected void setUp() throws Exception {
         deleteDirectory("target/allow");

Modified: camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/component/file/FileProducerAllowNullBodyTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/component/file/FileProducerAllowNullBodyTest.java?rev=1373769&r1=1373768&r2=1373769&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/component/file/FileProducerAllowNullBodyTest.java
(original)
+++ camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/component/file/FileProducerAllowNullBodyTest.java
Thu Aug 16 09:32:41 2012
@@ -45,7 +45,7 @@ public class FileProducerAllowNullBodyTe
             fail("Should have thrown a GenericFileOperationFailedException");
         } catch (CamelExecutionException e) {
             GenericFileOperationFailedException cause = assertIsInstanceOf(GenericFileOperationFailedException.class,
e.getCause());
-            assertEquals("Cannot write null body to file.", cause.getMessage());
+            assertTrue(cause.getMessage().endsWith("allowNullBody.txt"));
         }
         
         assertFalse("allowNullBody set to false with null body should not create a new file",
new File("./target/allow/allowNullBody.txt").exists());

Modified: camel/branches/camel-2.10.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java?rev=1373769&r1=1373768&r2=1373769&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
(original)
+++ camel/branches/camel-2.10.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
Thu Aug 16 09:32:41 2012
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.file.remote;
 
+import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileOutputStream;
@@ -498,8 +499,20 @@ public class FtpOperations implements Re
         }
 
         InputStream is = null;
+        if (exchange.getIn().getBody() == null) {
+            // Do an explicit test for a null body and decide what to do
+            if (endpoint.isAllowNullBody()) {
+                log.trace("Writing empty file.");
+                is = new ByteArrayInputStream(new byte[]{});
+            } else {
+                throw new GenericFileOperationFailedException("Cannot write null body to
file: " + name);
+            }
+        }
+
         try {
-            is = exchange.getIn().getMandatoryBody(InputStream.class);
+            if (is == null) {
+                is = exchange.getIn().getMandatoryBody(InputStream.class);
+            }
             if (endpoint.getFileExist() == GenericFileExist.Append) {
                 log.trace("Client appendFile: {}", targetName);
                 return client.appendFile(targetName, is);

Modified: camel/branches/camel-2.10.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java?rev=1373769&r1=1373768&r2=1373769&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
(original)
+++ camel/branches/camel-2.10.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
Thu Aug 16 09:32:41 2012
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.file.remote;
 
+import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileOutputStream;
@@ -672,11 +673,25 @@ public class SftpOperations implements R
         }
 
         InputStream is = null;
+        if (exchange.getIn().getBody() == null) {
+            // Do an explicit test for a null body and decide what to do
+            if (endpoint.isAllowNullBody()) {
+                LOG.trace("Writing empty file.");
+                is = new ByteArrayInputStream(new byte[]{});
+            } else {
+                throw new GenericFileOperationFailedException("Cannot write null body to
file: " + name);
+            }
+        }
+
         try {
-            is = exchange.getIn().getMandatoryBody(InputStream.class);
+            if (is == null) {
+                is = exchange.getIn().getMandatoryBody(InputStream.class);
+            }
             if (endpoint.getFileExist() == GenericFileExist.Append) {
+                LOG.trace("Client appendFile: {}", targetName);
                 channel.put(is, targetName, ChannelSftp.APPEND);
             } else {
+                LOG.trace("Client storeFile: {}", targetName);
                 // override is default
                 channel.put(is, targetName);
             }



Mime
View raw message