This is an automated email from the ASF dual-hosted git repository. liubao pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git
The following commit(s) were added to refs/heads/master by this push: new ad2bb00 [SCB-662]Using cse/servicecomb duplicate key will get list of values ad2bb00 is described below commit ad2bb00be2abe82c5d49b5fecd9f4b976f7e63b3 Author: liubao <bao....@huawei.com> AuthorDate: Wed Jun 13 09:45:57 2018 +0800 [SCB-662]Using cse/servicecomb duplicate key will get list of values --- .../src/main/resources/microservice.yaml | 25 ++++++++++++++++++++++ .../demo/springmvc/client/SpringmvcClient.java | 19 ++++++++++++++++ .../src/main/resources/microservice.yaml | 6 ++++++ .../org/apache/servicecomb/config/ConfigUtil.java | 9 +++++++- 4 files changed, 58 insertions(+), 1 deletion(-) diff --git a/demo/demo-schema/src/main/resources/microservice.yaml b/demo/demo-schema/src/main/resources/microservice.yaml new file mode 100644 index 0000000..92b6959 --- /dev/null +++ b/demo/demo-schema/src/main/resources/microservice.yaml @@ -0,0 +1,25 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- +cse-config-order: -1 + +cse: + test: + duplicate1: older + +servicecomb: + test: + duplicate2: older \ No newline at end of file diff --git a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/SpringmvcClient.java b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/SpringmvcClient.java index 065a676..7b2add9 100644 --- a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/SpringmvcClient.java +++ b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/SpringmvcClient.java @@ -36,6 +36,8 @@ import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.web.client.RestTemplate; +import com.netflix.config.DynamicPropertyFactory; + public class SpringmvcClient { private static RestTemplate templateUrlWithServiceName = new CseRestTemplate(); @@ -53,6 +55,8 @@ public class SpringmvcClient { } public static void run() { + testConfigurationDuplicate(); + templateUrlWithServiceName.setRequestFactory(new UrlWithServiceNameClientHttpRequestFactory()); restTemplate = RestTemplateBuilder.create(); controller = BeanUtils.getBean("controller"); @@ -198,4 +202,19 @@ public class SpringmvcClient { user.setName("world"); TestMgr.check("ha world", controller.saySomething("ha", user)); } + + private static void testConfigurationDuplicate() { + // this configuration will give warning messages: + // Key servicecomb.test.duplicate2 with an ambiguous item cse.test.duplicate2 exists, please use the same prefix or will get unexpected merged value. + // Key servicecomb.test.duplicate1 with an ambiguous item cse.test.duplicate1 exists, please use the same prefix or will get unexpected merged value. + // and the expected value is not quite determined. But will not get wrong value like 'older,newer' or 'newer,older' + TestMgr.check(DynamicPropertyFactory.getInstance().getStringProperty("cse.test.duplicate2", "wrong").get(), + "newer"); + TestMgr.check(DynamicPropertyFactory.getInstance().getStringProperty("servicecomb.test.duplicate2", "wrong").get(), + "older"); + TestMgr.check(DynamicPropertyFactory.getInstance().getStringProperty("cse.test.duplicate1", "wrong").get(), + "older"); + TestMgr.check(DynamicPropertyFactory.getInstance().getStringProperty("servicecomb.test.duplicate1", "wrong").get(), + "newer"); + } } diff --git a/demo/demo-springmvc/springmvc-client/src/main/resources/microservice.yaml b/demo/demo-springmvc/springmvc-client/src/main/resources/microservice.yaml index 541a8c7..8dc4824 100644 --- a/demo/demo-springmvc/springmvc-client/src/main/resources/microservice.yaml +++ b/demo/demo-springmvc/springmvc-client/src/main/resources/microservice.yaml @@ -80,6 +80,12 @@ servicecomb: region: my-Region availableZone: my-Zone + test: + duplicate1: newer + +cse: + test: + duplicate2: newer #########SSL options ssl.protocols: TLSv1.2 ssl.authPeer: true diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigUtil.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigUtil.java index f8b5271..8f8922d 100644 --- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigUtil.java +++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigUtil.java @@ -171,7 +171,14 @@ public final class ConfigUtil { } String cseKey = CONFIG_CSE_PREFIX + key.substring(key.indexOf(".") + 1); - source.addProperty(cseKey, source.getProperty(key)); + if (!source.containsKey(cseKey)) { + source.addProperty(cseKey, source.getProperty(key)); + } else { + LOGGER + .warn( + "Key {} with an ambiguous item {} exists, please use the same prefix or will get unexpected merged value.", + key, cseKey); + } } }