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
The following commit(s) were added to refs/heads/master by this push:
new 7c356e4 CAMEL-14936: Avoid last bit of reflection in file/ftp
components.
7c356e4 is described below
commit 7c356e441af82acfb504ef0007da94e5f1d39d3b
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue Apr 21 15:54:03 2020 +0200
CAMEL-14936: Avoid last bit of reflection in file/ftp components.
---
.../java/org/apache/camel/component/file/FileOperations.java | 5 +++++
.../java/org/apache/camel/component/file/GenericFile.java | 12 +++---------
.../apache/camel/component/file/GenericFileOperations.java | 6 ++++++
.../file/strategy/GenericFileDeleteProcessStrategy.java | 4 ++--
.../file/strategy/GenericFileExpressionRenamer.java | 6 ++++--
.../strategy/GenericFileRenameExclusiveReadLockStrategy.java | 3 ++-
.../file/strategy/GenericFileRenameProcessStrategy.java | 6 +++---
.../camel/component/file/strategy/GenericFileRenamer.java | 4 +++-
.../apache/camel/component/file/remote/FtpOperations.java | 5 +++++
.../apache/camel/component/file/remote/SftpOperations.java | 6 ++++++
.../java/org/apache/camel/component/scp/ScpOperations.java | 7 +++++++
.../file/strategy/GenericFileDeleteProcessStrategyTest.java | 5 +++++
12 files changed, 51 insertions(+), 18 deletions(-)
diff --git
a/components/camel-file/src/main/java/org/apache/camel/component/file/FileOperations.java
b/components/camel-file/src/main/java/org/apache/camel/component/file/FileOperations.java
index de6f025..68a1851 100644
---
a/components/camel-file/src/main/java/org/apache/camel/component/file/FileOperations.java
+++
b/components/camel-file/src/main/java/org/apache/camel/component/file/FileOperations.java
@@ -58,6 +58,11 @@ public class FileOperations implements
GenericFileOperations<File> {
public FileOperations() {
}
+ @Override
+ public GenericFile<File> newGenericFile() {
+ return new GenericFile<>();
+ }
+
public FileOperations(FileEndpoint endpoint) {
this.endpoint = endpoint;
}
diff --git
a/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFile.java
b/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFile.java
index c2b1d60..c0527c1 100644
---
a/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFile.java
+++
b/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFile.java
@@ -70,16 +70,11 @@ public class GenericFile<T> implements WrappedFile<T> {
* Creates a copy based on the source
*
* @param source the source
- * @return a copy of the source
+ * @param result the result
*/
@SuppressWarnings("unchecked")
- public GenericFile<T> copyFrom(GenericFile<T> source) {
- GenericFile<T> result;
- try {
- result = source.getClass().newInstance();
- } catch (Exception e) {
- throw RuntimeCamelException.wrapRuntimeCamelException(e);
- }
+ @Deprecated
+ public void copyFrom(GenericFile source, GenericFile result) {
result.setCopyFromAbsoluteFilePath(source.getAbsoluteFilePath());
result.setEndpointPath(source.getEndpointPath());
result.setAbsolute(source.isAbsolute());
@@ -96,7 +91,6 @@ public class GenericFile<T> implements WrappedFile<T> {
result.setCharset(source.getCharset());
copyFromPopulateAdditional(source, result);
- return result;
}
/**
diff --git
a/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileOperations.java
b/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileOperations.java
index 8281a5c..21ff471 100644
---
a/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileOperations.java
+++
b/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileOperations.java
@@ -23,6 +23,11 @@ import org.apache.camel.Exchange;
public interface GenericFileOperations<T> {
/**
+ * Creates a new instance of {@link GenericFile}
+ */
+ GenericFile<T> newGenericFile();
+
+ /**
* Sets the endpoint as some implementations need access to the endpoint
and
* how its configured.
*
@@ -138,4 +143,5 @@ public interface GenericFileOperations<T> {
* @throws GenericFileOperationFailedException can be thrown
*/
List<T> listFiles(String path) throws GenericFileOperationFailedException;
+
}
diff --git
a/components/camel-file/src/main/java/org/apache/camel/component/file/strategy/GenericFileDeleteProcessStrategy.java
b/components/camel-file/src/main/java/org/apache/camel/component/file/strategy/GenericFileDeleteProcessStrategy.java
index 023fafd..449d52a 100644
---
a/components/camel-file/src/main/java/org/apache/camel/component/file/strategy/GenericFileDeleteProcessStrategy.java
+++
b/components/camel-file/src/main/java/org/apache/camel/component/file/strategy/GenericFileDeleteProcessStrategy.java
@@ -43,7 +43,7 @@ public class GenericFileDeleteProcessStrategy<T> extends
GenericFileProcessStrat
// okay we got the file then execute the begin renamer
if (beginRenamer != null) {
- GenericFile<T> newName = beginRenamer.renameFile(exchange, file);
+ GenericFile<T> newName = beginRenamer.renameFile(operations,
exchange, file);
GenericFile<T> to = renameFile(operations, file, newName);
if (to != null) {
to.bindToExchange(exchange);
@@ -119,7 +119,7 @@ public class GenericFileDeleteProcessStrategy<T> extends
GenericFileProcessStrat
copy.getIn().setMessageId(exchange.getIn().getMessageId());
copy.setExchangeId(exchange.getExchangeId());
- GenericFile<T> newName = failureRenamer.renameFile(copy, file);
+ GenericFile<T> newName = failureRenamer.renameFile(operations,
copy, file);
renameFile(operations, file, newName);
}
} finally {
diff --git
a/components/camel-file/src/main/java/org/apache/camel/component/file/strategy/GenericFileExpressionRenamer.java
b/components/camel-file/src/main/java/org/apache/camel/component/file/strategy/GenericFileExpressionRenamer.java
index 59a977c..d7ac1e2 100644
---
a/components/camel-file/src/main/java/org/apache/camel/component/file/strategy/GenericFileExpressionRenamer.java
+++
b/components/camel-file/src/main/java/org/apache/camel/component/file/strategy/GenericFileExpressionRenamer.java
@@ -19,6 +19,7 @@ package org.apache.camel.component.file.strategy;
import org.apache.camel.Exchange;
import org.apache.camel.Expression;
import org.apache.camel.component.file.GenericFile;
+import org.apache.camel.component.file.GenericFileOperations;
import org.apache.camel.util.ObjectHelper;
public class GenericFileExpressionRenamer<T> implements GenericFileRenamer<T> {
@@ -32,13 +33,14 @@ public class GenericFileExpressionRenamer<T> implements
GenericFileRenamer<T> {
}
@Override
- public GenericFile<T> renameFile(Exchange exchange, GenericFile<T> file) {
+ public GenericFile<T> renameFile(GenericFileOperations<T> operations,
Exchange exchange, GenericFile<T> file) {
ObjectHelper.notNull(expression, "expression");
String newName = expression.evaluate(exchange, String.class);
// make a copy as result and change its file name
- GenericFile<T> result = file.copyFrom(file);
+ GenericFile<T> result = operations.newGenericFile();
+ file.copyFrom(file, result);
result.changeFileName(newName);
return result;
}
diff --git
a/components/camel-file/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameExclusiveReadLockStrategy.java
b/components/camel-file/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameExclusiveReadLockStrategy.java
index 2b0c9ab..de55763 100644
---
a/components/camel-file/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameExclusiveReadLockStrategy.java
+++
b/components/camel-file/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameExclusiveReadLockStrategy.java
@@ -57,7 +57,8 @@ public class GenericFileRenameExclusiveReadLockStrategy<T>
implements GenericFil
String newName = file.getFileName() + ".camelExclusiveReadLock";
// make a copy as result and change its file name
- GenericFile<T> newFile = file.copyFrom(file);
+ GenericFile<T> newFile = operations.newGenericFile();
+ file.copyFrom(file, newFile);
newFile.changeFileName(newName);
StopWatch watch = new StopWatch();
diff --git
a/components/camel-file/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameProcessStrategy.java
b/components/camel-file/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameProcessStrategy.java
index 64cb82a..8cd6daa 100644
---
a/components/camel-file/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameProcessStrategy.java
+++
b/components/camel-file/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameProcessStrategy.java
@@ -41,7 +41,7 @@ public class GenericFileRenameProcessStrategy<T> extends
GenericFileProcessStrat
// okay we got the file then execute the begin renamer
if (beginRenamer != null) {
- GenericFile<T> newName = beginRenamer.renameFile(exchange, file);
+ GenericFile<T> newName = beginRenamer.renameFile(operations,
exchange, file);
GenericFile<T> to = renameFile(operations, file, newName);
FileEndpoint fe = null;
if (endpoint instanceof FileEndpoint) {
@@ -80,7 +80,7 @@ public class GenericFileRenameProcessStrategy<T> extends
GenericFileProcessStrat
copy.getIn().setMessageId(exchange.getIn().getMessageId());
copy.setExchangeId(exchange.getExchangeId());
- GenericFile<T> newName = failureRenamer.renameFile(copy, file);
+ GenericFile<T> newName = failureRenamer.renameFile(operations,
copy, file);
renameFile(operations, file, newName);
}
} finally {
@@ -111,7 +111,7 @@ public class GenericFileRenameProcessStrategy<T> extends
GenericFileProcessStrat
copy.getIn().setMessageId(exchange.getIn().getMessageId());
copy.setExchangeId(exchange.getExchangeId());
- GenericFile<T> newName = commitRenamer.renameFile(copy, file);
+ GenericFile<T> newName = commitRenamer.renameFile(operations,
copy, file);
renameFile(operations, file, newName);
}
} finally {
diff --git
a/components/camel-file/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenamer.java
b/components/camel-file/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenamer.java
index 7614834..c6452c5 100644
---
a/components/camel-file/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenamer.java
+++
b/components/camel-file/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenamer.java
@@ -18,6 +18,7 @@ package org.apache.camel.component.file.strategy;
import org.apache.camel.Exchange;
import org.apache.camel.component.file.GenericFile;
+import org.apache.camel.component.file.GenericFileOperations;
/**
* Used for renaming files.
@@ -27,9 +28,10 @@ public interface GenericFileRenamer<T> {
/**
* Renames the given file
*
+ * @param operations the generic file operations
* @param exchange the exchange
* @param file the original file.
* @return the renamed file name.
*/
- GenericFile<T> renameFile(Exchange exchange, GenericFile<T> file);
+ GenericFile<T> renameFile(GenericFileOperations<T> operations, Exchange
exchange, GenericFile<T> file);
}
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 046feb1..5837418 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
@@ -80,6 +80,11 @@ public class FtpOperations implements
RemoteFileOperations<FTPFile> {
}
@Override
+ public GenericFile<FTPFile> newGenericFile() {
+ return new RemoteFile<>();
+ }
+
+ @Override
public boolean connect(RemoteFileConfiguration configuration, Exchange
exchange) throws GenericFileOperationFailedException {
client.setCopyStreamListener(clientActivityListener);
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 c25cec0..6203e2f 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
@@ -59,6 +59,7 @@ import org.apache.camel.util.IOHelper;
import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.StopWatch;
import org.apache.camel.util.TimeUtils;
+import org.apache.commons.net.ftp.FTPFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -100,6 +101,11 @@ public class SftpOperations implements
RemoteFileOperations<SftpRemoteFile> {
}
@Override
+ public GenericFile<SftpRemoteFile> newGenericFile() {
+ return new RemoteFile<>();
+ }
+
+ @Override
public synchronized boolean connect(RemoteFileConfiguration configuration,
Exchange exchange) throws GenericFileOperationFailedException {
if (isConnected()) {
// already connected
diff --git
a/components/camel-jsch/src/main/java/org/apache/camel/component/scp/ScpOperations.java
b/components/camel-jsch/src/main/java/org/apache/camel/component/scp/ScpOperations.java
index 954d7e5..d775fe7 100644
---
a/components/camel-jsch/src/main/java/org/apache/camel/component/scp/ScpOperations.java
+++
b/components/camel-jsch/src/main/java/org/apache/camel/component/scp/ScpOperations.java
@@ -34,8 +34,10 @@ import com.jcraft.jsch.UIKeyboardInteractive;
import com.jcraft.jsch.UserInfo;
import org.apache.camel.Exchange;
import org.apache.camel.InvalidPayloadException;
+import org.apache.camel.component.file.GenericFile;
import org.apache.camel.component.file.GenericFileEndpoint;
import org.apache.camel.component.file.GenericFileOperationFailedException;
+import org.apache.camel.component.file.remote.RemoteFile;
import org.apache.camel.component.file.remote.RemoteFileConfiguration;
import org.apache.camel.component.file.remote.RemoteFileOperations;
import org.apache.camel.support.ResourceHelper;
@@ -56,6 +58,11 @@ public class ScpOperations implements
RemoteFileOperations<ScpFile> {
private String userKnownHostFile;
@Override
+ public GenericFile<ScpFile> newGenericFile() {
+ return new RemoteFile<>();
+ }
+
+ @Override
public void setEndpoint(GenericFileEndpoint<ScpFile> endpoint) {
this.endpoint = (ScpEndpoint)endpoint;
}
diff --git
a/core/camel-core/src/test/java/org/apache/camel/component/file/strategy/GenericFileDeleteProcessStrategyTest.java
b/core/camel-core/src/test/java/org/apache/camel/component/file/strategy/GenericFileDeleteProcessStrategyTest.java
index 5c58277..718f49f 100644
---
a/core/camel-core/src/test/java/org/apache/camel/component/file/strategy/GenericFileDeleteProcessStrategyTest.java
+++
b/core/camel-core/src/test/java/org/apache/camel/component/file/strategy/GenericFileDeleteProcessStrategyTest.java
@@ -39,6 +39,11 @@ public class GenericFileDeleteProcessStrategyTest extends
ContextTestSupport {
private static class MyGenericFileOperations implements
GenericFileOperations<Object> {
@Override
+ public GenericFile<Object> newGenericFile() {
+ return null;
+ }
+
+ @Override
public void setEndpoint(GenericFileEndpoint<Object> endpoint) {
}