You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2010/06/23 13:08:11 UTC

svn commit: r957155 - /camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java

Author: davsclaus
Date: Wed Jun 23 11:08:10 2010
New Revision: 957155

URL: http://svn.apache.org/viewvc?rev=957155&view=rev
Log:
CAMEL-2842: Added JSCH logging when using sftp. Thanks to Bengt Rodehav for the patch.

Modified:
    camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.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=957155&r1=957154&r2=957155&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 Wed Jun 23 11:08:10 2010
@@ -32,7 +32,6 @@ import com.jcraft.jsch.JSchException;
 import com.jcraft.jsch.Session;
 import com.jcraft.jsch.SftpException;
 import com.jcraft.jsch.UserInfo;
-
 import org.apache.camel.Exchange;
 import org.apache.camel.InvalidPayloadException;
 import org.apache.camel.component.file.FileComponent;
@@ -115,6 +114,7 @@ public class SftpOperations implements R
 
     protected Session createSession(final RemoteFileConfiguration configuration) throws JSchException {
         final JSch jsch = new JSch();
+        JSch.setLogger(new JSchLogger());
 
         SftpConfiguration sftpConfig = (SftpConfiguration) configuration;
 
@@ -170,6 +170,44 @@ public class SftpOperations implements R
         return session;
     }
 
+    private static final class JSchLogger implements com.jcraft.jsch.Logger {
+
+        public boolean isEnabled(int level) {
+            switch (level) {
+            case FATAL:
+                return LOG.isFatalEnabled();
+            case ERROR:
+                return LOG.isErrorEnabled();
+            case WARN:
+                return LOG.isWarnEnabled();
+            case INFO:
+                return LOG.isInfoEnabled();
+            default:
+                return LOG.isDebugEnabled();
+            }
+        }
+
+        public void log(int level, String message) {
+            switch (level) {
+            case FATAL:
+                LOG.fatal("JSCH -> " + message);
+                break;
+            case ERROR:
+                LOG.error("JSCH -> " + message);
+                break;
+            case WARN:
+                LOG.warn("JSCH -> " + message);
+                break;
+            case INFO:
+                LOG.info("JSCH -> " + message);
+                break;
+            default:
+                LOG.debug("JSCH -> " + message);
+                break;
+            }
+        }
+    }
+
     public boolean isConnected() throws GenericFileOperationFailedException {
         return session != null && session.isConnected() && channel != null && channel.isConnected();
     }
@@ -307,7 +345,7 @@ public class SftpOperations implements R
             // can return either null or an empty list depending on FTP servers
             if (files != null) {
                 for (Object file : files) {
-                    list.add((ChannelSftp.LsEntry)file);
+                    list.add((ChannelSftp.LsEntry) file);
                 }
             }
             return list;
@@ -332,7 +370,7 @@ public class SftpOperations implements R
         try {
             os = new ByteArrayOutputStream();
             GenericFile<ChannelSftp.LsEntry> target =
-                (GenericFile<ChannelSftp.LsEntry>) exchange.getProperty(FileComponent.FILE_EXCHANGE_FILE);
+                    (GenericFile<ChannelSftp.LsEntry>) exchange.getProperty(FileComponent.FILE_EXCHANGE_FILE);
             ObjectHelper.notNull(target, "Exchange should have the " + FileComponent.FILE_EXCHANGE_FILE + " set");
             target.setBody(os);
             channel.get(name, os);
@@ -349,8 +387,8 @@ public class SftpOperations implements R
         File temp;
         File local = new File(endpoint.getLocalWorkDirectory());
         OutputStream os;
-        GenericFile<ChannelSftp.LsEntry> file = 
-            (GenericFile<ChannelSftp.LsEntry>) exchange.getProperty(FileComponent.FILE_EXCHANGE_FILE);
+        GenericFile<ChannelSftp.LsEntry> file =
+                (GenericFile<ChannelSftp.LsEntry>) exchange.getProperty(FileComponent.FILE_EXCHANGE_FILE);
         ObjectHelper.notNull(file, "Exchange should have the " + FileComponent.FILE_EXCHANGE_FILE + " set");
         try {
             // use relative filename in local work directory
@@ -483,4 +521,4 @@ public class SftpOperations implements R
         // is not implemented
         return true;
     }
-}
\ No newline at end of file
+}