camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [camel] 06/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:52 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 dcb3e1e92bab2cd42794fb42034b39da5982df13
Author: Claus Ibsen <claus.ibsen@gmail.com>
AuthorDate: Sun Jan 7 15:09:33 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.
---
 .../camel-ftp/src/main/docs/ftp-component.adoc     |  3 +-
 .../camel-ftp/src/main/docs/ftps-component.adoc    |  3 +-
 .../remote/DefaultFtpClientActivityListener.java   | 10 +++++
 .../file/remote/FtpClientActivityListener.java     |  4 ++
 .../camel/component/file/remote/FtpConsumer.java   |  6 +--
 .../camel/component/file/remote/FtpOperations.java | 45 +++++++++++++++++-----
 6 files changed, 57 insertions(+), 14 deletions(-)

diff --git a/components/camel-ftp/src/main/docs/ftp-component.adoc b/components/camel-ftp/src/main/docs/ftp-component.adoc
index 652ec16..c21b166 100644
--- a/components/camel-ftp/src/main/docs/ftp-component.adoc
+++ b/components/camel-ftp/src/main/docs/ftp-component.adoc
@@ -97,7 +97,7 @@ with the following path and query parameters:
 | *directoryName* | The starting directory |  | String
 |===
 
-==== Query Parameters (105 parameters):
+==== Query Parameters (106 parameters):
 
 [width="100%",cols="2,5,^1,2",options="header"]
 |===
@@ -110,6 +110,7 @@ with the following path and query parameters:
 | *passiveMode* (common) | Sets passive mode connections. Default is active mode connections.
| false | boolean
 | *separator* (common) | Sets the path separator to be used. UNIX = Uses unix style path
separator Windows = Uses windows style path separator Auto = (is default) Use existing path
separator in file name | UNIX | PathSeparator
 | *transferLoggingLevel* (common) | Configure the logging level to use when logging the progress
of upload and download operations. | DEBUG | LoggingLevel
+| *transferLoggingVerbose* (common) | Configures whether the perform verbose (fine grained)
logging of the progress of upload and download operations. | false | boolean
 | *fastExistsCheck* (common) | If set this option to be true camel-ftp will use the list
file directly to check if the file exists. Since some FTP server may not support to list the
file directly if the option is false camel-ftp will use the old way to list the directory
and check if the file exists. This option also influences readLock=changed to control whether
it performs a fast check to update file information or not. This can be used to speed up the
process if the FTP server has a l [...]
 | *bridgeErrorHandler* (consumer) | Allows for bridging the consumer to the Camel routing
Error Handler which mean any exceptions occurred while the consumer is trying to pickup incoming
messages or the likes will now be processed as a message and handled by the routing Error
Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal
with exceptions that will be logged at WARN or ERROR level and ignored. | false | boolean
 | *delete* (consumer) | If true the file will be deleted after it is processed successfully.
| false | boolean
diff --git a/components/camel-ftp/src/main/docs/ftps-component.adoc b/components/camel-ftp/src/main/docs/ftps-component.adoc
index 8fd9247..414f774 100644
--- a/components/camel-ftp/src/main/docs/ftps-component.adoc
+++ b/components/camel-ftp/src/main/docs/ftps-component.adoc
@@ -57,7 +57,7 @@ with the following path and query parameters:
 | *directoryName* | The starting directory |  | String
 |===
 
-==== Query Parameters (113 parameters):
+==== Query Parameters (114 parameters):
 
 [width="100%",cols="2,5,^1,2",options="header"]
 |===
@@ -70,6 +70,7 @@ with the following path and query parameters:
 | *passiveMode* (common) | Sets passive mode connections. Default is active mode connections.
| false | boolean
 | *separator* (common) | Sets the path separator to be used. UNIX = Uses unix style path
separator Windows = Uses windows style path separator Auto = (is default) Use existing path
separator in file name | UNIX | PathSeparator
 | *transferLoggingLevel* (common) | Configure the logging level to use when logging the progress
of upload and download operations. | DEBUG | LoggingLevel
+| *transferLoggingVerbose* (common) | Configures whether the perform verbose (fine grained)
logging of the progress of upload and download operations. | false | boolean
 | *fastExistsCheck* (common) | If set this option to be true camel-ftp will use the list
file directly to check if the file exists. Since some FTP server may not support to list the
file directly if the option is false camel-ftp will use the old way to list the directory
and check if the file exists. This option also influences readLock=changed to control whether
it performs a fast check to update file information or not. This can be used to speed up the
process if the FTP server has a l [...]
 | *bridgeErrorHandler* (consumer) | Allows for bridging the consumer to the Camel routing
Error Handler which mean any exceptions occurred while the consumer is trying to pickup incoming
messages or the likes will now be processed as a message and handled by the routing Error
Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal
with exceptions that will be logged at WARN or ERROR level and ignored. | false | boolean
 | *delete* (consumer) | If true the file will be deleted after it is processed successfully.
| false | boolean
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
index dfa14dc..8907fe4 100644
--- 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
@@ -65,6 +65,11 @@ public class DefaultFtpClientActivityListener implements FtpClientActivityListen
     }
 
     @Override
+    public void onGeneralError(String host, String errorMessage) {
+        doLogVerbose("General error when communicating with host: " + host + " error: " +
errorMessage);
+    }
+
+    @Override
     public void onConnecting(String host) {
         doLogVerbose("Connecting to host: " + host);
     }
@@ -85,6 +90,11 @@ public class DefaultFtpClientActivityListener implements FtpClientActivityListen
     }
 
     @Override
+    public void onLoginFailed(int replyCode, String replyMessage) {
+        doLogVerbose("Login on host: " + host + " failed (code: " + replyCode + ", message:
" + replyMessage + ")");
+    }
+
+    @Override
     public void onDisconnecting(String host) {
         doLogVerbose("Disconnecting from host: " + host);
     }
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
index 97908b7..0764b4d 100644
--- 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
@@ -33,6 +33,8 @@ public interface FtpClientActivityListener extends CopyStreamListener {
 
     void setRemoteFileName(String fileName);
 
+    void onGeneralError(String host, String errorMessage);
+
     void onConnecting(String host);
 
     void onConnected(String host);
@@ -41,6 +43,8 @@ public interface FtpClientActivityListener extends CopyStreamListener {
 
     void onLoginComplete(String host);
 
+    void onLoginFailed(int replyCode, String replyMessage);
+
     void onDisconnecting(String host);
 
     void onDisconnected(String host);
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 7ec7754..c4c5b72 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,7 +300,7 @@ public class FtpConsumer extends RemoteFileConsumer<FTPFile> {
         return config.isUseList();
     }
 
-    @ManagedAttribute(description = "Description of last FTP download activity")
+    @ManagedAttribute(description = "Summary of last FTP activity (download only)")
     public String getLastFtpActivity() {
         FTPClient client = getOperations().getFtpClient();
         FtpClientActivityListener listener = (FtpClientActivityListener) client.getCopyStreamListener();
@@ -321,8 +321,8 @@ public class FtpConsumer extends RemoteFileConsumer<FTPFile> {
         return null;
     }
 
-    @ManagedAttribute(description = "Description of last FTP activity (verbose)")
-    public String getLastActivityVerbose() {
+    @ManagedAttribute(description = "Summary of last FTP activity (all)")
+    public String getLastFtpActivityVerbose() {
         FTPClient client = getOperations().getFtpClient();
         FtpClientActivityListener listener = (FtpClientActivityListener) client.getCopyStreamListener();
         if (listener != null) {
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 fdf064a..b349894 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
@@ -76,6 +76,15 @@ public class FtpOperations implements RemoteFileOperations<FTPFile>
{
         listener = new DefaultFtpClientActivityListener(transferLogger, endpoint.isTransferLoggingVerbose(),
endpoint.getConfiguration().remoteServerInformation());
         client.setCopyStreamListener(listener);
 
+        try {
+            return doConnect(configuration);
+        } catch (GenericFileOperationFailedException e) {
+            listener.onGeneralError(endpoint.getConfiguration().remoteServerInformation(),
e.getMessage());
+            throw e;
+        }
+    }
+
+    protected boolean doConnect(RemoteFileConfiguration configuration) throws GenericFileOperationFailedException
{
         log.trace("Connecting using FTPClient: {}", client);
 
         String host = configuration.getHost();
@@ -191,10 +200,9 @@ public class FtpOperations implements RemoteFileOperations<FTPFile>
{
                 // store replyString, because disconnect() will reset it
                 String replyString = client.getReplyString();
                 int replyCode = client.getReplyCode();
+                listener.onLoginFailed(replyCode, replyString);
                 // disconnect to prevent connection leaks
-                listener.onDisconnecting(host);
                 client.disconnect();
-                listener.onDisconnected(host);
                 throw new GenericFileOperationFailedException(replyCode, replyString);
             }
             listener.onLoginComplete(host);
@@ -228,6 +236,15 @@ public class FtpOperations implements RemoteFileOperations<FTPFile>
{
     }
 
     public void disconnect() throws GenericFileOperationFailedException {
+        try {
+            doDisconnect();
+        } catch (GenericFileOperationFailedException e) {
+            listener.onGeneralError(endpoint.getConfiguration().remoteServerInformation(),
e.getMessage());
+            throw e;
+        }
+    }
+
+    protected void doDisconnect() throws GenericFileOperationFailedException {
         // logout before disconnecting
         listener.onDisconnecting(endpoint.getConfiguration().remoteServerInformation());
         try {
@@ -332,13 +349,18 @@ public class FtpOperations implements RemoteFileOperations<FTPFile>
{
         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
-            answer = retrieveFileToFileInLocalWorkDirectory(name, exchange);
-        } else {
-            // store file content directory as stream on the body
-            answer = retrieveFileToStreamInBody(name, exchange);
+        try {
+            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
+                answer = retrieveFileToFileInLocalWorkDirectory(name, exchange);
+            } else {
+                // store file content directory as stream on the body
+                answer = retrieveFileToStreamInBody(name, exchange);
+            }
+        } catch (GenericFileOperationFailedException e) {
+            listener.onGeneralError(endpoint.getConfiguration().remoteServerInformation(),
e.getMessage());
+            throw e;
         }
 
         if (answer) {
@@ -555,6 +577,9 @@ public class FtpOperations implements RemoteFileOperations<FTPFile>
{
 
             // store the file
             answer = doStoreFile(name, targetName, exchange);
+        } catch (GenericFileOperationFailedException e) {
+            listener.onGeneralError(endpoint.getConfiguration().remoteServerInformation(),
e.getMessage());
+            throw e;
         } finally {
             // change back to current directory if we changed directory
             if (currentDir != null) {
@@ -845,6 +870,7 @@ public class FtpOperations implements RemoteFileOperations<FTPFile>
{
             }
             return list;
         } catch (IOException e) {
+            listener.onGeneralError(endpoint.getConfiguration().remoteServerInformation(),
e.getMessage());
             throw new GenericFileOperationFailedException(client.getReplyCode(), client.getReplyString(),
e.getMessage(), e);
         }
     }
@@ -867,6 +893,7 @@ public class FtpOperations implements RemoteFileOperations<FTPFile>
{
             }
             return list;
         } catch (IOException e) {
+            listener.onGeneralError(endpoint.getConfiguration().remoteServerInformation(),
e.getMessage());
             throw new GenericFileOperationFailedException(client.getReplyCode(), client.getReplyString(),
e.getMessage(), e);
         }
     }

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

Mime
View raw message