This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new fa79138 (chores) camel-ftp cleanup (#5689)
fa79138 is described below
commit fa7913859bae5350cc21fcf839e73833a7bda8e5
Author: Otavio Rodolfo Piske <[email protected]>
AuthorDate: Thu Jun 17 12:46:17 2021 +0200
(chores) camel-ftp cleanup (#5689)
- removed unused imports
- simplified exception handling
- used log markers in some log messages
- removed exceptions not thrown from method signatures
---
.../component/file/remote/CamelFTPParserFactory.java | 1 -
.../org/apache/camel/component/file/remote/FtpUtils.java | 6 +++---
.../camel/component/file/remote/FtpsOperations.java | 5 -----
.../camel/component/file/remote/RemoteFileConsumer.java | 3 +--
.../camel/component/file/remote/RemoteFileEndpoint.java | 2 +-
.../camel/component/file/remote/SftpOperations.java | 16 ++++++----------
6 files changed, 11 insertions(+), 22 deletions(-)
diff --git
a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/CamelFTPParserFactory.java
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/CamelFTPParserFactory.java
index 52928ec..06d8509 100644
---
a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/CamelFTPParserFactory.java
+++
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/CamelFTPParserFactory.java
@@ -16,7 +16,6 @@
*/
package org.apache.camel.component.file.remote;
-import java.util.Locale;
import java.util.regex.Pattern;
import org.apache.camel.spi.ClassResolver;
diff --git
a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpUtils.java
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpUtils.java
index 30d402d..b8035bf 100644
---
a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpUtils.java
+++
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpUtils.java
@@ -133,9 +133,9 @@ public final class FtpUtils {
public static void ensureRelativeFtpDirectory(Component ftpComponent,
RemoteFileConfiguration configuration) {
if (FileUtil.hasLeadingSeparator(configuration.getDirectoryName())) {
String relativePath =
FileUtil.stripLeadingSeparator(configuration.getDirectoryName());
- LOG.warn(String.format("%s doesn't support absolute paths, \"%s\"
will be converted to \"%s\". "
- + "After Camel 2.16, absolute paths will be
invalid.",
- ftpComponent.getClass().getSimpleName(),
configuration.getDirectoryName(), relativePath));
+ LOG.warn("{} doesn't support absolute paths, \"{}\" will be
converted to \"{}\". "
+ + "After Camel 2.16, absolute paths will be invalid.",
+ ftpComponent.getClass().getSimpleName(),
configuration.getDirectoryName(), relativePath);
configuration.setDirectory(relativePath);
configuration.setDirectoryName(relativePath);
}
diff --git
a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpsOperations.java
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpsOperations.java
index af04893..4c77fb8 100644
---
a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpsOperations.java
+++
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpsOperations.java
@@ -18,8 +18,6 @@ package org.apache.camel.component.file.remote;
import java.io.IOException;
-import javax.net.ssl.SSLException;
-
import org.apache.camel.Exchange;
import org.apache.camel.component.file.GenericFileOperationFailedException;
import org.apache.camel.util.ObjectHelper;
@@ -64,9 +62,6 @@ public class FtpsOperations extends FtpOperations {
log.debug("FTPClient initializing with execProt={}",
execProt);
getFtpClient().execPROT(execProt);
}
- } catch (SSLException e) {
- throw new GenericFileOperationFailedException(
- client.getReplyCode(), client.getReplyString(),
e.getMessage(), e);
} catch (IOException e) {
throw new GenericFileOperationFailedException(
client.getReplyCode(), client.getReplyString(),
e.getMessage(), e);
diff --git
a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java
index 9a651e5..1666564 100644
---
a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java
+++
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java
@@ -16,7 +16,6 @@
*/
package org.apache.camel.component.file.remote;
-import java.io.IOException;
import java.util.List;
import org.apache.camel.Exchange;
@@ -216,7 +215,7 @@ public abstract class RemoteFileConsumer<T> extends
GenericFileConsumer<T> {
}
}
- protected void connectIfNecessary() throws IOException {
+ protected void connectIfNecessary() {
// We need to send a noop first to check if the connection is still
open
boolean isConnected = false;
try {
diff --git
a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
index 32db3d6..e51c780 100644
---
a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
+++
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
@@ -181,7 +181,7 @@ public abstract class RemoteFileEndpoint<T> extends
GenericFileEndpoint<T> {
*
* @throws Exception is thrown if endpoint is invalid configured for its
mandatory options
*/
- protected void afterPropertiesSet() throws Exception {
+ protected void afterPropertiesSet() {
RemoteFileConfiguration config = getConfiguration();
StringHelper.notEmpty(config.getHost(), "host");
StringHelper.notEmpty(config.getProtocol(), "protocol");
diff --git
a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
index 0433907..869c390 100644
---
a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
+++
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
@@ -26,7 +26,6 @@ import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.Socket;
-import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.security.KeyPair;
import java.util.ArrayList;
@@ -391,7 +390,7 @@ public class SftpOperations implements
RemoteFileOperations<SftpRemoteFile> {
}
@Override
- public Socket createSocket(String host, int port) throws
IOException, UnknownHostException {
+ public Socket createSocket(String host, int port) throws
IOException {
return createSocketUtil(host, port,
sftpConfig.getBindAddress(), session.getTimeout());
}
});
@@ -493,7 +492,7 @@ public class SftpOperations implements
RemoteFileOperations<SftpRemoteFile> {
channel.rm(name);
return true;
} catch (SftpException e) {
- LOG.debug("Cannot delete file: {}", name, e);
+ LOG.debug("Cannot delete file {}: {}", name, e.getMessage(), e);
throw new GenericFileOperationFailedException("Cannot delete file:
" + name, e);
}
}
@@ -555,7 +554,7 @@ public class SftpOperations implements
RemoteFileOperations<SftpRemoteFile> {
success = buildDirectoryChunks(directory);
}
}
- } catch (IOException | SftpException e) {
+ } catch (SftpException e) {
throw new GenericFileOperationFailedException("Cannot build
directory: " + directory, e);
} finally {
// change back to original directory
@@ -566,7 +565,7 @@ public class SftpOperations implements
RemoteFileOperations<SftpRemoteFile> {
return success;
}
- private boolean buildDirectoryChunks(String dirName) throws IOException,
SftpException {
+ private boolean buildDirectoryChunks(String dirName) throws SftpException {
final StringBuilder sb = new StringBuilder(dirName.length());
final String[] dirs = dirName.split("/|\\\\");
@@ -1020,7 +1019,7 @@ public class SftpOperations implements
RemoteFileOperations<SftpRemoteFile> {
if (LOG.isDebugEnabled()) {
long time = watch.taken();
LOG.debug("Took {} ({} millis) to store file: {} and FTP
client returned: true",
- new Object[] { TimeUtils.printDuration(time), time,
targetName });
+ TimeUtils.printDuration(time), time, targetName);
}
// after storing file, we may set chmod on the file
@@ -1157,10 +1156,7 @@ public class SftpOperations implements
RemoteFileOperations<SftpRemoteFile> {
} catch (Exception e) {
ee[0] = e;
if (sockp[0] != null && sockp[0].isConnected()) {
- try {
- sockp[0].close();
- } catch (Exception eee) {
- }
+ IOHelper.close(sockp[0]);
}
sockp[0] = null;
}