Commit 185f6448 authored by Scott Frederick's avatar Scott Frederick

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
parent c6687989
/*
* 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);
}
}
/*
* 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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment