Repository: camel Updated Branches: refs/heads/camel-2.18.x becd9613d -> 2cf934405 refs/heads/camel-2.19.x ab1a540e4 -> 0bd2b5da3
CAMEL-11523: Bridge properties parser should support default values as well. Thanks to Ronny Aerts for sample project to reproduce this issue. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/0bd2b5da Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0bd2b5da Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0bd2b5da Branch: refs/heads/camel-2.19.x Commit: 0bd2b5da3f28e0f1586df0ee34d7d8d2b93bb987 Parents: ab1a540 Author: Claus Ibsen <davscl...@apache.org> Authored: Wed Sep 6 09:41:26 2017 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Wed Sep 6 09:41:55 2017 +0200 ---------------------------------------------------------------------- .../BridgePropertyPlaceholderConfigurer.java | 26 +++++++++++++++++++- ...BridgePropertyPlaceholderConfigurerTest.java | 10 ++++++-- .../spi/bridgePropertyPlaceholderConfigurer.xml | 9 ++++++- 3 files changed, 41 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/0bd2b5da/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 58939ca..81e3d2d 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 @@ -245,7 +245,7 @@ public class BridgePropertyPlaceholderConfigurer extends PropertyPlaceholderConf } } - private final class BridgePropertiesParser implements PropertiesParser { + private final class BridgePropertiesParser implements PropertiesParser, AugmentedPropertyNameAwarePropertiesParser { private final PropertiesParser delegate; private final PropertiesParser parser; @@ -256,6 +256,30 @@ public class BridgePropertyPlaceholderConfigurer extends PropertyPlaceholderConf } @Override + public String parseUri(String text, Properties properties, String prefixToken, String suffixToken, String propertyPrefix, String propertySuffix, + boolean fallbackToUnaugmentedProperty, boolean defaultFallbackEnabled) throws IllegalArgumentException { + String answer = null; + if (delegate != null) { + if (delegate instanceof AugmentedPropertyNameAwarePropertiesParser) { + answer = ((AugmentedPropertyNameAwarePropertiesParser)this.delegate).parseUri(text, properties, + prefixToken, suffixToken, propertyPrefix, propertySuffix, fallbackToUnaugmentedProperty, defaultFallbackEnabled); + } else { + answer = delegate.parseUri(text, properties, prefixToken, suffixToken); + } + } + if (answer != null) { + text = answer; + } + if (parser instanceof AugmentedPropertyNameAwarePropertiesParser) { + answer = ((AugmentedPropertyNameAwarePropertiesParser)this.parser).parseUri(text, properties, + prefixToken, suffixToken, propertyPrefix, propertySuffix, fallbackToUnaugmentedProperty, defaultFallbackEnabled); + } else { + answer = parser.parseUri(text, properties, prefixToken, suffixToken); + } + return answer; + } + + @Override public String parseUri(String text, Properties properties, String prefixToken, String suffixToken) throws IllegalArgumentException { String answer = null; if (delegate != null) { http://git-wip-us.apache.org/repos/asf/camel/blob/0bd2b5da/components/camel-spring/src/test/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurerTest.java ---------------------------------------------------------------------- diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurerTest.java b/components/camel-spring/src/test/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurerTest.java index f219525..d4bb126 100644 --- a/components/camel-spring/src/test/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurerTest.java +++ b/components/camel-spring/src/test/java/org/apache/camel/spring/spi/BridgePropertyPlaceholderConfigurerTest.java @@ -29,12 +29,18 @@ public class BridgePropertyPlaceholderConfigurerTest extends SpringTestSupport { return new ClassPathXmlApplicationContext("org/apache/camel/spring/spi/bridgePropertyPlaceholderConfigurer.xml"); } - - public void testIgnore() throws Exception { + public void testProperty() throws Exception { MockEndpoint result = context.getEndpoint("mock:result", MockEndpoint.class); result.expectedBodiesReceived(CONSTANT); template.sendBody("direct:start", "Test"); result.assertIsSatisfied(); } + public void testPropertyDefault() throws Exception { + MockEndpoint result = context.getEndpoint("mock:result", MockEndpoint.class); + result.expectedBodiesReceived("myDefaultValue"); + template.sendBody("direct:start2", "Test"); + result.assertIsSatisfied(); + } + } http://git-wip-us.apache.org/repos/asf/camel/blob/0bd2b5da/components/camel-spring/src/test/resources/org/apache/camel/spring/spi/bridgePropertyPlaceholderConfigurer.xml ---------------------------------------------------------------------- diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/spi/bridgePropertyPlaceholderConfigurer.xml b/components/camel-spring/src/test/resources/org/apache/camel/spring/spi/bridgePropertyPlaceholderConfigurer.xml index 99db40f..dba79ea 100644 --- a/components/camel-spring/src/test/resources/org/apache/camel/spring/spi/bridgePropertyPlaceholderConfigurer.xml +++ b/components/camel-spring/src/test/resources/org/apache/camel/spring/spi/bridgePropertyPlaceholderConfigurer.xml @@ -49,6 +49,13 @@ </camel:setBody> <camel:to uri="mock:result" /> </camel:route> - </camel:camelContext> + <camel:route> + <camel:from uri="direct:start2" /> + <camel:setBody> + <camel:simple>{{unknown:myDefaultValue}}</camel:simple> + </camel:setBody> + <camel:to uri="mock:result" /> + </camel:route> + </camel:camelContext> </beans> \ No newline at end of file