Remove the body from actuator 404 responses

When a request to the /actuator/env/{toMatch} endpoint does not match a
property, a response status 404 was being returned along with a body
containing the existing property sources. This commit removes the body
from the response to be more consistent with a typical 404 response.

Fixes gh-20314
This commit is contained in:
Scott Frederick 2020-03-05 17:21:15 -06:00
parent c668798923
commit 185f644877
2 changed files with 7 additions and 15 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -26,6 +26,7 @@ import org.springframework.boot.actuate.env.EnvironmentEndpoint.EnvironmentEntry
* {@link EndpointWebExtension @EndpointWebExtension} for the {@link EnvironmentEndpoint}.
*
* @author Stephane Nicoll
* @author Scott Frederick
* @since 2.0.0
*/
@EndpointWebExtension(endpoint = EnvironmentEndpoint.class)
@ -40,14 +41,8 @@ public class EnvironmentEndpointWebExtension {
@ReadOperation
public WebEndpointResponse<EnvironmentEntryDescriptor> environmentEntry(@Selector String toMatch) {
EnvironmentEntryDescriptor descriptor = this.delegate.environmentEntry(toMatch);
return new WebEndpointResponse<>(descriptor, getStatus(descriptor));
}
private int getStatus(EnvironmentEntryDescriptor descriptor) {
if (descriptor.getProperty() == null) {
return WebEndpointResponse.STATUS_NOT_FOUND;
}
return WebEndpointResponse.STATUS_OK;
return (descriptor.getProperty() != null) ? new WebEndpointResponse<>(descriptor, WebEndpointResponse.STATUS_OK)
: new WebEndpointResponse<>(WebEndpointResponse.STATUS_NOT_FOUND);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -88,11 +88,8 @@ class EnvironmentEndpointWebIntegrationTests {
}
@WebEndpointTest
void nestedPathForUnknownKeyShouldReturn404AndBody() {
this.client.get().uri("/actuator/env/this.does.not.exist").exchange().expectStatus().isNotFound().expectBody()
.jsonPath("property").doesNotExist().jsonPath("propertySources[?(@.name=='test')]").exists()
.jsonPath("propertySources[?(@.name=='systemProperties')]").exists()
.jsonPath("propertySources[?(@.name=='systemEnvironment')]").exists();
void nestedPathForUnknownKeyShouldReturn404() {
this.client.get().uri("/actuator/env/this.does.not.exist").exchange().expectStatus().isNotFound();
}
@WebEndpointTest