From 72824ba5d580dbd50e7cf47259a8f714426cc629 Mon Sep 17 00:00:00 2001 From: Spencer Gibb Date: Tue, 17 Dec 2019 17:21:25 -0500 Subject: [PATCH 1/2] Makes locateCollection() retryable --- .../config/client/ConfigServicePropertySourceLocator.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spring-cloud-config-client/src/main/java/org/springframework/cloud/config/client/ConfigServicePropertySourceLocator.java b/spring-cloud-config-client/src/main/java/org/springframework/cloud/config/client/ConfigServicePropertySourceLocator.java index be4cb5c8..ea63281e 100644 --- a/spring-cloud-config-client/src/main/java/org/springframework/cloud/config/client/ConfigServicePropertySourceLocator.java +++ b/spring-cloud-config-client/src/main/java/org/springframework/cloud/config/client/ConfigServicePropertySourceLocator.java @@ -18,6 +18,7 @@ package org.springframework.cloud.config.client; import java.io.IOException; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -146,6 +147,13 @@ public class ConfigServicePropertySourceLocator implements PropertySourceLocator } + @Override + @Retryable(interceptor = "configServerRetryInterceptor") + public Collection> locateCollection( + org.springframework.core.env.Environment environment) { + return PropertySourceLocator.locateCollection(this, environment); + } + private void log(Environment result) { if (logger.isInfoEnabled()) { logger.info(String.format( From 9d67aa0e452fb6c4b8826419d2c7b03d5f35283c Mon Sep 17 00:00:00 2001 From: Ryan Baxter Date: Fri, 10 Jan 2020 13:31:51 -0500 Subject: [PATCH 2/2] Use a more robust filter when dealing with multiple keys (#1534) * Use a more robust filter when dealing with multiple keys. Fixes #1533 * Simplifying tests * Creating a variable for the Pattern to avoid creating it everytime --- ...pClientConfigurableHttpConnectionFactory.java | 16 +++++++++------- ...entConfigurableHttpConnectionFactoryTest.java | 9 ++++++--- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/HttpClientConfigurableHttpConnectionFactory.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/HttpClientConfigurableHttpConnectionFactory.java index 8196565c..13687499 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/HttpClientConfigurableHttpConnectionFactory.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/HttpClientConfigurableHttpConnectionFactory.java @@ -47,7 +47,10 @@ import static java.util.stream.Collectors.toMap; public class HttpClientConfigurableHttpConnectionFactory implements ConfigurableHttpConnectionFactory { - private static final String PLACEHOLDER_PATTERN = "\\{(\\w+)}"; + private static final String PLACEHOLDER_PATTERN_STRING = "\\{(\\w+)}"; + + private static final Pattern PLACEHOLDER_PATTERN = Pattern + .compile(PLACEHOLDER_PATTERN_STRING); Log log = LogFactory.getLog(getClass()); @@ -111,10 +114,9 @@ public class HttpClientConfigurableHttpConnectionFactory * which have no placeholders. That is the one we want to use in the case * there are multiple matches. */ - List keys = builderMap.keySet().stream().filter(key -> { - String[] tokens = key.split(PLACEHOLDER_PATTERN); - return tokens.length == 1; - }).collect(Collectors.toList()); + List keys = builderMap.keySet().stream() + .filter(key -> !PLACEHOLDER_PATTERN.matcher(key).find()) + .collect(Collectors.toList()); if (keys.size() == 1) { return builderMap.get(keys.get(0)); @@ -130,7 +132,7 @@ public class HttpClientConfigurableHttpConnectionFactory private String getUrlWithPlaceholders(URL url, String key) { String spec = url.toString(); - String[] tokens = key.split(PLACEHOLDER_PATTERN); + String[] tokens = key.split(PLACEHOLDER_PATTERN_STRING); // if token[0] equals url then there was no placeholder in the the url, so // matching needed if (tokens.length >= 1 && !tokens[0].equals(url.toString())) { @@ -164,7 +166,7 @@ public class HttpClientConfigurableHttpConnectionFactory } private List getPlaceholders(String key) { - Pattern pattern = Pattern.compile(PLACEHOLDER_PATTERN); + Pattern pattern = Pattern.compile(PLACEHOLDER_PATTERN_STRING); Matcher matcher = pattern.matcher(key); List placeholders = new LinkedList<>(); while (matcher.find()) { diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/HttpClientConfigurableHttpConnectionFactoryTest.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/HttpClientConfigurableHttpConnectionFactoryTest.java index 71bfa827..961bd514 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/HttpClientConfigurableHttpConnectionFactoryTest.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/HttpClientConfigurableHttpConnectionFactoryTest.java @@ -162,14 +162,17 @@ public class HttpClientConfigurableHttpConnectionFactoryTest { @Test public void multipleMatchesWithPlaceholder() throws Exception { MultipleJGitEnvironmentProperties properties1 = new MultipleJGitEnvironmentProperties(); - properties1.setUri("https://github.com/marnee01/mderider-{application}.git"); + properties1.setUri("https://github.com/user/user-{application}.git"); MultipleJGitEnvironmentProperties properties2 = new MultipleJGitEnvironmentProperties(); - properties2.setUri("https://github.com/marnee01/mderider-MultiApps.git"); + properties2.setUri("https://github.com/user/user-MultiApps.git"); + MultipleJGitEnvironmentProperties properties3 = new MultipleJGitEnvironmentProperties(); + properties1.setUri("https://github.com/user/user-{application}"); this.connectionFactory.addConfiguration(properties1); this.connectionFactory.addConfiguration(properties2); + this.connectionFactory.addConfiguration(properties3); HttpConnection actualConnection = this.connectionFactory.create(new URL( - "https://github.com/marnee01/mderider-MultiApps.git/info/refs?service=git-upload-pack")); + "https://github.com/user/user-MultiApps.git/info/refs?service=git-upload-pack")); HttpClientBuilder expectedHttpClientBuilder = this.connectionFactory.httpClientBuildersByUri .get(properties2.getUri()); HttpClientBuilder actualHttpClientBuilder = getActualHttpClientBuilder(