This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-2.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-2.x by this push:
new 94c88a7 CAMEL-14030: camel-ftp - streamDownload=true and move options
dont work. Thanks to Peter Nowak for reporting and the suggested fix.
94c88a7 is described below
commit 94c88a7d9745b5999c809baaa45fb06c8995202a
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Oct 3 09:55:21 2019 +0200
CAMEL-14030: camel-ftp - streamDownload=true and move options dont work.
Thanks to Peter Nowak for reporting and the suggested fix.
---
.../strategy/GenericFileRenameProcessStrategy.java | 9 ++-
.../file/remote/FtpStreamingMoveTest.java | 77 ++++++++++++++++++++++
2 files changed, 84 insertions(+), 2 deletions(-)
diff --git
a/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameProcessStrategy.java
b/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameProcessStrategy.java
index ada2a9c..024bf45 100644
---
a/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameProcessStrategy.java
+++
b/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameProcessStrategy.java
@@ -93,6 +93,8 @@ public class GenericFileRenameProcessStrategy<T> extends
GenericFileProcessStrat
@Override
public void commit(GenericFileOperations<T> operations,
GenericFileEndpoint<T> endpoint, Exchange exchange, GenericFile<T> file) throws
Exception {
try {
+ operations.releaseRetrievedFileResources(exchange);
+
if (commitRenamer != null) {
// create a copy and bind the file to the exchange to be used
by the renamer to evaluate the file name
Exchange copy = ExchangeHelper.createCopy(exchange, true);
@@ -111,8 +113,11 @@ public class GenericFileRenameProcessStrategy<T> extends
GenericFileProcessStrat
renameFile(operations, file, newName);
}
} finally {
- // must invoke super
- super.commit(operations, endpoint, exchange, file);
+ deleteLocalWorkFile(exchange);
+ // must release lock last
+ if (exclusiveReadLockStrategy != null) {
+
exclusiveReadLockStrategy.releaseExclusiveReadLockOnCommit(operations, file,
exchange);
+ }
}
}
diff --git
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpStreamingMoveTest.java
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpStreamingMoveTest.java
new file mode 100644
index 0000000..45f4bb2
--- /dev/null
+++
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpStreamingMoveTest.java
@@ -0,0 +1,77 @@
+/**
+ * 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 java.io.File;
+import java.io.InputStream;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.file.GenericFile;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Before;
+import org.junit.Test;
+
+public class FtpStreamingMoveTest extends FtpServerTestSupport {
+
+ private String getFtpUrl() {
+ return "ftp://admin@localhost:" + getPort() +
"/mymove?password=admin&delay=1000&streamDownload=true&move=done";
+ }
+
+ @Override
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ deleteDirectory("target/mymove");
+ }
+
+ @Test
+ public void testStreamDownloadMove() throws Exception {
+ if (!canTest()) {
+ return;
+ }
+
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedBodiesReceived("Hello World");
+
+ sendFile(getFtpUrl(), "Hello World", "hello.txt");
+
+ context.getRouteController().startRoute("foo");
+
+ assertMockEndpointsSatisfied();
+
+ GenericFile<?> remoteFile = (GenericFile<?>)
mock.getExchanges().get(0).getIn().getBody();
+ assertTrue(remoteFile.getBody() instanceof InputStream);
+
+ // give time for consumer to rename file
+ Thread.sleep(1000);
+
+ File file = new File(FTP_ROOT_DIR + "/mymove/done/hello.txt");
+ assertTrue("File should have been renamed", file.exists());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from(getFtpUrl())
+ .routeId("foo").noAutoStartup()
+ .to("mock:result");
+ }
+ };
+ }
+}