Author: davsclaus
Date: Wed Nov 11 06:12:00 2009
New Revision: 834776

URL: http://svn.apache.org/viewvc?rev=834776&view=rev
Log:
CAMEL-2157: Closing streams to avoid connections not being released later by 
FTP framework. Fixed spelling.

Modified:
    
camel/branches/camel-1.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java
    
camel/branches/camel-1.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpProducer.java
    
camel/branches/camel-1.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileProducer.java
    
camel/branches/camel-1.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConsumer.java
    
camel/branches/camel-1.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpProducer.java

Modified: 
camel/branches/camel-1.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java?rev=834776&r1=834775&r2=834776&view=diff
==============================================================================
--- 
camel/branches/camel-1.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java
 (original)
+++ 
camel/branches/camel-1.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java
 Wed Nov 11 06:12:00 2009
@@ -17,12 +17,12 @@
 package org.apache.camel.component.file.remote;
 
 import java.io.ByteArrayOutputStream;
-import java.io.File;
 import java.io.IOException;
 import java.util.concurrent.ScheduledExecutorService;
 
 import org.apache.camel.Processor;
 import org.apache.camel.component.file.FileComponent;
+import org.apache.camel.util.ObjectHelper;
 import org.apache.commons.net.ftp.FTPClient;
 import org.apache.commons.net.ftp.FTPFile;
 
@@ -135,7 +135,7 @@
                 log.warn("Consumer is stopping. Ignoring caught exception: "
                          + e.getClass().getCanonicalName() + " message: " + 
e.getMessage());
             } else {
-                log.warn("Exception occured during polling: "
+                log.warn("Exception occurred during polling: "
                          + e.getClass().getCanonicalName() + " message: " + 
e.getMessage());
                 disconnect();
                 // Rethrow to signify that we didn't poll
@@ -194,16 +194,21 @@
         if (timestampMatched && isMatched(ftpFile)) {
             String fullFileName = getFullFileName(ftpFile);
 
-            // is we use excluse read then acquire the exclusive read (waiting 
until we got it)
+            // is we use exclusive read then acquire the exclusive read 
(waiting until we got it)
             if (exclusiveReadLock) {
                 acquireExclusiveReadLock(client, ftpFile);
             }
 
             // retrieve the file
             final ByteArrayOutputStream byteArrayOutputStream = new 
ByteArrayOutputStream();
-            client.retrieveFile(ftpFile.getName(), byteArrayOutputStream);
-            if (log.isDebugEnabled()) {
-                log.debug("Retrieved file: " + ftpFile.getName() + " from: " + 
remoteServer());
+            try {
+                client.retrieveFile(ftpFile.getName(), byteArrayOutputStream);
+                if (log.isDebugEnabled()) {
+                    log.debug("Retrieved file: " + ftpFile.getName() + " from: 
" + remoteServer());
+                }
+            } finally {
+                // close stream to avoid leaking FTP connections
+                ObjectHelper.close(byteArrayOutputStream, "retrieve: " + 
ftpFile.getName(), log);
             }
 
             RemoteFileExchange exchange = 
endpoint.createExchange(fullFileName, ftpFile.getName(),
@@ -234,7 +239,7 @@
                 if (deleteFile) {
                     // delete file after consuming
                     if (log.isDebugEnabled()) {
-                        log.debug("Deleteing file: " + ftpFile.getName() + " 
from: " + remoteServer());
+                        log.debug("Deleting file: " + ftpFile.getName() + " 
from: " + remoteServer());
                     }
                     boolean deleted = client.deleteFile(ftpFile.getName());
                     if (!deleted) {

Modified: 
camel/branches/camel-1.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpProducer.java
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpProducer.java?rev=834776&r1=834775&r2=834776&view=diff
==============================================================================
--- 
camel/branches/camel-1.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpProducer.java
 (original)
+++ 
camel/branches/camel-1.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpProducer.java
 Wed Nov 11 06:12:00 2009
@@ -56,7 +56,7 @@
                 log.warn("Producer is stopping. Ignoring caught exception: "
                          + e.getClass().getCanonicalName() + " message: " + 
e.getMessage());
             } else {
-                log.warn("Exception occured during processing: "
+                log.warn("Exception occurred during processing: "
                          + e.getClass().getCanonicalName() + " message: " + 
e.getMessage());
                 disconnect();
                 // Rethrow to signify that we didn't poll

Modified: 
camel/branches/camel-1.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileProducer.java
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileProducer.java?rev=834776&r1=834775&r2=834776&view=diff
==============================================================================
--- 
camel/branches/camel-1.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileProducer.java
 (original)
+++ 
camel/branches/camel-1.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileProducer.java
 Wed Nov 11 06:12:00 2009
@@ -96,7 +96,7 @@
             disconnect();
         } catch (Exception e) {
             // ignore just log a warning
-            log.warn("Exception occured during disconecting from " + 
remoteServer() + ". "
+            log.warn("Exception occurred during disconecting from " + 
remoteServer() + ". "
                      + e.getClass().getCanonicalName() + " message: " + 
e.getMessage());
         }
         super.doStop();

Modified: 
camel/branches/camel-1.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConsumer.java
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConsumer.java?rev=834776&r1=834775&r2=834776&view=diff
==============================================================================
--- 
camel/branches/camel-1.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConsumer.java
 (original)
+++ 
camel/branches/camel-1.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConsumer.java
 Wed Nov 11 06:12:00 2009
@@ -28,6 +28,7 @@
 
 import org.apache.camel.Processor;
 import org.apache.camel.component.file.FileComponent;
+import org.apache.camel.util.ObjectHelper;
 
 public class SftpConsumer extends RemoteFileConsumer<RemoteFileExchange> {
     private final SftpEndpoint endpoint;
@@ -59,7 +60,7 @@
             disconnect();
         } catch (Exception e) {
             // ignore just log a warning
-            log.warn("Exception occured during disconecting from " + 
remoteServer() + ". "
+            log.warn("Exception occurred during disconecting from " + 
remoteServer() + ". "
                      + e.getClass().getCanonicalName() + " message: " + 
e.getMessage());
         }
         super.doStop();
@@ -119,7 +120,7 @@
                 log.warn("Consumer is stopping. Ignoring caught exception: "
                          + e.getClass().getCanonicalName() + " message: " + 
e.getMessage());
             } else {
-                log.warn("Exception occured during polling: "
+                log.warn("Exception occurred during polling: "
                          + e.getClass().getCanonicalName() + " message: " + 
e.getMessage());
                 disconnect();
                 // Rethrow to signify that we didn't poll
@@ -176,16 +177,21 @@
         if (timestampMatched && isMatched(sftpFile)) {
             String fullFileName = getFullFileName(sftpFile);
 
-            // is we use excluse read then acquire the exclusive read (waiting 
until we got it)
+            // is we use exclusive read then acquire the exclusive read 
(waiting until we got it)
             if (exclusiveReadLock) {
                 acquireExclusiveReadLock(sftpFile);
             }
 
             // retrieve the file
             final ByteArrayOutputStream byteArrayOutputStream = new 
ByteArrayOutputStream();
-            channel.get(sftpFile.getFilename(), byteArrayOutputStream);
-            if (log.isDebugEnabled()) {
-                log.debug("Retrieved file: " + sftpFile.getFilename() + " 
from: " + remoteServer());
+            try {
+                channel.get(sftpFile.getFilename(), byteArrayOutputStream);
+                if (log.isDebugEnabled()) {
+                    log.debug("Retrieved file: " + sftpFile.getFilename() + " 
from: " + remoteServer());
+                }
+            } finally {
+                // close stream to avoid leaking SFTP connections
+                ObjectHelper.close(byteArrayOutputStream, "retrieve: " + 
sftpFile.getFilename(), log);
             }
 
             RemoteFileExchange exchange = 
endpoint.createExchange(getFullFileName(sftpFile),
@@ -214,7 +220,7 @@
                 if (deleteFile) {
                     // delete file after consuming
                     if (log.isDebugEnabled()) {
-                        log.debug("Deleteing file: " + sftpFile.getFilename() 
+ " from: " + remoteServer());
+                        log.debug("Deleting file: " + sftpFile.getFilename() + 
" from: " + remoteServer());
                     }
                     deleteFile(sftpFile.getFilename());
                 } else if (isMoveFile()) {

Modified: 
camel/branches/camel-1.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpProducer.java
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpProducer.java?rev=834776&r1=834775&r2=834776&view=diff
==============================================================================
--- 
camel/branches/camel-1.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpProducer.java
 (original)
+++ 
camel/branches/camel-1.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpProducer.java
 Wed Nov 11 06:12:00 2009
@@ -50,7 +50,7 @@
                 log.warn("Producer is stopping. Ignoring caught exception: "
                          + e.getClass().getCanonicalName() + " message: " + 
e.getMessage());
             } else {
-                log.warn("Exception occured during processing: "
+                log.warn("Exception occurred during processing: "
                          + e.getClass().getCanonicalName() + " message: " + 
e.getMessage());
                 disconnect();
                 // Rethrow to signify that we didn't poll


Reply via email to