Merge pull request #1837 from ryanjbaxter/master
Adding logging when we fail to get the Environment
This commit is contained in:
@@ -28,6 +28,8 @@ import java.util.Map.Entry;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.yaml.snakeyaml.DumperOptions.FlowStyle;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.nodes.Tag;
|
||||
@@ -65,6 +67,8 @@ import static org.springframework.cloud.config.server.support.EnvironmentPropert
|
||||
@RequestMapping(method = RequestMethod.GET, path = "${spring.cloud.config.server.prefix:}")
|
||||
public class EnvironmentController {
|
||||
|
||||
private static final Log LOG = LogFactory.getLog(EnvironmentController.class);
|
||||
|
||||
private EnvironmentRepository repository;
|
||||
|
||||
private ObjectMapper objectMapper;
|
||||
@@ -121,13 +125,20 @@ public class EnvironmentController {
|
||||
}
|
||||
|
||||
public Environment getEnvironment(String name, String profiles, String label, boolean includeOrigin) {
|
||||
name = normalize(name);
|
||||
label = normalize(label);
|
||||
Environment environment = this.repository.findOne(name, profiles, label, includeOrigin);
|
||||
if (!this.acceptEmpty && (environment == null || environment.getPropertySources().isEmpty())) {
|
||||
throw new EnvironmentNotFoundException("Profile Not found");
|
||||
try {
|
||||
name = normalize(name);
|
||||
label = normalize(label);
|
||||
Environment environment = this.repository.findOne(name, profiles, label, includeOrigin);
|
||||
if (!this.acceptEmpty && (environment == null || environment.getPropertySources().isEmpty())) {
|
||||
throw new EnvironmentNotFoundException("Profile Not found");
|
||||
}
|
||||
return environment;
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOG.warn(String.format("Error getting the Environment with name=%s profiles=%s label=%s includeOrigin=%b",
|
||||
name, profiles, label, includeOrigin), e);
|
||||
throw e;
|
||||
}
|
||||
return environment;
|
||||
}
|
||||
|
||||
private String normalize(String part) {
|
||||
|
||||
@@ -89,4 +89,12 @@ public class VanillaConfigServerIntegrationTests {
|
||||
assertThat(response.getBody().length).isEqualTo(expected.length());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidYaml() {
|
||||
ResponseEntity<Environment> response = new TestRestTemplate().exchange(
|
||||
"http://localhost:" + this.port + "/invalid/default", HttpMethod.GET, getV2AcceptEntity(),
|
||||
Environment.class);
|
||||
assertThat(response.getStatusCodeValue()).isEqualTo(500);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
spring:
|
||||
flyway:
|
||||
url: jdbc:mariadb://${db.host}/${db.name}
|
||||
Reference in New Issue
Block a user