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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 ...@@ -26,6 +26,7 @@ import org.springframework.boot.actuate.env.EnvironmentEndpoint.EnvironmentEntry
* {@link EndpointWebExtension @EndpointWebExtension} for the {@link EnvironmentEndpoint}. * {@link EndpointWebExtension @EndpointWebExtension} for the {@link EnvironmentEndpoint}.
* *
* @author Stephane Nicoll * @author Stephane Nicoll
* @author Scott Frederick
* @since 2.0.0 * @since 2.0.0
*/ */
@EndpointWebExtension(endpoint = EnvironmentEndpoint.class) @EndpointWebExtension(endpoint = EnvironmentEndpoint.class)
...@@ -40,14 +41,8 @@ public class EnvironmentEndpointWebExtension { ...@@ -40,14 +41,8 @@ public class EnvironmentEndpointWebExtension {
@ReadOperation @ReadOperation
public WebEndpointResponse<EnvironmentEntryDescriptor> environmentEntry(@Selector String toMatch) { public WebEndpointResponse<EnvironmentEntryDescriptor> environmentEntry(@Selector String toMatch) {
EnvironmentEntryDescriptor descriptor = this.delegate.environmentEntry(toMatch); EnvironmentEntryDescriptor descriptor = this.delegate.environmentEntry(toMatch);
return new WebEndpointResponse<>(descriptor, getStatus(descriptor)); return (descriptor.getProperty() != null) ? new WebEndpointResponse<>(descriptor, WebEndpointResponse.STATUS_OK)
} : new WebEndpointResponse<>(WebEndpointResponse.STATUS_NOT_FOUND);
private int getStatus(EnvironmentEntryDescriptor descriptor) {
if (descriptor.getProperty() == null) {
return WebEndpointResponse.STATUS_NOT_FOUND;
}
return WebEndpointResponse.STATUS_OK;
} }
} }
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -88,11 +88,8 @@ class EnvironmentEndpointWebIntegrationTests { ...@@ -88,11 +88,8 @@ class EnvironmentEndpointWebIntegrationTests {
} }
@WebEndpointTest @WebEndpointTest
void nestedPathForUnknownKeyShouldReturn404AndBody() { void nestedPathForUnknownKeyShouldReturn404() {
this.client.get().uri("/actuator/env/this.does.not.exist").exchange().expectStatus().isNotFound().expectBody() this.client.get().uri("/actuator/env/this.does.not.exist").exchange().expectStatus().isNotFound();
.jsonPath("property").doesNotExist().jsonPath("propertySources[?(@.name=='test')]").exists()
.jsonPath("propertySources[?(@.name=='systemProperties')]").exists()
.jsonPath("propertySources[?(@.name=='systemEnvironment')]").exists();
} }
@WebEndpointTest @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