From fed8a00ee9dc8a2e339f3002f1c492baf640ccad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Mirc?= Date: Fri, 19 Jun 2015 09:46:44 -0400 Subject: [PATCH 1/2] Consul client returns nodes and leaves. This fix will save only the leaves in the properties map. --- .../cloud/consul/config/ConsulPropertySource.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulPropertySource.java b/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulPropertySource.java index a7439712..16ad5a3c 100644 --- a/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulPropertySource.java +++ b/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulPropertySource.java @@ -55,9 +55,10 @@ public class ConsulPropertySource extends EnumerablePropertySource if (values != null) { for (GetValue getValue : values) { - String key = getValue.getKey().replace(context, "").replace('/', '.'); - String value = getDecoded(getValue.getValue()); - if (StringUtils.hasText(key)) { + String key = getValue.getKey(); + if (!StringUtils.endsWithIgnoreCase(key, "/")) { + key = key.replace(context, "").replace('/', '.'); + String value = getDecoded(getValue.getValue()); properties.put(key, value); } } From caba0f37dabe379436179439ec8fc90ad48d8b26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Mirc?= Date: Mon, 22 Jun 2015 12:00:39 -0400 Subject: [PATCH 2/2] Reformat code --- .../cloud/consul/config/ConsulPropertySource.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulPropertySource.java b/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulPropertySource.java index 16ad5a3c..b967bc0b 100644 --- a/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulPropertySource.java +++ b/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulPropertySource.java @@ -22,12 +22,11 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import org.springframework.core.env.EnumerablePropertySource; - import com.ecwid.consul.v1.ConsulClient; import com.ecwid.consul.v1.QueryParams; import com.ecwid.consul.v1.Response; import com.ecwid.consul.v1.kv.model.GetValue; +import org.springframework.core.env.EnumerablePropertySource; import org.springframework.util.StringUtils; /** @@ -55,10 +54,10 @@ public class ConsulPropertySource extends EnumerablePropertySource if (values != null) { for (GetValue getValue : values) { - String key = getValue.getKey(); - if (!StringUtils.endsWithIgnoreCase(key, "/")) { - key = key.replace(context, "").replace('/', '.'); - String value = getDecoded(getValue.getValue()); + String key = getValue.getKey(); + if (!StringUtils.endsWithIgnoreCase(key, "/")) { + key = key.replace(context, "").replace('/', '.'); + String value = getDecoded(getValue.getValue()); properties.put(key, value); } }