avoid throwing htpp 404 error
This commit is contained in:
@@ -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<Environment> response = restTemplate.exchange(uri + path,
|
||||
HttpMethod.GET, new HttpEntity<Void>((Void) null),
|
||||
Environment.class, args);
|
||||
ResponseEntity<Environment> response = null;
|
||||
|
||||
try {
|
||||
response = restTemplate.exchange(uri + path,
|
||||
HttpMethod.GET, new HttpEntity<Void>((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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
.<Throwable> instanceOf(HttpClientErrorException.class));
|
||||
expected.expectCause(IsNull.nullValue(Throwable.class));
|
||||
expected.expectMessage("fail fast property is set");
|
||||
assertNull(locator.locate(environment));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user