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:
parent
c668798923
commit
185f644877
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue