From 54e279ad9335b4b6fd0d59a54262ecc1efb9755d Mon Sep 17 00:00:00 2001 From: Aizhan Date: Tue, 11 Aug 2015 14:04:30 -0600 Subject: [PATCH 1/2] avoid throwing htpp 404 error --- .../ConfigServicePropertySourceLocator.java | 16 +++++++++++++--- .../ConfigServicePropertySourceLocatorTests.java | 4 ++-- 2 files changed, 15 insertions(+), 5 deletions(-) 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 845347c9..8aeec429 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 @@ -39,6 +39,7 @@ import org.springframework.http.client.ClientHttpRequestInterceptor; import org.springframework.http.client.ClientHttpResponse; import org.springframework.retry.annotation.Retryable; import org.springframework.util.StringUtils; +import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.HttpServerErrorException; import org.springframework.web.client.RestTemplate; @@ -117,9 +118,18 @@ public class ConfigServicePropertySourceLocator implements PropertySourceLocator args = new String[] { name, profile, label }; path = path + "/{label}"; } - ResponseEntity response = restTemplate.exchange(uri + path, - HttpMethod.GET, new HttpEntity((Void) null), - Environment.class, args); + ResponseEntity response = null; + + try { + response = restTemplate.exchange(uri + path, + HttpMethod.GET, new HttpEntity((Void) null), + Environment.class, args); + } catch (HttpClientErrorException e) { + if(e.getStatusCode() != HttpStatus.NOT_FOUND ) { + throw e; + } + } + if (response==null || response.getStatusCode()!=HttpStatus.OK) { return null; } diff --git a/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/ConfigServicePropertySourceLocatorTests.java b/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/ConfigServicePropertySourceLocatorTests.java index 920186e9..4d1d8a32 100644 --- a/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/ConfigServicePropertySourceLocatorTests.java +++ b/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/ConfigServicePropertySourceLocatorTests.java @@ -7,6 +7,7 @@ import java.io.ByteArrayInputStream; import java.net.URI; import org.hamcrest.core.IsInstanceOf; +import org.hamcrest.core.IsNull; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -129,8 +130,7 @@ public class ConfigServicePropertySourceLocatorTests { Mockito.when(response.getBody()).thenReturn( new ByteArrayInputStream("".getBytes())); locator.setRestTemplate(restTemplate); - expected.expectCause(IsInstanceOf - . instanceOf(HttpClientErrorException.class)); + expected.expectCause(IsNull.nullValue(Throwable.class)); expected.expectMessage("fail fast property is set"); assertNull(locator.locate(environment)); } From 91b8eab02700de505141053191f795afd93e1275 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Thu, 13 Aug 2015 13:38:52 +0100 Subject: [PATCH 2/2] Clarify some configuration in documentation Some of the examples used to illustrate multi-git configuration are apparently confusing. This change adds some clarification. Fixes gh-213 --- docs/src/main/asciidoc/spring-cloud-config.adoc | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/docs/src/main/asciidoc/spring-cloud-config.adoc b/docs/src/main/asciidoc/spring-cloud-config.adoc index 087dca5f..f14ddee7 100644 --- a/docs/src/main/asciidoc/spring-cloud-config.adoc +++ b/docs/src/main/asciidoc/spring-cloud-config.adoc @@ -106,21 +106,26 @@ spring: git: uri: https://github.com/spring-cloud-samples/config-repo repos: - simple: https://github.com/pattern1/config-repo + simple: https://github.com/simple/config-repo special: pattern: pattern*,*pattern1* - uri: https://github.com/pattern2/config-repo + uri: https://github.com/special/config-repo local: pattern: local* uri: file:/home/configsvc/config-repo ---- -In the above example, if {application} does not match to any of the +In the above example, if `{application}` does not match any of the patterns, it will use the default uri defined under "spring.cloud.config.server.git.uri". For the "simple" repository, the -pattern is "simple" (i.e. it only matches one application). The -pattern format is a comma-separated list of application names with -wildcards. +pattern is "simple" (i.e. it only matches one application named "simple"). +The pattern format is a comma-separated list of application names with +wildcards (a pattern beginning with a wildcard may need to be quoted). + +NOTE: the "one-liner" short cut used in the "simple" example above can +only be used if the only property to be set is the URI. If you need to +set anything else (credentials, pattern, etc.) you need to use the full +form. Every repository can also optionally store config files in sub-directories, and patterns to search for those directories can be