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 2019/09/06 16:40:27 UTC
[camel] branch master updated: CAMEL-13935: Fixed properties
component with initial/override properties may store values as non string
types.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new 60ab5c4 CAMEL-13935: Fixed properties component with initial/override properties may store values as non string types.
60ab5c4 is described below
commit 60ab5c43bdfd978356c0a53ba84d3cff51dab744
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Sep 6 18:21:37 2019 +0200
CAMEL-13935: Fixed properties component with initial/override properties may store values as non string types.
---
.../properties/DefaultPropertiesLookup.java | 22 ++++++-
...esComponentOverridePropertiesNonStringTest.java | 68 ++++++++++++++++++++++
2 files changed, 88 insertions(+), 2 deletions(-)
diff --git a/components/camel-properties/src/main/java/org/apache/camel/component/properties/DefaultPropertiesLookup.java b/components/camel-properties/src/main/java/org/apache/camel/component/properties/DefaultPropertiesLookup.java
index 1e4a2b5..30d7680 100644
--- a/components/camel-properties/src/main/java/org/apache/camel/component/properties/DefaultPropertiesLookup.java
+++ b/components/camel-properties/src/main/java/org/apache/camel/component/properties/DefaultPropertiesLookup.java
@@ -18,6 +18,8 @@ package org.apache.camel.component.properties;
import java.util.Iterator;
+import org.apache.camel.NoTypeConversionAvailableException;
+import org.apache.camel.RuntimeCamelException;
import org.apache.camel.spi.PropertiesSource;
/**
@@ -33,11 +35,23 @@ public class DefaultPropertiesLookup implements PropertiesLookup {
@Override
public String lookup(String name) {
+ try {
+ return doLookup(name);
+ } catch (NoTypeConversionAvailableException e) {
+ throw RuntimeCamelException.wrapRuntimeCamelException(e);
+ }
+ }
+
+ private String doLookup(String name) throws NoTypeConversionAvailableException {
String answer = null;
// override takes precedence
if (component.getOverrideProperties() != null) {
- answer = component.getOverrideProperties().getProperty(name);
+ // use get as the value can potentially be stored as a non string value
+ Object value = component.getOverrideProperties().get(name);
+ if (value != null) {
+ answer = component.getCamelContext().getTypeConverter().mandatoryConvertTo(String.class, value);
+ }
}
if (answer == null) {
// try till first found source
@@ -48,7 +62,11 @@ public class DefaultPropertiesLookup implements PropertiesLookup {
}
// initial properties are last
if (answer == null && component.getInitialProperties() != null) {
- answer = component.getInitialProperties().getProperty(name);
+ // use get as the value can potentially be stored as a non string value
+ Object value = component.getInitialProperties().get(name);
+ if (value != null) {
+ answer = component.getCamelContext().getTypeConverter().mandatoryConvertTo(String.class, value);
+ }
}
return answer;
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentOverridePropertiesNonStringTest.java b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentOverridePropertiesNonStringTest.java
new file mode 100644
index 0000000..9537b23
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentOverridePropertiesNonStringTest.java
@@ -0,0 +1,68 @@
+/*
+ * 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.properties;
+
+import java.util.Properties;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+public class PropertiesComponentOverridePropertiesNonStringTest extends ContextTestSupport {
+
+ @Override
+ public boolean isUseRouteBuilder() {
+ return false;
+ }
+
+ @Test
+ public void testPropertiesComponentEndpoint() throws Exception {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start").to("{{hey}}").to("mock:{{cool.result}}");
+ }
+ });
+ context.start();
+
+ getMockEndpoint("mock:123").expectedMessageCount(1);
+ getMockEndpoint("mock:hey").expectedMessageCount(1);
+ getMockEndpoint("mock:result").expectedMessageCount(0);
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext context = super.createCamelContext();
+
+ PropertiesComponent pc = new PropertiesComponent();
+ pc.setLocation("classpath:org/apache/camel/component/properties/myproperties.properties");
+ context.addComponent("properties", pc);
+
+ Properties extra = new Properties();
+ extra.put("cool.result", 123);
+ extra.put("hey", "mock:hey");
+ pc.setOverrideProperties(extra);
+
+ return context;
+ }
+
+}