camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [camel] 05/11: CAMEL-12127: camel-ftp - Add option to turn on logging of transfer activity. Lets also see it in the JMX consumer so we can monitor when it last downloaded something.
Date Mon, 08 Jan 2018 10:20:51 GMT
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 25da2bfec3d35c6c5bbc1b24e577923b7181a51b
Author: Claus Ibsen <claus.ibsen@gmail.com>
AuthorDate: Sun Jan 7 14:40:21 2018 +0100

    CAMEL-12127: camel-ftp - Add option to turn on logging of transfer activity. Lets also
see it in the JMX consumer so we can monitor when it last downloaded something.
---
 .../remote/DefaultFtpClientActivityListener.java   | 190 +++++++++++++++++++++
 .../file/remote/FtpClientActivityListener.java     |  62 +++++++
 .../camel/component/file/remote/FtpConsumer.java   |  27 ++-
 .../file/remote/FtpCopyStreamListener.java         |  69 --------
 .../camel/component/file/remote/FtpEndpoint.java   |  14 +-
 .../camel/component/file/remote/FtpOperations.java |  58 +++++--
 .../FromFileTransferLoggingLevelVerboseTest.java   |  48 ++++++
 7 files changed, 379 insertions(+), 89 deletions(-)

diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/DefaultFtpClientActivityListener.java
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/DefaultFtpClientActivityListener.java
new file mode 100644
index 0000000..dfa14dc
--- /dev/null
+++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/DefaultFtpClientActivityListener.java
@@ -0,0 +1,190 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.file.remote;
+
+import org.apache.camel.util.CamelLogger;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.commons.net.io.CopyStreamEvent;
+import org.apache.commons.net.io.CopyStreamListener;
+
+public class DefaultFtpClientActivityListener implements FtpClientActivityListener, CopyStreamListener
{
+
+    private final CamelLogger logger;
+    private final String host;
+    private final boolean verbose;
+    private boolean download;
+
+    private volatile String fileName;
+    private volatile String lastLogActivity;
+    private volatile String lastVerboseLogActivity;
+    private volatile long lastLogActivityTimestamp = -1;
+    private volatile long lastVerboseLogActivityTimestamp = -1;
+    private volatile long transferredBytes;
+
+    public DefaultFtpClientActivityListener(CamelLogger logger, boolean verbose, String host)
{
+        this.logger = logger;
+        this.host = host;
+        this.verbose = verbose;
+    }
+
+    @Override
+    public void setRemoteFileName(String fileName) {
+        this.fileName = fileName;
+    }
+
+    public String getLastLogActivity() {
+        return lastLogActivity;
+    }
+
+    public long getLastLogActivityTimestamp() {
+        return lastLogActivityTimestamp;
+    }
+
+    @Override
+    public String getLastVerboseLogActivity() {
+        return lastVerboseLogActivity;
+    }
+
+    @Override
+    public long getLastVerboseLogActivityTimestamp() {
+        return lastVerboseLogActivityTimestamp;
+    }
+
+    @Override
+    public void onConnecting(String host) {
+        doLogVerbose("Connecting to host: " + host);
+    }
+
+    @Override
+    public void onConnected(String host) {
+        doLogVerbose("Connected to host: " + host);
+    }
+
+    @Override
+    public void onLogin(String host) {
+        doLogVerbose("Login on host: " + host);
+    }
+
+    @Override
+    public void onLoginComplete(String host) {
+        doLogVerbose("Login on host: " + host + " complete");
+    }
+
+    @Override
+    public void onDisconnecting(String host) {
+        doLogVerbose("Disconnecting from host: " + host);
+    }
+
+    @Override
+    public void onDisconnected(String host) {
+        doLogVerbose("Disconnected from host: " + host);
+    }
+
+    @Override
+    public void onScanningForFiles(String host, String directory) {
+        if (ObjectHelper.isEmpty(directory)) {
+            doLogVerbose("Scanning for new files to download from host: " + host);
+        } else {
+            doLogVerbose("Scanning for new files to download from host: " + host + " in directory:
" + directory);
+        }
+    }
+
+    @Override
+    public void onBeginDownloading(String host, String file) {
+        download = true;
+        String msg = "Downloading from host: " + host + " file: " + file + " starting";
+        doLog(msg);
+    }
+
+    @Override
+    public void onDownload(String host, String file, long chunkSize, long totalChunkSize,
long fileSize) {
+        transferredBytes = totalChunkSize;
+
+        String msg = "Downloading from host: " + host + " file: " + file + " chunk (" + chunkSize
+ "/" + totalChunkSize + " bytes)";
+        if (fileSize > 0) {
+            msg += " (file-size: " + fileSize + " bytes)";
+        }
+        doLog(msg);
+    }
+
+    @Override
+    public void onDownloadComplete(String host, String file) {
+        String msg = "Downloading from host: " + host + " file: " + file + " completed";
+        if (transferredBytes > 0) {
+            msg += " (" + transferredBytes + " bytes)";
+        }
+        doLog(msg);
+    }
+
+    @Override
+    public void onBeginUploading(String host, String file) {
+        download = false;
+        String msg = "Uploading to host: " + host + " file: " + file + " starting";
+        doLog(msg);
+    }
+
+    @Override
+    public void onUpload(String host, String file, long chunkSize, long totalChunkSize, long
fileSize) {
+        transferredBytes = totalChunkSize;
+
+        String msg = "Uploading to host: " + host + " file: " + file + " chunk (" + chunkSize
+ "/" + totalChunkSize + " bytes)";
+        if (fileSize > 0) {
+            msg += " (file-size: " + fileSize + " bytes)";
+        }
+        doLog(msg);
+    }
+
+    @Override
+    public void onUploadComplete(String host, String file) {
+        String msg = "Uploading to host: " + host + " file: " + file + " completed";
+        if (transferredBytes > 0) {
+            msg += " (" + transferredBytes + " bytes)";
+        }
+        doLog(msg);
+    }
+
+    @Override
+    public void bytesTransferred(CopyStreamEvent event) {
+        // not in use
+    }
+
+    @Override
+    public void bytesTransferred(long totalBytesTransferred, int bytesTransferred, long streamSize)
{
+        if (download) {
+            onDownload(host, fileName, bytesTransferred, totalBytesTransferred, streamSize);
+        } else {
+            onUpload(host, fileName, bytesTransferred, totalBytesTransferred, streamSize);
+        }
+    }
+
+    protected void doLog(String message) {
+        lastLogActivity = message;
+        lastLogActivityTimestamp = System.currentTimeMillis();
+        // verbose implies regular log as well
+        lastVerboseLogActivity = lastLogActivity;
+        lastVerboseLogActivityTimestamp = lastLogActivityTimestamp;
+        logger.log(message);
+    }
+
+    protected void doLogVerbose(String message) {
+        lastVerboseLogActivity = message;
+        lastVerboseLogActivityTimestamp = System.currentTimeMillis();
+        if (verbose) {
+            logger.log(message);
+        }
+    }
+}
diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpClientActivityListener.java
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpClientActivityListener.java
new file mode 100644
index 0000000..97908b7
--- /dev/null
+++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpClientActivityListener.java
@@ -0,0 +1,62 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.file.remote;
+
+import org.apache.commons.net.io.CopyStreamListener;
+
+/**
+ * Listener that captures the activity of the FTP Client such as connecting, login, upload
and download etc.
+ */
+public interface FtpClientActivityListener extends CopyStreamListener {
+
+    String getLastLogActivity();
+
+    long getLastLogActivityTimestamp();
+
+    String getLastVerboseLogActivity();
+
+    long getLastVerboseLogActivityTimestamp();
+
+    void setRemoteFileName(String fileName);
+
+    void onConnecting(String host);
+
+    void onConnected(String host);
+
+    void onLogin(String host);
+
+    void onLoginComplete(String host);
+
+    void onDisconnecting(String host);
+
+    void onDisconnected(String host);
+
+    void onScanningForFiles(String host, String directory);
+
+    void onBeginDownloading(String host, String file);
+
+    void onDownload(String host, String file, long chunkSize, long totalChunkSize, long fileSize);
+
+    void onDownloadComplete(String host, String file);
+
+    void onBeginUploading(String host, String file);
+
+    void onUpload(String host, String file, long chunkSize, long totalChunkSize, long fileSize);
+
+    void onUploadComplete(String host, String file);
+
+}
diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java
index f5c2530..7ec7754 100644
--- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java
+++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java
@@ -300,10 +300,10 @@ public class FtpConsumer extends RemoteFileConsumer<FTPFile> {
         return config.isUseList();
     }
 
-    @ManagedAttribute(description = "Description of last download activity")
-    public String getLastTransferActivity() {
+    @ManagedAttribute(description = "Description of last FTP download activity")
+    public String getLastFtpActivity() {
         FTPClient client = getOperations().getFtpClient();
-        FtpCopyStreamListener listener = (FtpCopyStreamListener) client.getCopyStreamListener();
+        FtpClientActivityListener listener = (FtpClientActivityListener) client.getCopyStreamListener();
         if (listener != null) {
             String log = listener.getLastLogActivity();
             if (log != null) {
@@ -321,6 +321,27 @@ public class FtpConsumer extends RemoteFileConsumer<FTPFile> {
         return null;
     }
 
+    @ManagedAttribute(description = "Description of last FTP activity (verbose)")
+    public String getLastActivityVerbose() {
+        FTPClient client = getOperations().getFtpClient();
+        FtpClientActivityListener listener = (FtpClientActivityListener) client.getCopyStreamListener();
+        if (listener != null) {
+            String log = listener.getLastVerboseLogActivity();
+            if (log != null) {
+                long since = listener.getLastVerboseLogActivityTimestamp();
+                if (since > 0) {
+                    StopWatch watch = new StopWatch(new Date(since));
+                    long delta = watch.taken();
+                    String human = TimeUtils.printDuration(delta);
+                    return log + " " + human + " ago";
+                } else {
+                    return log;
+                }
+            }
+        }
+        return null;
+    }
+
     @Override
     public String toString() {
         if (ftpConsumerToString == null) {
diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpCopyStreamListener.java
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpCopyStreamListener.java
deleted file mode 100644
index e2434a5..0000000
--- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpCopyStreamListener.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.file.remote;
-
-import org.apache.camel.util.CamelLogger;
-import org.apache.commons.net.io.CopyStreamEvent;
-import org.apache.commons.net.io.CopyStreamListener;
-
-/**
- * Listener used for logging the progress of the upload or download of files.
- */
-public class FtpCopyStreamListener implements CopyStreamListener {
-
-    // TODO: add support for connect / scanning dirs / complete events
-    // TODO: add API to operations to include more details than just the name, eg RemoteFile
so we can get its size / timestamp etc
-
-    private final CamelLogger logger;
-    private final String fileName;
-    private final boolean download;
-    private String lastLogActivity;
-    private long lastLogActivityTimestamp = -1;
-
-    public FtpCopyStreamListener(CamelLogger logger, String fileName, boolean download) {
-        this.logger = logger;
-        this.fileName = fileName;
-        this.download = download;
-    }
-
-    public String getLastLogActivity() {
-        return lastLogActivity;
-    }
-
-    public long getLastLogActivityTimestamp() {
-        return lastLogActivityTimestamp;
-    }
-
-    @Override
-    public void bytesTransferred(CopyStreamEvent event) {
-        // not in use
-    }
-
-    @Override
-    public void bytesTransferred(long totalBytesTransferred, int bytesTransferred, long streamSize)
{
-        // stream size is always -1 from the FTP client
-
-        if (download) {
-            lastLogActivity = "Downloading: " + fileName + " (chunk: " + bytesTransferred
+ ", total chunk: " + totalBytesTransferred + " bytes)";
-        } else {
-            lastLogActivity = "Uploading: " + fileName + " (chunk: " + bytesTransferred +
", total chunk: " + totalBytesTransferred + " bytes)";
-        }
-        lastLogActivityTimestamp = System.currentTimeMillis();
-
-        logger.log(lastLogActivity);
-    }
-}
diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpEndpoint.java
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpEndpoint.java
index 6e20600..45b098a 100644
--- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpEndpoint.java
+++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpEndpoint.java
@@ -29,7 +29,6 @@ import org.apache.camel.component.file.remote.RemoteFileConfiguration.PathSepara
 import org.apache.camel.spi.ClassResolver;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriParam;
-import org.apache.camel.util.CamelLogger;
 import org.apache.camel.util.PlatformHelper;
 import org.apache.commons.net.ftp.FTPClient;
 import org.apache.commons.net.ftp.FTPClientConfig;
@@ -57,6 +56,8 @@ public class FtpEndpoint<T extends FTPFile> extends RemoteFileEndpoint<FTPFile>
     protected FTPClient ftpClient;
     @UriParam(label = "common", defaultValue = "DEBUG")
     protected LoggingLevel transferLoggingLevel = LoggingLevel.DEBUG;
+    @UriParam(label = "common")
+    protected boolean transferLoggingVerbose;
 
     public FtpEndpoint() {
     }
@@ -268,6 +269,17 @@ public class FtpEndpoint<T extends FTPFile> extends RemoteFileEndpoint<FTPFile>
         this.transferLoggingLevel = transferLoggingLevel;
     }
 
+    public boolean isTransferLoggingVerbose() {
+        return transferLoggingVerbose;
+    }
+
+    /**
+     * Configures whether the perform verbose (fine grained) logging of the progress of upload
and download operations.
+     */
+    public void setTransferLoggingVerbose(boolean transferLoggingVerbose) {
+        this.transferLoggingVerbose = transferLoggingVerbose;
+    }
+
     @Override
     public char getFileSeparator() {
         // the regular ftp component should use the configured separator
diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
index 9d968d5..fdf064a 100644
--- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
+++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
@@ -57,8 +57,9 @@ public class FtpOperations implements RemoteFileOperations<FTPFile>
{
     protected final Logger log = LoggerFactory.getLogger(getClass());
     protected final FTPClient client;
     protected final FTPClientConfig clientConfig;
-    protected final CamelLogger transferLogger = new CamelLogger(LoggerFactory.getLogger(FtpCopyStreamListener.class));
+    protected final CamelLogger transferLogger = new CamelLogger(LoggerFactory.getLogger(FtpClientActivityListener.class));
     protected FtpEndpoint<FTPFile> endpoint;
+    protected volatile FtpClientActivityListener listener;
 
     public FtpOperations(FTPClient client, FTPClientConfig clientConfig) {
         this.client = client;
@@ -70,6 +71,11 @@ public class FtpOperations implements RemoteFileOperations<FTPFile>
{
     }
 
     public boolean connect(RemoteFileConfiguration configuration) throws GenericFileOperationFailedException
{
+        // setup download listener/logger when we connect
+        transferLogger.setLevel(endpoint.getTransferLoggingLevel());
+        listener = new DefaultFtpClientActivityListener(transferLogger, endpoint.isTransferLoggingVerbose(),
endpoint.getConfiguration().remoteServerInformation());
+        client.setCopyStreamListener(listener);
+
         log.trace("Connecting using FTPClient: {}", client);
 
         String host = configuration.getHost();
@@ -95,6 +101,7 @@ public class FtpOperations implements RemoteFileOperations<FTPFile>
{
                 if (log.isTraceEnabled() && attempt > 0) {
                     log.trace("Reconnect attempt #{} connecting to {}", attempt, configuration.remoteServerInformation());
                 }
+                listener.onConnecting(host);
                 client.connect(host, port);
                 // must check reply code if we are connected
                 int reply = client.getReplyCode();
@@ -136,6 +143,9 @@ public class FtpOperations implements RemoteFileOperations<FTPFile>
{
             }
         }
 
+        // we are now connected
+        listener.onConnected(host);
+
         // must enter passive mode directly after connect
         if (configuration.isPassiveMode()) {
             log.trace("Using passive mode connections");
@@ -144,7 +154,7 @@ public class FtpOperations implements RemoteFileOperations<FTPFile>
{
 
         // must set soTimeout after connect
         if (endpoint instanceof FtpEndpoint) {
-            FtpEndpoint<?> ftpEndpoint = (FtpEndpoint<?>) endpoint;
+            FtpEndpoint<?> ftpEndpoint = endpoint;
             if (ftpEndpoint.getSoTimeout() > 0) {
                 log.trace("Using SoTimeout={}", ftpEndpoint.getSoTimeout());
                 try {
@@ -156,6 +166,7 @@ public class FtpOperations implements RemoteFileOperations<FTPFile>
{
         }
 
         try {
+            listener.onLogin(host);
             boolean login;
             if (username != null) {
                 if (account != null) {
@@ -181,9 +192,12 @@ public class FtpOperations implements RemoteFileOperations<FTPFile>
{
                 String replyString = client.getReplyString();
                 int replyCode = client.getReplyCode();
                 // disconnect to prevent connection leaks
+                listener.onDisconnecting(host);
                 client.disconnect();
+                listener.onDisconnected(host);
                 throw new GenericFileOperationFailedException(replyCode, replyString);
             }
+            listener.onLoginComplete(host);
             client.setFileType(configuration.isBinary() ? FTP.BINARY_FILE_TYPE : FTP.ASCII_FILE_TYPE);
         } catch (IOException e) {
             throw new GenericFileOperationFailedException(client.getReplyCode(), client.getReplyString(),
e.getMessage(), e);
@@ -215,6 +229,7 @@ public class FtpOperations implements RemoteFileOperations<FTPFile>
{
 
     public void disconnect() throws GenericFileOperationFailedException {
         // logout before disconnecting
+        listener.onDisconnecting(endpoint.getConfiguration().remoteServerInformation());
         try {
             log.trace("Client logout");
             client.logout();
@@ -228,6 +243,7 @@ public class FtpOperations implements RemoteFileOperations<FTPFile>
{
                 throw new GenericFileOperationFailedException(client.getReplyCode(), client.getReplyString(),
e.getMessage(), e);
             }
         }
+        listener.onDisconnected(endpoint.getConfiguration().remoteServerInformation());
     }
 
     public boolean deleteFile(String name) throws GenericFileOperationFailedException {
@@ -311,14 +327,24 @@ public class FtpOperations implements RemoteFileOperations<FTPFile>
{
     }
 
     public boolean retrieveFile(String name, Exchange exchange) throws GenericFileOperationFailedException
{
+        // store the name of the file to download on the listener
+        listener.setRemoteFileName(name);
+        listener.onBeginDownloading(endpoint.getConfiguration().remoteServerInformation(),
name);
+
+        boolean answer;
         log.trace("retrieveFile({})", name);
         if (ObjectHelper.isNotEmpty(endpoint.getLocalWorkDirectory())) {
             // local work directory is configured so we should store file content as files
in this local directory
-            return retrieveFileToFileInLocalWorkDirectory(name, exchange);
+            answer = retrieveFileToFileInLocalWorkDirectory(name, exchange);
         } else {
             // store file content directory as stream on the body
-            return retrieveFileToStreamInBody(name, exchange);
+            answer = retrieveFileToStreamInBody(name, exchange);
         }
+
+        if (answer) {
+            listener.onDownloadComplete(endpoint.getConfiguration().remoteServerInformation(),
name);
+        }
+        return answer;
     }
     
     @Override
@@ -358,10 +384,6 @@ public class FtpOperations implements RemoteFileOperations<FTPFile>
{
                 remoteName = FileUtil.stripPath(name);
             }
 
-            // setup donwload logger for the given file
-            transferLogger.setLevel(endpoint.getTransferLoggingLevel());
-            client.setCopyStreamListener(new FtpCopyStreamListener(transferLogger, remoteName,
true));
-
             log.trace("Client retrieveFile: {}", remoteName);
             if (endpoint.getConfiguration().isStreamDownload()) {
                 InputStream is = client.retrieveFileStream(remoteName); 
@@ -460,10 +482,6 @@ public class FtpOperations implements RemoteFileOperations<FTPFile>
{
                 remoteName = FileUtil.stripPath(name);
             }
 
-            // setup donwload logger for the given file
-            transferLogger.setLevel(endpoint.getTransferLoggingLevel());
-            client.setCopyStreamListener(new FtpCopyStreamListener(transferLogger, remoteName,
true));
-
             log.trace("Client retrieveFile: {}", remoteName);
             result = client.retrieveFile(remoteName, os);
 
@@ -512,9 +530,13 @@ public class FtpOperations implements RemoteFileOperations<FTPFile>
{
         // must normalize name first
         name = endpoint.getConfiguration().normalizePath(name);
 
+        // store the name of the file to upload on the listener
+        listener.setRemoteFileName(name);
+        listener.onBeginUploading(endpoint.getConfiguration().remoteServerInformation(),
name);
+
         log.trace("storeFile({})", name);
 
-        boolean answer = false;
+        boolean answer;
         String currentDir = null;
         String path = FileUtil.onlyPath(name);
         String targetName = name;
@@ -540,6 +562,10 @@ public class FtpOperations implements RemoteFileOperations<FTPFile>
{
             }
         }
 
+        if (answer) {
+            listener.onUploadComplete(endpoint.getConfiguration().remoteServerInformation(),
name);
+        }
+
         return answer;
     }
 
@@ -589,9 +615,6 @@ public class FtpOperations implements RemoteFileOperations<FTPFile>
{
 
             final StopWatch watch = new StopWatch();
             boolean answer;
-            // setup upload logger for the given file
-            transferLogger.setLevel(endpoint.getTransferLoggingLevel());
-            client.setCopyStreamListener(new FtpCopyStreamListener(transferLogger, targetName,
false));
             log.debug("About to store file: {} using stream: {}", targetName, is);
             if (endpoint.getFileExist() == GenericFileExist.Append) {
                 log.trace("Client appendFile: {}", targetName);
@@ -812,6 +835,7 @@ public class FtpOperations implements RemoteFileOperations<FTPFile>
{
 
     public List<FTPFile> listFiles() throws GenericFileOperationFailedException {
         log.trace("listFiles()");
+        listener.onScanningForFiles(endpoint.remoteServerInformation(), null);
         try {
             final List<FTPFile> list = new ArrayList<FTPFile>();
             FTPFile[] files = client.listFiles();
@@ -827,6 +851,8 @@ public class FtpOperations implements RemoteFileOperations<FTPFile>
{
 
     public List<FTPFile> listFiles(String path) throws GenericFileOperationFailedException
{
         log.trace("listFiles({})", path);
+        listener.onScanningForFiles(endpoint.remoteServerInformation(), path);
+
         // use current directory if path not given
         if (ObjectHelper.isEmpty(path)) {
             path = ".";
diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFileTransferLoggingLevelVerboseTest.java
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFileTransferLoggingLevelVerboseTest.java
new file mode 100644
index 0000000..ab6a267
--- /dev/null
+++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFileTransferLoggingLevelVerboseTest.java
@@ -0,0 +1,48 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.file.remote;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+
+/**
+ * @version 
+ */
+public class FromFileTransferLoggingLevelVerboseTest extends FtpServerTestSupport {
+
+    protected String getFtpUrl() {
+        return "ftp://admin@localhost:" + getPort() + "/tmp3/camel?password=admin&transferLoggingLevel=INFO&transferLoggingVerbose=true";
+    }
+
+    @Test
+    public void testTransferLoggingLevelVerbose() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(2);
+
+        assertMockEndpointsSatisfied();
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from(getFtpUrl()).to("mock:result");
+                from("file:src/main/data?noop=true").to(getFtpUrl());
+            }
+        };
+    }
+}
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
"commits@camel.apache.org" <commits@camel.apache.org>.

Mime
View raw message