Support mixed case endpoint IDs with time-to-live

Update the endpoint time-to-live binding logic so that mixed case
endpoint IDs are supported. Prior to this commit an
`InvalidConfigurationPropertyNameException` would be thrown when using
a camel case endpoint ID.

See gh-14773
This commit is contained in:
Phillip Webb
2018-10-13 21:01:27 -07:00
parent 3105a38884
commit 138d85477d
8 changed files with 37 additions and 21 deletions

View File

@@ -18,6 +18,7 @@ package org.springframework.boot.actuate.endpoint.invoker.cache;
import java.util.function.Function;
import org.springframework.boot.actuate.endpoint.EndpointId;
import org.springframework.boot.actuate.endpoint.OperationType;
import org.springframework.boot.actuate.endpoint.SecurityContext;
import org.springframework.boot.actuate.endpoint.invoke.OperationInvoker;
@@ -33,9 +34,10 @@ import org.springframework.boot.actuate.endpoint.invoke.OperationParameters;
*/
public class CachingOperationInvokerAdvisor implements OperationInvokerAdvisor {
private final Function<String, Long> endpointIdTimeToLive;
private final Function<EndpointId, Long> endpointIdTimeToLive;
public CachingOperationInvokerAdvisor(Function<String, Long> endpointIdTimeToLive) {
public CachingOperationInvokerAdvisor(
Function<EndpointId, Long> endpointIdTimeToLive) {
this.endpointIdTimeToLive = endpointIdTimeToLive;
}
@@ -43,6 +45,12 @@ public class CachingOperationInvokerAdvisor implements OperationInvokerAdvisor {
@Deprecated
public OperationInvoker apply(String endpointId, OperationType operationType,
OperationParameters parameters, OperationInvoker invoker) {
return apply(EndpointId.of(endpointId), operationType, parameters, invoker);
}
@Override
public OperationInvoker apply(EndpointId endpointId, OperationType operationType,
OperationParameters parameters, OperationInvoker invoker) {
if (operationType == OperationType.READ && !hasMandatoryParameter(parameters)) {
Long timeToLive = this.endpointIdTimeToLive.apply(endpointId);
if (timeToLive != null && timeToLive > 0) {

View File

@@ -500,12 +500,12 @@ public class EndpointDiscovererTests {
}
TestEndpointDiscoverer(ApplicationContext applicationContext,
Function<String, Long> timeToLive) {
Function<EndpointId, Long> timeToLive) {
this(applicationContext, timeToLive, Collections.emptyList());
}
TestEndpointDiscoverer(ApplicationContext applicationContext,
Function<String, Long> timeToLive,
Function<EndpointId, Long> timeToLive,
Collection<EndpointFilter<TestExposableEndpoint>> filters) {
this(applicationContext, new ConversionServiceParameterValueMapper(),
Collections.singleton(new CachingOperationInvokerAdvisor(timeToLive)),

View File

@@ -51,7 +51,7 @@ public class CachingOperationInvokerAdvisorTests {
private OperationInvoker invoker;
@Mock
private Function<String, Long> timeToLive;
private Function<EndpointId, Long> timeToLive;
private CachingOperationInvokerAdvisor advisor;
@@ -85,7 +85,7 @@ public class CachingOperationInvokerAdvisorTests {
OperationInvoker advised = this.advisor.apply(EndpointId.of("foo"),
OperationType.READ, parameters, this.invoker);
assertThat(advised).isSameAs(this.invoker);
verify(this.timeToLive).apply("foo");
verify(this.timeToLive).apply(EndpointId.of("foo"));
}
@Test
@@ -95,7 +95,7 @@ public class CachingOperationInvokerAdvisorTests {
OperationInvoker advised = this.advisor.apply(EndpointId.of("foo"),
OperationType.READ, parameters, this.invoker);
assertThat(advised).isSameAs(this.invoker);
verify(this.timeToLive).apply("foo");
verify(this.timeToLive).apply(EndpointId.of("foo"));
}
@Test

View File

@@ -306,7 +306,7 @@ public class JmxEndpointDiscovererTests {
load(configuration, (id) -> null, consumer);
}
private void load(Class<?> configuration, Function<String, Long> timeToLive,
private void load(Class<?> configuration, Function<EndpointId, Long> timeToLive,
Consumer<JmxEndpointDiscoverer> consumer) {
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
configuration)) {

View File

@@ -257,8 +257,9 @@ public class WebEndpointDiscovererTests {
this.load((id) -> null, (id) -> id, configuration, consumer);
}
private void load(Function<String, Long> timeToLive, PathMapper endpointPathMapper,
Class<?> configuration, Consumer<WebEndpointDiscoverer> consumer) {
private void load(Function<EndpointId, Long> timeToLive,
PathMapper endpointPathMapper, Class<?> configuration,
Consumer<WebEndpointDiscoverer> consumer) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
configuration);
try {