You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2015/07/16 21:55:04 UTC
[1/4] camel git commit: CAMEL-8954: File componet readlock state
should be per file so its possible to use pollEnrich to poll in a 2nd file
and keep those state separated. Thanks to Andy Fedotov for unit test.
Repository: camel
Updated Branches:
refs/heads/camel-2.15.x 6cb8770ee -> 9f26e12a6
refs/heads/master 1af2133f6 -> d7b8afc74
CAMEL-8954: File componet readlock state should be per file so its possible to use pollEnrich to poll in a 2nd file and keep those state separated. Thanks to Andy Fedotov for unit test.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/7b1253db
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/7b1253db
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/7b1253db
Branch: refs/heads/master
Commit: 7b1253db516a39a1fe75440ad1226f8fbd60f2c3
Parents: 1af2133
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Jul 16 19:39:55 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Jul 16 20:44:33 2015 +0200
----------------------------------------------------------------------
.../camel/component/file/GenericFile.java | 10 +++
.../FileLockExclusiveReadLockStrategy.java | 21 ++++--
.../MarkerFileExclusiveReadLockStrategy.java | 20 ++++--
...FileExclusiveReadLockStrategyUnlockTest.java | 73 ++++++++++++++++++++
4 files changed, 114 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/7b1253db/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 343d836..907de21 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
@@ -35,6 +35,7 @@ import org.slf4j.LoggerFactory;
public class GenericFile<T> implements WrappedFile<T> {
private static final Logger LOG = LoggerFactory.getLogger(GenericFile.class);
+ private String copyFromAbsoluteFilePath;
private String endpointPath;
private String fileName;
private String fileNameOnly;
@@ -66,6 +67,7 @@ public class GenericFile<T> implements WrappedFile<T> {
} catch (Exception e) {
throw ObjectHelper.wrapRuntimeCamelException(e);
}
+ result.setCopyFromAbsoluteFilePath(source.getAbsoluteFilePath());
result.setEndpointPath(source.getEndpointPath());
result.setAbsolute(source.isAbsolute());
result.setDirectory(source.isDirectory());
@@ -365,6 +367,14 @@ public class GenericFile<T> implements WrappedFile<T> {
this.directory = directory;
}
+ public String getCopyFromAbsoluteFilePath() {
+ return copyFromAbsoluteFilePath;
+ }
+
+ public void setCopyFromAbsoluteFilePath(String copyFromAbsoluteFilePath) {
+ this.copyFromAbsoluteFilePath = copyFromAbsoluteFilePath;
+ }
+
/**
* Fixes the path separator to be according to the protocol
*/
http://git-wip-us.apache.org/repos/asf/camel/blob/7b1253db/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java b/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java
index 8fd94f5..de5101f 100644
--- a/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java
+++ b/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java
@@ -127,10 +127,11 @@ public class FileLockExclusiveReadLockStrategy extends MarkerFileExclusiveReadLo
}
}
- // we grabbed the lock
- exchange.setProperty(Exchange.FILE_LOCK_EXCLUSIVE_LOCK, lock);
- exchange.setProperty(Exchange.FILE_LOCK_RANDOM_ACCESS_FILE, randomAccessFile);
+ // store read-lock state
+ exchange.setProperty(asReadLockKey(file, Exchange.FILE_LOCK_EXCLUSIVE_LOCK), lock);
+ exchange.setProperty(asReadLockKey(file, Exchange.FILE_LOCK_RANDOM_ACCESS_FILE), randomAccessFile);
+ // we grabbed the lock
return true;
}
@@ -140,10 +141,10 @@ public class FileLockExclusiveReadLockStrategy extends MarkerFileExclusiveReadLo
// must call super
super.doReleaseExclusiveReadLock(operations, file, exchange);
- String target = file.getFileName();
- FileLock lock = exchange.getProperty(Exchange.FILE_LOCK_EXCLUSIVE_LOCK, FileLock.class);
- RandomAccessFile rac = exchange.getProperty(Exchange.FILE_LOCK_RANDOM_ACCESS_FILE, RandomAccessFile.class);
+ FileLock lock = exchange.getProperty(asReadLockKey(file, Exchange.FILE_LOCK_EXCLUSIVE_LOCK), FileLock.class);
+ RandomAccessFile rac = exchange.getProperty(asReadLockKey(file, Exchange.FILE_LOCK_EXCLUSIVE_LOCK), RandomAccessFile.class);
+ String target = file.getFileName();
if (lock != null) {
Channel channel = lock.acquiredBy();
try {
@@ -186,4 +187,12 @@ public class FileLockExclusiveReadLockStrategy extends MarkerFileExclusiveReadLo
this.readLockLoggingLevel = readLockLoggingLevel;
}
+ private static String asReadLockKey(GenericFile file, String key) {
+ // use the copy from absolute path as that was the original path of the file when the lock was acquired
+ // for example if the file consumer uses preMove then the file is moved and therefore has another name
+ // that would no longer match
+ String path = file.getCopyFromAbsoluteFilePath() != null ? file.getCopyFromAbsoluteFilePath() : file.getAbsoluteFilePath();
+ return path + "-" + key;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/camel/blob/7b1253db/camel-core/src/main/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategy.java b/camel-core/src/main/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategy.java
index ceabd01..1c92bbd 100644
--- a/camel-core/src/main/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategy.java
+++ b/camel-core/src/main/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategy.java
@@ -73,8 +73,10 @@ public class MarkerFileExclusiveReadLockStrategy implements GenericFileExclusive
// create a plain file as marker filer for locking (do not use FileLock)
boolean acquired = FileUtil.createNewFile(new File(lockFileName));
- exchange.setProperty(Exchange.FILE_LOCK_FILE_ACQUIRED, acquired);
- exchange.setProperty(Exchange.FILE_LOCK_FILE_NAME, lockFileName);
+
+ // store read-lock state
+ exchange.setProperty(asReadLockKey(file, Exchange.FILE_LOCK_FILE_ACQUIRED), acquired);
+ exchange.setProperty(asReadLockKey(file, Exchange.FILE_LOCK_FILE_NAME), lockFileName);
return acquired;
}
@@ -101,9 +103,11 @@ public class MarkerFileExclusiveReadLockStrategy implements GenericFileExclusive
return;
}
+ boolean acquired = exchange.getProperty(asReadLockKey(file, Exchange.FILE_LOCK_FILE_ACQUIRED), false, Boolean.class);
+
// only release the file if camel get the lock before
- if (exchange.getProperty(Exchange.FILE_LOCK_FILE_ACQUIRED, false, Boolean.class)) {
- String lockFileName = exchange.getProperty(Exchange.FILE_LOCK_FILE_NAME, getLockFileName(file), String.class);
+ if (acquired) {
+ String lockFileName = exchange.getProperty(asReadLockKey(file, Exchange.FILE_LOCK_FILE_NAME), String.class);
File lock = new File(lockFileName);
if (lock.exists()) {
@@ -162,4 +166,12 @@ public class MarkerFileExclusiveReadLockStrategy implements GenericFileExclusive
return file.getAbsoluteFilePath() + FileComponent.DEFAULT_LOCK_FILE_POSTFIX;
}
+ private static String asReadLockKey(GenericFile file, String key) {
+ // use the copy from absolute path as that was the original path of the file when the lock was acquired
+ // for example if the file consumer uses preMove then the file is moved and therefore has another name
+ // that would no longer match
+ String path = file.getCopyFromAbsoluteFilePath() != null ? file.getCopyFromAbsoluteFilePath() : file.getAbsoluteFilePath();
+ return path + "-" + key;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/camel/blob/7b1253db/camel-core/src/test/java/org/apache/camel/component/file/MarkerFileExclusiveReadLockStrategyUnlockTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/file/MarkerFileExclusiveReadLockStrategyUnlockTest.java b/camel-core/src/test/java/org/apache/camel/component/file/MarkerFileExclusiveReadLockStrategyUnlockTest.java
new file mode 100644
index 0000000..b12b8b2
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/file/MarkerFileExclusiveReadLockStrategyUnlockTest.java
@@ -0,0 +1,73 @@
+/**
+ * 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 java.io.FileOutputStream;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.NotifyBuilder;
+import org.apache.camel.builder.RouteBuilder;
+
+public class MarkerFileExclusiveReadLockStrategyUnlockTest extends ContextTestSupport {
+
+ @Override
+ protected void setUp() throws Exception {
+ setupDirectory();
+ super.setUp();
+ }
+
+ public void testUnlocking() throws Exception {
+ NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create();
+ writeFiles();
+ boolean done = notify.matches(5, TimeUnit.SECONDS);
+
+ assertTrue("Route should be done processing 1 exchanges", done);
+
+ assertFileNotExists("target/marker-unlock/input-a/file1.dat.camelLock");
+ assertFileNotExists("target/marker-unlock/input-b/file2.dat.camelLock");
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("file:target/marker-unlock/input-a?fileName=file1.dat&readLock=markerFile")
+ .pollEnrich("file:target/marker-unlock/input-b?fileName=file2.dat&readLock=markerFile")
+ .to("mock:result");
+ }
+ };
+ }
+
+ private void setupDirectory() {
+ deleteDirectory("target/marker-unlock/");
+ createDirectory("target/marker-unlock/input-a");
+ createDirectory("target/marker-unlock/input-b");
+ }
+
+ private void writeFiles() throws Exception {
+ FileOutputStream fos1 = new FileOutputStream("target/marker-unlock/input-a/file1.dat");
+ FileOutputStream fos2 = new FileOutputStream("target/marker-unlock/input-b/file2.dat");
+ fos1.write("File-1".getBytes());
+ fos2.write("File-2".getBytes());
+ fos1.flush();
+ fos1.close();
+ fos2.flush();
+ fos2.close();
+ }
+}
[3/4] camel git commit: CAMEL-8954: File componet readlock state
should be per file so its possible to use pollEnrich to poll in a 2nd file
and keep those state separated. Thanks to Andy Fedotov for unit test.
Posted by da...@apache.org.
CAMEL-8954: File componet readlock state should be per file so its possible to use pollEnrich to poll in a 2nd file and keep those state separated. Thanks to Andy Fedotov for unit test.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/0a6dc865
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0a6dc865
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0a6dc865
Branch: refs/heads/camel-2.15.x
Commit: 0a6dc865a6670b791dc46bcaf4a99f38f5b65c88
Parents: 6cb8770
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Jul 16 19:39:55 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Jul 16 22:01:30 2015 +0200
----------------------------------------------------------------------
.../camel/component/file/GenericFile.java | 10 +++
.../FileLockExclusiveReadLockStrategy.java | 21 ++++--
.../MarkerFileExclusiveReadLockStrategy.java | 20 ++++--
...FileExclusiveReadLockStrategyUnlockTest.java | 73 ++++++++++++++++++++
4 files changed, 114 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/0a6dc865/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 343d836..907de21 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
@@ -35,6 +35,7 @@ import org.slf4j.LoggerFactory;
public class GenericFile<T> implements WrappedFile<T> {
private static final Logger LOG = LoggerFactory.getLogger(GenericFile.class);
+ private String copyFromAbsoluteFilePath;
private String endpointPath;
private String fileName;
private String fileNameOnly;
@@ -66,6 +67,7 @@ public class GenericFile<T> implements WrappedFile<T> {
} catch (Exception e) {
throw ObjectHelper.wrapRuntimeCamelException(e);
}
+ result.setCopyFromAbsoluteFilePath(source.getAbsoluteFilePath());
result.setEndpointPath(source.getEndpointPath());
result.setAbsolute(source.isAbsolute());
result.setDirectory(source.isDirectory());
@@ -365,6 +367,14 @@ public class GenericFile<T> implements WrappedFile<T> {
this.directory = directory;
}
+ public String getCopyFromAbsoluteFilePath() {
+ return copyFromAbsoluteFilePath;
+ }
+
+ public void setCopyFromAbsoluteFilePath(String copyFromAbsoluteFilePath) {
+ this.copyFromAbsoluteFilePath = copyFromAbsoluteFilePath;
+ }
+
/**
* Fixes the path separator to be according to the protocol
*/
http://git-wip-us.apache.org/repos/asf/camel/blob/0a6dc865/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java b/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java
index ae5b0ff..7b5f1ce 100644
--- a/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java
+++ b/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java
@@ -127,10 +127,11 @@ public class FileLockExclusiveReadLockStrategy extends MarkerFileExclusiveReadLo
}
}
- // we grabbed the lock
- exchange.setProperty(Exchange.FILE_LOCK_EXCLUSIVE_LOCK, lock);
- exchange.setProperty(Exchange.FILE_LOCK_RANDOM_ACCESS_FILE, randomAccessFile);
+ // store read-lock state
+ exchange.setProperty(asReadLockKey(file, Exchange.FILE_LOCK_EXCLUSIVE_LOCK), lock);
+ exchange.setProperty(asReadLockKey(file, Exchange.FILE_LOCK_RANDOM_ACCESS_FILE), randomAccessFile);
+ // we grabbed the lock
return true;
}
@@ -141,10 +142,10 @@ public class FileLockExclusiveReadLockStrategy extends MarkerFileExclusiveReadLo
// must call super
super.releaseExclusiveReadLock(operations, file, exchange);
- String target = file.getFileName();
- FileLock lock = exchange.getProperty(Exchange.FILE_LOCK_EXCLUSIVE_LOCK, FileLock.class);
- RandomAccessFile rac = exchange.getProperty(Exchange.FILE_LOCK_RANDOM_ACCESS_FILE, RandomAccessFile.class);
+ FileLock lock = exchange.getProperty(asReadLockKey(file, Exchange.FILE_LOCK_EXCLUSIVE_LOCK), FileLock.class);
+ RandomAccessFile rac = exchange.getProperty(asReadLockKey(file, Exchange.FILE_LOCK_EXCLUSIVE_LOCK), RandomAccessFile.class);
+ String target = file.getFileName();
if (lock != null) {
Channel channel = lock.acquiredBy();
try {
@@ -187,4 +188,12 @@ public class FileLockExclusiveReadLockStrategy extends MarkerFileExclusiveReadLo
this.readLockLoggingLevel = readLockLoggingLevel;
}
+ private static String asReadLockKey(GenericFile file, String key) {
+ // use the copy from absolute path as that was the original path of the file when the lock was acquired
+ // for example if the file consumer uses preMove then the file is moved and therefore has another name
+ // that would no longer match
+ String path = file.getCopyFromAbsoluteFilePath() != null ? file.getCopyFromAbsoluteFilePath() : file.getAbsoluteFilePath();
+ return path + "-" + key;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/camel/blob/0a6dc865/camel-core/src/main/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategy.java b/camel-core/src/main/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategy.java
index 6deebff..b9676f5 100644
--- a/camel-core/src/main/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategy.java
+++ b/camel-core/src/main/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategy.java
@@ -69,8 +69,10 @@ public class MarkerFileExclusiveReadLockStrategy implements GenericFileExclusive
// create a plain file as marker filer for locking (do not use FileLock)
boolean acquired = FileUtil.createNewFile(new File(lockFileName));
- exchange.setProperty(Exchange.FILE_LOCK_FILE_ACQUIRED, acquired);
- exchange.setProperty(Exchange.FILE_LOCK_FILE_NAME, lockFileName);
+
+ // store read-lock state
+ exchange.setProperty(asReadLockKey(file, Exchange.FILE_LOCK_FILE_ACQUIRED), acquired);
+ exchange.setProperty(asReadLockKey(file, Exchange.FILE_LOCK_FILE_NAME), lockFileName);
return acquired;
}
@@ -83,9 +85,11 @@ public class MarkerFileExclusiveReadLockStrategy implements GenericFileExclusive
return;
}
+ boolean acquired = exchange.getProperty(asReadLockKey(file, Exchange.FILE_LOCK_FILE_ACQUIRED), false, Boolean.class);
+
// only release the file if camel get the lock before
- if (exchange.getProperty(Exchange.FILE_LOCK_FILE_ACQUIRED, false, Boolean.class)) {
- String lockFileName = exchange.getProperty(Exchange.FILE_LOCK_FILE_NAME, getLockFileName(file), String.class);
+ if (acquired) {
+ String lockFileName = exchange.getProperty(asReadLockKey(file, Exchange.FILE_LOCK_FILE_NAME), String.class);
File lock = new File(lockFileName);
if (lock.exists()) {
@@ -139,4 +143,12 @@ public class MarkerFileExclusiveReadLockStrategy implements GenericFileExclusive
return file.getAbsoluteFilePath() + FileComponent.DEFAULT_LOCK_FILE_POSTFIX;
}
+ private static String asReadLockKey(GenericFile file, String key) {
+ // use the copy from absolute path as that was the original path of the file when the lock was acquired
+ // for example if the file consumer uses preMove then the file is moved and therefore has another name
+ // that would no longer match
+ String path = file.getCopyFromAbsoluteFilePath() != null ? file.getCopyFromAbsoluteFilePath() : file.getAbsoluteFilePath();
+ return path + "-" + key;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/camel/blob/0a6dc865/camel-core/src/test/java/org/apache/camel/component/file/MarkerFileExclusiveReadLockStrategyUnlockTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/file/MarkerFileExclusiveReadLockStrategyUnlockTest.java b/camel-core/src/test/java/org/apache/camel/component/file/MarkerFileExclusiveReadLockStrategyUnlockTest.java
new file mode 100644
index 0000000..b12b8b2
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/file/MarkerFileExclusiveReadLockStrategyUnlockTest.java
@@ -0,0 +1,73 @@
+/**
+ * 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 java.io.FileOutputStream;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.NotifyBuilder;
+import org.apache.camel.builder.RouteBuilder;
+
+public class MarkerFileExclusiveReadLockStrategyUnlockTest extends ContextTestSupport {
+
+ @Override
+ protected void setUp() throws Exception {
+ setupDirectory();
+ super.setUp();
+ }
+
+ public void testUnlocking() throws Exception {
+ NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create();
+ writeFiles();
+ boolean done = notify.matches(5, TimeUnit.SECONDS);
+
+ assertTrue("Route should be done processing 1 exchanges", done);
+
+ assertFileNotExists("target/marker-unlock/input-a/file1.dat.camelLock");
+ assertFileNotExists("target/marker-unlock/input-b/file2.dat.camelLock");
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("file:target/marker-unlock/input-a?fileName=file1.dat&readLock=markerFile")
+ .pollEnrich("file:target/marker-unlock/input-b?fileName=file2.dat&readLock=markerFile")
+ .to("mock:result");
+ }
+ };
+ }
+
+ private void setupDirectory() {
+ deleteDirectory("target/marker-unlock/");
+ createDirectory("target/marker-unlock/input-a");
+ createDirectory("target/marker-unlock/input-b");
+ }
+
+ private void writeFiles() throws Exception {
+ FileOutputStream fos1 = new FileOutputStream("target/marker-unlock/input-a/file1.dat");
+ FileOutputStream fos2 = new FileOutputStream("target/marker-unlock/input-b/file2.dat");
+ fos1.write("File-1".getBytes());
+ fos2.write("File-2".getBytes());
+ fos1.flush();
+ fos1.close();
+ fos2.flush();
+ fos2.close();
+ }
+}
[2/4] camel git commit: CAMEL-8974: Properties component support
systemPropertiesMode to control whether JVM system properties are in use.
When in Spring bridge mode it uses the spring configured value.
Posted by da...@apache.org.
CAMEL-8974: Properties component support systemPropertiesMode to control whether JVM system properties are in use. When in Spring bridge mode it uses the spring configured value.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/d7b8afc7
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d7b8afc7
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d7b8afc7
Branch: refs/heads/master
Commit: d7b8afc7411a54c58ea6d9e0fb0ee195912e35df
Parents: 7b1253d
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Jul 16 21:16:35 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Jul 16 21:16:35 2015 +0200
----------------------------------------------------------------------
.../properties/DefaultPropertiesParser.java | 29 ++++++--
.../properties/PropertiesComponent.java | 40 +++++++++++
.../properties/PropertiesComponentTest.java | 74 ++++++++++++++++++++
.../properties/myproperties.properties | 1 +
.../camel/spring/CamelContextFactoryBean.java | 2 +
.../BridgePropertyPlaceholderConfigurer.java | 6 +-
6 files changed, 145 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/d7b8afc7/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java b/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java
index 5b83983..127b988 100644
--- a/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java
+++ b/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java
@@ -20,12 +20,12 @@ import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
-import static java.lang.String.format;
-
import org.apache.camel.util.ObjectHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import static java.lang.String.format;
+
/**
* A parser to parse a string which contains property placeholders.
*/
@@ -297,12 +297,29 @@ public class DefaultPropertiesParser implements AugmentedPropertyNameAwareProper
* @return Value of the property or {@code null} if not found
*/
private String doGetPropertyValue(String key) {
- String value = System.getProperty(key);
- if (value != null) {
- log.debug("Found a JVM system property: {} with value: {} to be used.", key, value);
- } else if (properties != null) {
+ String value = null;
+
+ if (propertiesComponent.getSystemPropertiesMode() == PropertiesComponent.SYSTEM_PROPERTIES_MODE_OVERRIDE) {
+ value = System.getProperty(key);
+ if (value != null) {
+ log.debug("Found a JVM system property: {} with value: {} to be used.", key, value);
+ }
+ }
+
+ if (value == null && properties != null) {
value = properties.getProperty(key);
+ if (value != null) {
+ log.debug("Found property: {} with value: {} to be used.", key, value);
+ }
+ }
+
+ if (value == null && propertiesComponent.getSystemPropertiesMode() == PropertiesComponent.SYSTEM_PROPERTIES_MODE_FALLBACK) {
+ value = System.getProperty(key);
+ if (value != null) {
+ log.debug("Found a JVM system property: {} with value: {} to be used.", key, value);
+ }
}
+
return parseProperty(key, value, properties);
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/d7b8afc7/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java b/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
index e9de896..3eee968 100644
--- a/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
+++ b/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
@@ -64,6 +64,24 @@ public class PropertiesComponent extends DefaultComponent {
public static final String SUFFIX_TOKEN = DEFAULT_SUFFIX_TOKEN;
/**
+ * Never check system properties.
+ */
+ public static final int SYSTEM_PROPERTIES_MODE_NEVER = 0;
+
+ /**
+ * Check system properties if not resolvable in the specified properties.
+ */
+ public static final int SYSTEM_PROPERTIES_MODE_FALLBACK = 1;
+
+ /**
+ * Check system properties first, before trying the specified properties.
+ * This allows system properties to override any other property source.
+ * <p/>
+ * This is the default.
+ */
+ public static final int SYSTEM_PROPERTIES_MODE_OVERRIDE = 2;
+
+ /**
* Key for stores special override properties that containers such as OSGi can store
* in the OSGi service registry
*/
@@ -87,6 +105,7 @@ public class PropertiesComponent extends DefaultComponent {
private String suffixToken = DEFAULT_SUFFIX_TOKEN;
private Properties initialProperties;
private Properties overrideProperties;
+ private int systemPropertiesMode = SYSTEM_PROPERTIES_MODE_OVERRIDE;
public PropertiesComponent() {
// include out of the box functions
@@ -368,10 +387,31 @@ public class PropertiesComponent extends DefaultComponent {
return functions.containsKey(name);
}
+ public int getSystemPropertiesMode() {
+ return systemPropertiesMode;
+ }
+
+ /**
+ * Sets the system property mode.
+ *
+ * @see #SYSTEM_PROPERTIES_MODE_NEVER
+ * @see #SYSTEM_PROPERTIES_MODE_FALLBACK
+ * @see #SYSTEM_PROPERTIES_MODE_OVERRIDE
+ */
+ public void setSystemPropertiesMode(int systemPropertiesMode) {
+ this.systemPropertiesMode = systemPropertiesMode;
+ }
+
@Override
protected void doStart() throws Exception {
super.doStart();
+ if (systemPropertiesMode != SYSTEM_PROPERTIES_MODE_NEVER
+ && systemPropertiesMode != SYSTEM_PROPERTIES_MODE_FALLBACK
+ && systemPropertiesMode != SYSTEM_PROPERTIES_MODE_OVERRIDE) {
+ throw new IllegalArgumentException("Option systemPropertiesMode has invalid value: " + systemPropertiesMode);
+ }
+
// inject the component to the parser
if (propertiesParser instanceof DefaultPropertiesParser) {
((DefaultPropertiesParser) propertiesParser).setPropertiesComponent(this);
http://git-wip-us.apache.org/repos/asf/camel/blob/d7b8afc7/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentTest.java b/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentTest.java
index b8a6a3b..94bf5bb 100644
--- a/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentTest.java
@@ -311,6 +311,8 @@ public class PropertiesComponentTest extends ContextTestSupport {
template.sendBody("direct:foo", "Hello Foo");
assertMockEndpointsSatisfied();
+
+ System.clearProperty("myPrefix");
}
public void testPropertiesComponentPropertyPrefixFallbackDefault() throws Exception {
@@ -498,6 +500,78 @@ public class PropertiesComponentTest extends ContextTestSupport {
assertEquals("\"mock", context.resolvePropertyPlaceholders("\"{{cool.mock}}"));
}
+ public void testPropertiesComponentOverride() throws Exception {
+ System.setProperty("cool.result", "bar");
+ PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class);
+ pc.setSystemPropertiesMode(PropertiesComponent.SYSTEM_PROPERTIES_MODE_OVERRIDE);
+
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:foo").to("mock:{{cool.result}}");
+ }
+ });
+ context.start();
+
+ getMockEndpoint("mock:result").expectedMessageCount(0);
+ getMockEndpoint("mock:bar").expectedMessageCount(1);
+
+ template.sendBody("direct:foo", "Hello Foo");
+
+ assertMockEndpointsSatisfied();
+
+ System.clearProperty("cool.result");
+ }
+
+ public void testPropertiesComponentFallback() throws Exception {
+ System.setProperty("cool.result", "bar");
+ System.setProperty("beer", "Carlsberg");
+ PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class);
+ pc.setSystemPropertiesMode(PropertiesComponent.SYSTEM_PROPERTIES_MODE_FALLBACK);
+
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:foo").to("mock:{{beer}}").to("mock:{{cool.result}}");
+ }
+ });
+ context.start();
+
+ getMockEndpoint("mock:result").expectedMessageCount(1);
+ getMockEndpoint("mock:bar").expectedMessageCount(0);
+ getMockEndpoint("mock:Carlsberg").expectedMessageCount(1);
+
+ template.sendBody("direct:foo", "Hello Foo");
+
+ assertMockEndpointsSatisfied();
+
+ System.clearProperty("cool.result");
+ System.clearProperty("beer");
+ }
+
+ public void testPropertiesComponentNever() throws Exception {
+ System.setProperty("cool.result", "bar");
+ System.setProperty("beer", "Carlsberg");
+ PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class);
+ pc.setSystemPropertiesMode(PropertiesComponent.SYSTEM_PROPERTIES_MODE_NEVER);
+
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:foo").to("mock:{{beer}}").to("mock:{{cool.result}}");
+ }
+ });
+ try {
+ context.start();
+ fail("Should have thrown exception");
+ } catch (FailedToCreateRouteException e) {
+ assertEquals("Property with key [beer] not found in properties from text: mock:{{beer}}", e.getCause().getMessage());
+ }
+
+ System.clearProperty("cool.result");
+ System.clearProperty("beer");
+ }
+
@Override
protected CamelContext createCamelContext() throws Exception {
CamelContext context = super.createCamelContext();
http://git-wip-us.apache.org/repos/asf/camel/blob/d7b8afc7/camel-core/src/test/resources/org/apache/camel/component/properties/myproperties.properties
----------------------------------------------------------------------
diff --git a/camel-core/src/test/resources/org/apache/camel/component/properties/myproperties.properties b/camel-core/src/test/resources/org/apache/camel/component/properties/myproperties.properties
index a89d393..64e6552 100644
--- a/camel-core/src/test/resources/org/apache/camel/component/properties/myproperties.properties
+++ b/camel-core/src/test/resources/org/apache/camel/component/properties/myproperties.properties
@@ -38,3 +38,4 @@ slipDelimiter=##
stop=true
+
http://git-wip-us.apache.org/repos/asf/camel/blob/d7b8afc7/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java b/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
index 1725227..9703f70 100644
--- a/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
+++ b/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
@@ -288,6 +288,8 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Spr
pc = new PropertiesComponent();
getContext().addComponent("properties", pc);
}
+ // use the spring system properties mode which has a different value than Camel may have
+ pc.setSystemPropertiesMode(configurer.getSystemPropertiesMode());
// replace existing resolver with us
configurer.setResolver(pc.getPropertiesResolver());
configurer.setParser(pc.getPropertiesParser());
http://git-wip-us.apache.org/repos/asf/camel/blob/d7b8afc7/components/camel-spring/src/main/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurer.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurer.java b/components/camel-spring/src/main/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurer.java
index c30ea65..260cbb2 100644
--- a/components/camel-spring/src/main/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurer.java
+++ b/components/camel-spring/src/main/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurer.java
@@ -51,6 +51,10 @@ public class BridgePropertyPlaceholderConfigurer extends PropertyPlaceholderConf
private int systemPropertiesMode = SYSTEM_PROPERTIES_MODE_FALLBACK;
private Boolean ignoreResourceNotFound;
+ public int getSystemPropertiesMode() {
+ return systemPropertiesMode;
+ }
+
@Override
protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props) throws BeansException {
super.processProperties(beanFactoryToProcess, props);
@@ -226,7 +230,7 @@ public class BridgePropertyPlaceholderConfigurer extends PropertyPlaceholderConf
public String resolvePlaceholder(String placeholderName) {
String propVal = null;
- if (systemPropertiesMode == SYSTEM_PROPERTIES_MODE_OVERRIDE) {
+ if (systemPropertiesMode == SYSTEM_PROPERTIES_MODE_OVERRIDE) {
propVal = resolveSystemProperty(placeholderName);
}
if (propVal == null) {
[4/4] camel git commit: CAMEL-8974: Properties component support
systemPropertiesMode to control whether JVM system properties are in use.
When in Spring bridge mode it uses the spring configured value.
Posted by da...@apache.org.
CAMEL-8974: Properties component support systemPropertiesMode to control whether JVM system properties are in use. When in Spring bridge mode it uses the spring configured value.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/9f26e12a
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/9f26e12a
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/9f26e12a
Branch: refs/heads/camel-2.15.x
Commit: 9f26e12a6b6518460fad3333839e5851e0f9455f
Parents: 0a6dc86
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Jul 16 21:16:35 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Jul 16 22:01:40 2015 +0200
----------------------------------------------------------------------
.../properties/DefaultPropertiesParser.java | 29 ++++++--
.../properties/PropertiesComponent.java | 40 +++++++++++
.../properties/PropertiesComponentTest.java | 74 ++++++++++++++++++++
.../properties/myproperties.properties | 1 +
.../camel/spring/CamelContextFactoryBean.java | 2 +
.../BridgePropertyPlaceholderConfigurer.java | 6 +-
6 files changed, 145 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/9f26e12a/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java b/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java
index 5b83983..127b988 100644
--- a/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java
+++ b/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java
@@ -20,12 +20,12 @@ import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
-import static java.lang.String.format;
-
import org.apache.camel.util.ObjectHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import static java.lang.String.format;
+
/**
* A parser to parse a string which contains property placeholders.
*/
@@ -297,12 +297,29 @@ public class DefaultPropertiesParser implements AugmentedPropertyNameAwareProper
* @return Value of the property or {@code null} if not found
*/
private String doGetPropertyValue(String key) {
- String value = System.getProperty(key);
- if (value != null) {
- log.debug("Found a JVM system property: {} with value: {} to be used.", key, value);
- } else if (properties != null) {
+ String value = null;
+
+ if (propertiesComponent.getSystemPropertiesMode() == PropertiesComponent.SYSTEM_PROPERTIES_MODE_OVERRIDE) {
+ value = System.getProperty(key);
+ if (value != null) {
+ log.debug("Found a JVM system property: {} with value: {} to be used.", key, value);
+ }
+ }
+
+ if (value == null && properties != null) {
value = properties.getProperty(key);
+ if (value != null) {
+ log.debug("Found property: {} with value: {} to be used.", key, value);
+ }
+ }
+
+ if (value == null && propertiesComponent.getSystemPropertiesMode() == PropertiesComponent.SYSTEM_PROPERTIES_MODE_FALLBACK) {
+ value = System.getProperty(key);
+ if (value != null) {
+ log.debug("Found a JVM system property: {} with value: {} to be used.", key, value);
+ }
}
+
return parseProperty(key, value, properties);
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/9f26e12a/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java b/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
index e9de896..3eee968 100644
--- a/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
+++ b/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
@@ -64,6 +64,24 @@ public class PropertiesComponent extends DefaultComponent {
public static final String SUFFIX_TOKEN = DEFAULT_SUFFIX_TOKEN;
/**
+ * Never check system properties.
+ */
+ public static final int SYSTEM_PROPERTIES_MODE_NEVER = 0;
+
+ /**
+ * Check system properties if not resolvable in the specified properties.
+ */
+ public static final int SYSTEM_PROPERTIES_MODE_FALLBACK = 1;
+
+ /**
+ * Check system properties first, before trying the specified properties.
+ * This allows system properties to override any other property source.
+ * <p/>
+ * This is the default.
+ */
+ public static final int SYSTEM_PROPERTIES_MODE_OVERRIDE = 2;
+
+ /**
* Key for stores special override properties that containers such as OSGi can store
* in the OSGi service registry
*/
@@ -87,6 +105,7 @@ public class PropertiesComponent extends DefaultComponent {
private String suffixToken = DEFAULT_SUFFIX_TOKEN;
private Properties initialProperties;
private Properties overrideProperties;
+ private int systemPropertiesMode = SYSTEM_PROPERTIES_MODE_OVERRIDE;
public PropertiesComponent() {
// include out of the box functions
@@ -368,10 +387,31 @@ public class PropertiesComponent extends DefaultComponent {
return functions.containsKey(name);
}
+ public int getSystemPropertiesMode() {
+ return systemPropertiesMode;
+ }
+
+ /**
+ * Sets the system property mode.
+ *
+ * @see #SYSTEM_PROPERTIES_MODE_NEVER
+ * @see #SYSTEM_PROPERTIES_MODE_FALLBACK
+ * @see #SYSTEM_PROPERTIES_MODE_OVERRIDE
+ */
+ public void setSystemPropertiesMode(int systemPropertiesMode) {
+ this.systemPropertiesMode = systemPropertiesMode;
+ }
+
@Override
protected void doStart() throws Exception {
super.doStart();
+ if (systemPropertiesMode != SYSTEM_PROPERTIES_MODE_NEVER
+ && systemPropertiesMode != SYSTEM_PROPERTIES_MODE_FALLBACK
+ && systemPropertiesMode != SYSTEM_PROPERTIES_MODE_OVERRIDE) {
+ throw new IllegalArgumentException("Option systemPropertiesMode has invalid value: " + systemPropertiesMode);
+ }
+
// inject the component to the parser
if (propertiesParser instanceof DefaultPropertiesParser) {
((DefaultPropertiesParser) propertiesParser).setPropertiesComponent(this);
http://git-wip-us.apache.org/repos/asf/camel/blob/9f26e12a/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentTest.java b/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentTest.java
index b8a6a3b..94bf5bb 100644
--- a/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentTest.java
@@ -311,6 +311,8 @@ public class PropertiesComponentTest extends ContextTestSupport {
template.sendBody("direct:foo", "Hello Foo");
assertMockEndpointsSatisfied();
+
+ System.clearProperty("myPrefix");
}
public void testPropertiesComponentPropertyPrefixFallbackDefault() throws Exception {
@@ -498,6 +500,78 @@ public class PropertiesComponentTest extends ContextTestSupport {
assertEquals("\"mock", context.resolvePropertyPlaceholders("\"{{cool.mock}}"));
}
+ public void testPropertiesComponentOverride() throws Exception {
+ System.setProperty("cool.result", "bar");
+ PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class);
+ pc.setSystemPropertiesMode(PropertiesComponent.SYSTEM_PROPERTIES_MODE_OVERRIDE);
+
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:foo").to("mock:{{cool.result}}");
+ }
+ });
+ context.start();
+
+ getMockEndpoint("mock:result").expectedMessageCount(0);
+ getMockEndpoint("mock:bar").expectedMessageCount(1);
+
+ template.sendBody("direct:foo", "Hello Foo");
+
+ assertMockEndpointsSatisfied();
+
+ System.clearProperty("cool.result");
+ }
+
+ public void testPropertiesComponentFallback() throws Exception {
+ System.setProperty("cool.result", "bar");
+ System.setProperty("beer", "Carlsberg");
+ PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class);
+ pc.setSystemPropertiesMode(PropertiesComponent.SYSTEM_PROPERTIES_MODE_FALLBACK);
+
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:foo").to("mock:{{beer}}").to("mock:{{cool.result}}");
+ }
+ });
+ context.start();
+
+ getMockEndpoint("mock:result").expectedMessageCount(1);
+ getMockEndpoint("mock:bar").expectedMessageCount(0);
+ getMockEndpoint("mock:Carlsberg").expectedMessageCount(1);
+
+ template.sendBody("direct:foo", "Hello Foo");
+
+ assertMockEndpointsSatisfied();
+
+ System.clearProperty("cool.result");
+ System.clearProperty("beer");
+ }
+
+ public void testPropertiesComponentNever() throws Exception {
+ System.setProperty("cool.result", "bar");
+ System.setProperty("beer", "Carlsberg");
+ PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class);
+ pc.setSystemPropertiesMode(PropertiesComponent.SYSTEM_PROPERTIES_MODE_NEVER);
+
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:foo").to("mock:{{beer}}").to("mock:{{cool.result}}");
+ }
+ });
+ try {
+ context.start();
+ fail("Should have thrown exception");
+ } catch (FailedToCreateRouteException e) {
+ assertEquals("Property with key [beer] not found in properties from text: mock:{{beer}}", e.getCause().getMessage());
+ }
+
+ System.clearProperty("cool.result");
+ System.clearProperty("beer");
+ }
+
@Override
protected CamelContext createCamelContext() throws Exception {
CamelContext context = super.createCamelContext();
http://git-wip-us.apache.org/repos/asf/camel/blob/9f26e12a/camel-core/src/test/resources/org/apache/camel/component/properties/myproperties.properties
----------------------------------------------------------------------
diff --git a/camel-core/src/test/resources/org/apache/camel/component/properties/myproperties.properties b/camel-core/src/test/resources/org/apache/camel/component/properties/myproperties.properties
index a89d393..64e6552 100644
--- a/camel-core/src/test/resources/org/apache/camel/component/properties/myproperties.properties
+++ b/camel-core/src/test/resources/org/apache/camel/component/properties/myproperties.properties
@@ -38,3 +38,4 @@ slipDelimiter=##
stop=true
+
http://git-wip-us.apache.org/repos/asf/camel/blob/9f26e12a/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java b/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
index 1c02e5f..9747b6b 100644
--- a/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
+++ b/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
@@ -288,6 +288,8 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Spr
pc = new PropertiesComponent();
getContext().addComponent("properties", pc);
}
+ // use the spring system properties mode which has a different value than Camel may have
+ pc.setSystemPropertiesMode(configurer.getSystemPropertiesMode());
// replace existing resolver with us
configurer.setResolver(pc.getPropertiesResolver());
configurer.setParser(pc.getPropertiesParser());
http://git-wip-us.apache.org/repos/asf/camel/blob/9f26e12a/components/camel-spring/src/main/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurer.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurer.java b/components/camel-spring/src/main/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurer.java
index c30ea65..260cbb2 100644
--- a/components/camel-spring/src/main/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurer.java
+++ b/components/camel-spring/src/main/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurer.java
@@ -51,6 +51,10 @@ public class BridgePropertyPlaceholderConfigurer extends PropertyPlaceholderConf
private int systemPropertiesMode = SYSTEM_PROPERTIES_MODE_FALLBACK;
private Boolean ignoreResourceNotFound;
+ public int getSystemPropertiesMode() {
+ return systemPropertiesMode;
+ }
+
@Override
protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props) throws BeansException {
super.processProperties(beanFactoryToProcess, props);
@@ -226,7 +230,7 @@ public class BridgePropertyPlaceholderConfigurer extends PropertyPlaceholderConf
public String resolvePlaceholder(String placeholderName) {
String propVal = null;
- if (systemPropertiesMode == SYSTEM_PROPERTIES_MODE_OVERRIDE) {
+ if (systemPropertiesMode == SYSTEM_PROPERTIES_MODE_OVERRIDE) {
propVal = resolveSystemProperty(placeholderName);
}
if (propVal == null) {