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 2013/11/10 12:48:57 UTC
[2/2] git commit: CAMEL-6916: Properties component/placeholder should
ignore non existing jvm/env variables if ignoreMissingLocation is enabled.
CAMEL-6916: Properties component/placeholder should ignore non existing jvm/env variables if ignoreMissingLocation is enabled.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/37372a8a
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/37372a8a
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/37372a8a
Branch: refs/heads/camel-2.12.x
Commit: 37372a8afdbefeffd930c6450be71a89bd614c7f
Parents: a504a91
Author: Claus Ibsen <da...@apache.org>
Authored: Sun Nov 10 12:49:28 2013 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Nov 10 12:49:42 2013 +0100
----------------------------------------------------------------------
.../properties/DefaultPropertiesResolver.java | 2 +-
.../properties/PropertiesComponent.java | 29 ++++++++++++++------
.../PropertiesComponentDefaultTest.java | 29 ++++++++++++++++++++
3 files changed, 50 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/37372a8a/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesResolver.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesResolver.java b/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesResolver.java
index 8b3a202..dd730d4 100644
--- a/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesResolver.java
+++ b/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesResolver.java
@@ -110,7 +110,7 @@ public class DefaultPropertiesResolver implements PropertiesResolver {
if (path.startsWith("ref:")) {
path = ObjectHelper.after(path, "ref:");
}
- Properties answer = null;
+ Properties answer;
try {
answer = context.getRegistry().lookupByNameAndType(path, Properties.class);
} catch (Exception ex) {
http://git-wip-us.apache.org/repos/asf/camel/blob/37372a8a/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 070b765..fbe652e 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
@@ -17,7 +17,9 @@
package org.apache.camel.component.properties;
import java.io.Serializable;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.regex.Matcher;
@@ -123,7 +125,7 @@ public class PropertiesComponent extends DefaultComponent {
// location may contain JVM system property or OS environment variables
// so we need to parse those
String[] locations = parseLocations(paths);
-
+
// check cache first
CacheKey key = new CacheKey(locations);
prop = cache ? cacheMap.get(key) : null;
@@ -283,19 +285,28 @@ public class PropertiesComponent extends DefaultComponent {
}
private String[] parseLocations(String[] locations) {
- String[] answer = new String[locations.length];
+ List<String> answer = new ArrayList<String>();
- for (int i = 0; i < locations.length; i++) {
- String location = locations[i];
+ for (String location : locations) {
LOG.trace("Parsing location: {} ", location);
- location = FilePathResolver.resolvePath(location);
-
- LOG.debug("Parsed location: {} ", location);
- answer[i] = location;
+ try {
+ location = FilePathResolver.resolvePath(location);
+ LOG.debug("Parsed location: {} ", location);
+ if (ObjectHelper.isNotEmpty(location)) {
+ answer.add(location);
+ }
+ } catch (IllegalArgumentException e) {
+ if (!ignoreMissingLocation) {
+ throw e;
+ } else {
+ LOG.debug("Ignored missing location: {}", location);
+ }
+ }
}
- return answer;
+ // must return a not-null answer
+ return answer.toArray(new String[answer.size()]);
}
/**
http://git-wip-us.apache.org/repos/asf/camel/blob/37372a8a/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentDefaultTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentDefaultTest.java b/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentDefaultTest.java
index b1c2ca0..5cdc53d 100644
--- a/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentDefaultTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentDefaultTest.java
@@ -103,6 +103,35 @@ public class PropertiesComponentDefaultTest extends ContextTestSupport {
assertMockEndpointsSatisfied();
}
+ public void testIgnoreMissingPropertySystemPropertyOnClasspath() throws Exception {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start").to("properties:bar.end?locations=${my.home}/unknown.properties,org/apache/camel/component/properties/bar.properties"
+ + "&ignoreMissingLocation=true");
+ }
+ });
+ context.start();
+ getMockEndpoint("mock:bar").expectedMessageCount(1);
+ template.sendBody("direct:start", "Hello World");
+ assertMockEndpointsSatisfied();
+ }
+
+ public void testNotIgnoreMissingPropertySystemPropertyOnClasspath() throws Exception {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start").to("properties:bar.end?locations=${my.home}/unknown.properties,org/apache/camel/component/properties/bar.properties"
+ + "&ignoreMissingLocation=false");
+ }
+ });
+ try {
+ context.start();
+ fail("Should have thrown exception");
+ } catch (FailedToCreateRouteException e) {
+ assertEquals("Cannot find JVM system property with key: my.home", e.getCause().getCause().getMessage());
+ }
+ }
@Override
public boolean isUseRouteBuilder() {