Merge pull request #1837 from ryanjbaxter/master

Adding logging when we fail to get the Environment
This commit is contained in:
Ryan Baxter
2021-03-16 14:10:16 -04:00
committed by GitHub
3 changed files with 28 additions and 6 deletions

View File

@@ -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) {

View File

@@ -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);
}
}

View File

@@ -0,0 +1,3 @@
spring:
flyway:
url: jdbc:mariadb://${db.host}/${db.name}