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 e02c35e CAMEL-13833: Properties component - Fallback to ENV should replace dots with underscores (#3085) e02c35e is described below commit e02c35ee11e67ec7769c083148f5c276b05a7d7d Author: Luca Burgazzoli <lburgazz...@users.noreply.github.com> AuthorDate: Wed Aug 7 20:45:19 2019 +0200 CAMEL-13833: Properties component - Fallback to ENV should replace dots with underscores (#3085) --- .../main/java/org/apache/camel/util/IOHelper.java | 24 ++++++++++------- .../java/org/apache/camel/util/IOHelperTest.java | 30 ++++++++++++++++++++++ 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/core/camel-util/src/main/java/org/apache/camel/util/IOHelper.java b/core/camel-util/src/main/java/org/apache/camel/util/IOHelper.java index 701ee6e..b5e8d2a 100644 --- a/core/camel-util/src/main/java/org/apache/camel/util/IOHelper.java +++ b/core/camel-util/src/main/java/org/apache/camel/util/IOHelper.java @@ -96,7 +96,7 @@ public final class IOHelper { * object and returns that. If the passed <code>in</code> is already an * instance of {@link BufferedInputStream} returns the same passed * <code>in</code> reference as is (avoiding double wrapping). - * + * * @param in the wrapee to be used for the buffering support * @return the passed <code>in</code> decorated through a * {@link BufferedInputStream} object as wrapper @@ -111,7 +111,7 @@ public final class IOHelper { * object and returns that. If the passed <code>out</code> is already an * instance of {@link BufferedOutputStream} returns the same passed * <code>out</code> reference as is (avoiding double wrapping). - * + * * @param out the wrapee to be used for the buffering support * @return the passed <code>out</code> decorated through a * {@link BufferedOutputStream} object as wrapper @@ -126,7 +126,7 @@ public final class IOHelper { * and returns that. If the passed <code>reader</code> is already an * instance of {@link BufferedReader} returns the same passed * <code>reader</code> reference as is (avoiding double wrapping). - * + * * @param reader the wrapee to be used for the buffering support * @return the passed <code>reader</code> decorated through a * {@link BufferedReader} object as wrapper @@ -141,7 +141,7 @@ public final class IOHelper { * and returns that. If the passed <code>writer</code> is already an * instance of {@link BufferedWriter} returns the same passed * <code>writer</code> reference as is (avoiding double wrapping). - * + * * @param writer the wrapee to be used for the buffering support * @return the passed <code>writer</code> decorated through a * {@link BufferedWriter} object as wrapper @@ -430,7 +430,7 @@ public final class IOHelper { /** * Closes the given resources if they are available. - * + * * @param closeables the objects to close */ public static void close(Closeable... closeables) { @@ -491,7 +491,7 @@ public final class IOHelper { /** * Get the charset name from the content type string - * + * * @param contentType * @return the charset name, or <tt>UTF-8</tt> if no found */ @@ -539,10 +539,16 @@ public final class IOHelper { // lookup OS env with upper case key String upperKey = key.toUpperCase(); String value = System.getenv(upperKey); - // some OS do not support dashes in keys, so replace with underscore + if (value == null) { - String noDashKey = upperKey.replace('-', '_'); - value = System.getenv(noDashKey); + // some OS do not support dashes in keys, so replace with underscore + String normalizedKey = upperKey.replace('-', '_'); + + // and replace dots with underscores so keys like my.key are + // translated to MY_KEY + normalizedKey = normalizedKey.replace('.', '_'); + + value = System.getenv(normalizedKey); } return value; } diff --git a/core/camel-util/src/test/java/org/apache/camel/util/IOHelperTest.java b/core/camel-util/src/test/java/org/apache/camel/util/IOHelperTest.java new file mode 100644 index 0000000..3395c1a --- /dev/null +++ b/core/camel-util/src/test/java/org/apache/camel/util/IOHelperTest.java @@ -0,0 +1,30 @@ +/* + * 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.util; + +import org.junit.Assert; +import org.junit.Test; + +public class IOHelperTest extends Assert { + @Test + public void testLookupEnvironmentVariable() throws Exception { + assertEquals("8081", IOHelper.lookupEnvironmentVariable("FOO_SERVICE_PORT")); + assertEquals("8081", IOHelper.lookupEnvironmentVariable("foo-service.port")); + assertEquals("8081", IOHelper.lookupEnvironmentVariable("foo-service-port")); + assertEquals("8081", IOHelper.lookupEnvironmentVariable("foo.service.port")); + } +}