You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by on...@apache.org on 2017/06/25 16:37:31 UTC
[1/2] camel git commit: CAMEL-11437 - probeContentType and preMove
attributes causes Exchange.FILE_CONTENT_TYPE to get dropped
Repository: camel
Updated Branches:
refs/heads/camel-2.19.x d759b51d2 -> 00332ef5a
CAMEL-11437 - probeContentType and preMove attributes causes Exchange.FILE_CONTENT_TYPE to get dropped
CAMEL-11437 - self review
CAMEL-11437 - defaulted super.populateHeaders with false flag as there is not such `probeContentType` option in ftp/sftp endpoints
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/45b18d91
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/45b18d91
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/45b18d91
Branch: refs/heads/camel-2.19.x
Commit: 45b18d91f36ca405ead08af5c21066056d1d5019
Parents: d759b51
Author: onders86 <on...@gmail.com>
Authored: Fri Jun 23 12:17:22 2017 +0300
Committer: onders86 <on...@gmail.com>
Committed: Sun Jun 25 19:14:42 2017 +0300
----------------------------------------------------------------------
.../camel/component/file/FileEndpoint.java | 2 +-
.../camel/component/file/GenericFile.java | 20 +++++--
.../GenericFileRenameProcessStrategy.java | 33 ++++++++++--
...ConsumerPreMoveWithProbeContentTypeTest.java | 55 ++++++++++++++++++++
.../component/file/GenericFileMessageTest.java | 2 +-
.../camel/component/file/remote/RemoteFile.java | 5 +-
6 files changed, 108 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/45b18d91/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java b/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
index 8a1ed20..0bbd860 100644
--- a/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
+++ b/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
@@ -140,7 +140,7 @@ public class FileEndpoint extends GenericFileEndpoint<File> {
public Exchange createExchange(GenericFile<File> file) {
Exchange exchange = createExchange();
if (file != null) {
- file.bindToExchange(exchange);
+ file.bindToExchange(exchange, probeContentType);
}
return exchange;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/45b18d91/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java b/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
index 2e3fee3..6edc41f 100644
--- a/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
+++ b/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
@@ -21,6 +21,7 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
+import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.WrappedFile;
import org.apache.camel.util.FileUtil;
@@ -113,6 +114,19 @@ public class GenericFile<T> implements WrappedFile<T> {
* Bind this GenericFile to an Exchange
*/
public void bindToExchange(Exchange exchange) {
+ GenericFileMessage<T> msg = commonBindToExchange(exchange);
+ populateHeaders(msg, false);
+ }
+
+ /**
+ * Bind this GenericFile to an Exchange
+ */
+ public void bindToExchange(Exchange exchange, boolean isProbeContentTypeFromEndpoint) {
+ GenericFileMessage<T> msg = commonBindToExchange(exchange);
+ populateHeaders(msg, isProbeContentTypeFromEndpoint);
+ }
+
+ private GenericFileMessage<T> commonBindToExchange(Exchange exchange) {
Map<String, Object> headers;
exchange.setProperty(FileComponent.FILE_EXCHANGE_FILE, this);
@@ -131,7 +145,7 @@ public class GenericFile<T> implements WrappedFile<T> {
// remove any file related headers, as we will re-populate file headers
msg.removeHeaders("CamelFile*");
}
- populateHeaders(msg);
+ return msg;
}
/**
@@ -139,7 +153,7 @@ public class GenericFile<T> implements WrappedFile<T> {
*
* @param message the message to populate with headers
*/
- public void populateHeaders(GenericFileMessage<T> message) {
+ public void populateHeaders(GenericFileMessage<T> message, boolean isProbeContentTypeFromEndpoint) {
if (message != null) {
message.setHeader(Exchange.FILE_NAME_ONLY, getFileNameOnly());
message.setHeader(Exchange.FILE_NAME, getFileName());
@@ -151,7 +165,7 @@ public class GenericFile<T> implements WrappedFile<T> {
message.setHeader("CamelFileExtendedAttributes", extendedAttributes);
}
- if (probeContentType && file instanceof File) {
+ if ((isProbeContentTypeFromEndpoint || probeContentType) && file instanceof File) {
File f = (File) file;
Path path = f.toPath();
try {
http://git-wip-us.apache.org/repos/asf/camel/blob/45b18d91/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameProcessStrategy.java
----------------------------------------------------------------------
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 9271b0f..fbf684b 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
@@ -17,6 +17,7 @@
package org.apache.camel.component.file.strategy;
import org.apache.camel.Exchange;
+import org.apache.camel.component.file.FileEndpoint;
import org.apache.camel.component.file.GenericFile;
import org.apache.camel.component.file.GenericFileEndpoint;
import org.apache.camel.component.file.GenericFileOperations;
@@ -41,9 +42,18 @@ public class GenericFileRenameProcessStrategy<T> extends GenericFileProcessStrat
if (beginRenamer != null) {
GenericFile<T> newName = beginRenamer.renameFile(exchange, file);
GenericFile<T> to = renameFile(operations, file, newName);
- if (to != null) {
- to.bindToExchange(exchange);
+ FileEndpoint fe = null;
+ if (endpoint instanceof FileEndpoint) {
+ fe = (FileEndpoint)endpoint;
+ if (to != null) {
+ to.bindToExchange(exchange, fe.isProbeContentType());
+ }
+ } else {
+ if (to != null) {
+ to.bindToExchange(exchange);
+ }
}
+
}
return true;
@@ -56,8 +66,19 @@ public class GenericFileRenameProcessStrategy<T> extends GenericFileProcessStrat
if (failureRenamer != null) {
// create a copy and bind the file to the exchange to be used by the renamer to evaluate the file name
+<<<<<<< HEAD
Exchange copy = exchange.copy();
file.bindToExchange(copy);
+=======
+ Exchange copy = ExchangeHelper.createCopy(exchange, true);
+ FileEndpoint fe = null;
+ if (endpoint instanceof FileEndpoint) {
+ fe = (FileEndpoint)endpoint;
+ file.bindToExchange(copy, fe.isProbeContentType());
+ } else {
+ file.bindToExchange(copy);
+ }
+>>>>>>> e3a1bdb... CAMEL-11437 - probeContentType and preMove attributes causes Exchange.FILE_CONTENT_TYPE to get dropped
// must preserve message id
copy.getIn().setMessageId(exchange.getIn().getMessageId());
copy.setExchangeId(exchange.getExchangeId());
@@ -79,7 +100,13 @@ public class GenericFileRenameProcessStrategy<T> extends GenericFileProcessStrat
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 = exchange.copy();
- file.bindToExchange(copy);
+ FileEndpoint fe = null;
+ if (endpoint instanceof FileEndpoint) {
+ fe = (FileEndpoint)endpoint;
+ file.bindToExchange(copy, fe.isProbeContentType());
+ } else {
+ file.bindToExchange(copy);
+ }
// must preserve message id
copy.getIn().setMessageId(exchange.getIn().getMessageId());
copy.setExchangeId(exchange.getExchangeId());
http://git-wip-us.apache.org/repos/asf/camel/blob/45b18d91/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPreMoveWithProbeContentTypeTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPreMoveWithProbeContentTypeTest.java b/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPreMoveWithProbeContentTypeTest.java
new file mode 100644
index 0000000..d4a4848
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPreMoveWithProbeContentTypeTest.java
@@ -0,0 +1,55 @@
+/**
+ * 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;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * @version
+ */
+public class FileConsumerPreMoveWithProbeContentTypeTest extends ContextTestSupport {
+
+ @Override
+ protected void setUp() throws Exception {
+ deleteDirectory("target/premove");
+ super.setUp();
+ }
+
+ public void testContentTypeWithPremoveAndProbeContentTypeOptions() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedBodiesReceived("Hello World");
+ mock.expectedHeaderReceived(Exchange.FILE_CONTENT_TYPE, "txt");
+
+ template.sendBodyAndHeader("file://target/premove", "Hello World", Exchange.FILE_NAME, "hello.txt");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("file://target/premove?probeContentType=true&preMove=work/work-${file:name}&initialDelay=0&delay=100")
+ .to("mock:result");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/45b18d91/camel-core/src/test/java/org/apache/camel/component/file/GenericFileMessageTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/file/GenericFileMessageTest.java b/camel-core/src/test/java/org/apache/camel/component/file/GenericFileMessageTest.java
index 6108029..6f45ed3 100644
--- a/camel-core/src/test/java/org/apache/camel/component/file/GenericFileMessageTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/file/GenericFileMessageTest.java
@@ -42,7 +42,7 @@ public class GenericFileMessageTest extends ContextTestSupport {
file.setFileName("target");
file.setFile(new File("target/camel-core-test.log"));
GenericFileMessage<File> message = new GenericFileMessage<File>(file);
- file.populateHeaders(message);
+ file.populateHeaders(message, false);
assertEquals("Get a wrong file content type", "txt", message.getHeader(Exchange.FILE_CONTENT_TYPE));
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/45b18d91/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFile.java
----------------------------------------------------------------------
diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFile.java b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFile.java
index 60f9199..cd1d18e 100644
--- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFile.java
+++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFile.java
@@ -35,7 +35,10 @@ public class RemoteFile<T> extends GenericFile<T> implements Cloneable {
*/
public void populateHeaders(GenericFileMessage<T> message) {
if (message != null) {
- super.populateHeaders(message);
+ // because there is not probeContentType option
+ // in other file based components, false may be passed
+ // as the second argument.
+ super.populateHeaders(message, false);
message.setHeader("CamelFileHost", getHostname());
}
}
[2/2] camel git commit: CAMEL-11437-resolve conflict
Posted by on...@apache.org.
CAMEL-11437-resolve conflict
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/00332ef5
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/00332ef5
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/00332ef5
Branch: refs/heads/camel-2.19.x
Commit: 00332ef5a01ca92cd06ca074cc2ef19e2107682f
Parents: 45b18d9
Author: onders86 <on...@gmail.com>
Authored: Sun Jun 25 19:32:03 2017 +0300
Committer: onders86 <on...@gmail.com>
Committed: Sun Jun 25 19:32:03 2017 +0300
----------------------------------------------------------------------
.../file/strategy/GenericFileRenameProcessStrategy.java | 5 -----
1 file changed, 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/00332ef5/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameProcessStrategy.java
----------------------------------------------------------------------
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 fbf684b..b02ce0a 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
@@ -66,11 +66,7 @@ public class GenericFileRenameProcessStrategy<T> extends GenericFileProcessStrat
if (failureRenamer != null) {
// create a copy and bind the file to the exchange to be used by the renamer to evaluate the file name
-<<<<<<< HEAD
Exchange copy = exchange.copy();
- file.bindToExchange(copy);
-=======
- Exchange copy = ExchangeHelper.createCopy(exchange, true);
FileEndpoint fe = null;
if (endpoint instanceof FileEndpoint) {
fe = (FileEndpoint)endpoint;
@@ -78,7 +74,6 @@ public class GenericFileRenameProcessStrategy<T> extends GenericFileProcessStrat
} else {
file.bindToExchange(copy);
}
->>>>>>> e3a1bdb... CAMEL-11437 - probeContentType and preMove attributes causes Exchange.FILE_CONTENT_TYPE to get dropped
// must preserve message id
copy.getIn().setMessageId(exchange.getIn().getMessageId());
copy.setExchangeId(exchange.getExchangeId());