Skip to content

Commit

Permalink
Migrate endpoints to return OperationResponseBody types
Browse files Browse the repository at this point in the history
Update types returned from endpoints to implement the
`OperationResponseBody` interface. This ensures that they will be
serialized using the isolated actuator `ObjectMapper`.

See gh-20291
  • Loading branch information
philwebb committed Nov 10, 2022
1 parent 1f8493f commit 3d2071d
Show file tree
Hide file tree
Showing 25 changed files with 74 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

import org.springframework.boot.actuate.endpoint.OperationResponseBody;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport;
Expand Down Expand Up @@ -81,7 +82,7 @@ private ConfigurableApplicationContext getConfigurableParent(ConfigurableApplica
/**
* A description of an application's condition evaluation.
*/
public static final class ConditionsDescriptor {
public static final class ConditionsDescriptor implements OperationResponseBody {

private final Map<String, ContextConditionsDescriptor> contexts;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.time.OffsetDateTime;
import java.util.List;

import org.springframework.boot.actuate.endpoint.OperationResponseBody;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.lang.Nullable;
Expand Down Expand Up @@ -55,7 +56,7 @@ private Instant getInstant(OffsetDateTime offsetDateTime) {
/**
* Description of an application's {@link AuditEvent audit events}.
*/
public static final class AuditEventsDescriptor {
public static final class AuditEventsDescriptor implements OperationResponseBody {

private final List<AuditEvent> events;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.boot.actuate.endpoint.OperationResponseBody;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.context.ApplicationContext;
Expand Down Expand Up @@ -73,7 +74,7 @@ private static ConfigurableApplicationContext getConfigurableParent(Configurable
/**
* Description of an application's beans.
*/
public static final class BeansDescriptor {
public static final class BeansDescriptor implements OperationResponseBody {

private final Map<String, ContextBeansDescriptor> contexts;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Objects;
import java.util.function.Predicate;

import org.springframework.boot.actuate.endpoint.OperationResponseBody;
import org.springframework.boot.actuate.endpoint.annotation.DeleteOperation;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
Expand Down Expand Up @@ -148,7 +149,7 @@ private Predicate<String> matchAll() {
/**
* Description of the caches.
*/
public static final class CachesDescriptor {
public static final class CachesDescriptor implements OperationResponseBody {

private final Map<String, CacheManagerDescriptor> cacheManagers;

Expand Down Expand Up @@ -182,7 +183,7 @@ public Map<String, CacheDescriptor> getCaches() {
/**
* Description of a {@link Cache}.
*/
public static class CacheDescriptor {
public static class CacheDescriptor implements OperationResponseBody {

private final String target;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.springframework.boot.actuate.context;

import org.springframework.beans.BeansException;
import org.springframework.boot.actuate.endpoint.OperationResponseBody;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.WriteOperation;
import org.springframework.context.ApplicationContext;
Expand Down Expand Up @@ -71,7 +72,7 @@ public void setApplicationContext(ApplicationContext context) throws BeansExcept
/**
* Description of the shutdown.
*/
public static class ShutdownDescriptor {
public static class ShutdownDescriptor implements OperationResponseBody {

private static final ShutdownDescriptor DEFAULT = new ShutdownDescriptor("Shutting down, bye...");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.apache.commons.logging.LogFactory;

import org.springframework.beans.BeansException;
import org.springframework.boot.actuate.endpoint.OperationResponseBody;
import org.springframework.boot.actuate.endpoint.SanitizableData;
import org.springframework.boot.actuate.endpoint.Sanitizer;
import org.springframework.boot.actuate.endpoint.SanitizingFunction;
Expand Down Expand Up @@ -564,7 +565,7 @@ private String determineAccessorSuffix(String propertyName) {
* Description of an application's
* {@link ConfigurationProperties @ConfigurationProperties} beans.
*/
public static final class ConfigurationPropertiesDescriptor {
public static final class ConfigurationPropertiesDescriptor implements OperationResponseBody {

private final Map<String, ContextConfigurationPropertiesDescriptor> contexts;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.springframework.boot.actuate.endpoint.InvalidEndpointRequestException;
import org.springframework.boot.actuate.endpoint.InvocationContext;
import org.springframework.boot.actuate.endpoint.OperationArgumentResolver;
import org.springframework.boot.actuate.endpoint.OperationResponseBody;
import org.springframework.boot.actuate.endpoint.ProducibleOperationArgumentResolver;
import org.springframework.boot.actuate.endpoint.SecurityContext;
import org.springframework.boot.actuate.endpoint.web.EndpointLinksResolver;
Expand Down Expand Up @@ -323,7 +324,8 @@ private EndpointLinksInflector(EndpointLinksResolver linksResolver) {
public Response apply(ContainerRequestContext request) {
Map<String, Link> links = this.linksResolver
.resolveLinks(request.getUriInfo().getAbsolutePath().toString());
return Response.ok(Collections.singletonMap("_links", links)).build();
Map<String, Map<String, Link>> entity = OperationResponseBody.of(Collections.singletonMap("_links", links));
return Response.ok(entity).build();
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.springframework.aot.hint.annotation.Reflective;
import org.springframework.aot.hint.annotation.ReflectiveRuntimeHintsRegistrar;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.actuate.endpoint.OperationResponseBody;
import org.springframework.boot.actuate.endpoint.web.EndpointLinksResolver;
import org.springframework.boot.actuate.endpoint.web.EndpointMapping;
import org.springframework.boot.actuate.endpoint.web.EndpointMediaTypes;
Expand Down Expand Up @@ -87,8 +88,8 @@ class WebFluxLinksHandler implements LinksHandler {
public Map<String, Map<String, Link>> links(ServerWebExchange exchange) {
String requestUri = UriComponentsBuilder.fromUri(exchange.getRequest().getURI()).replaceQuery(null)
.toUriString();
return Collections.singletonMap("_links",
WebFluxEndpointHandlerMapping.this.linksResolver.resolveLinks(requestUri));
Map<String, Link> links = WebFluxEndpointHandlerMapping.this.linksResolver.resolveLinks(requestUri);
return OperationResponseBody.of(Collections.singletonMap("_links", links));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.aot.hint.annotation.Reflective;
import org.springframework.aot.hint.annotation.ReflectiveRuntimeHintsRegistrar;
import org.springframework.boot.actuate.endpoint.OperationResponseBody;
import org.springframework.boot.actuate.endpoint.web.EndpointLinksResolver;
import org.springframework.boot.actuate.endpoint.web.EndpointMapping;
import org.springframework.boot.actuate.endpoint.web.EndpointMediaTypes;
Expand Down Expand Up @@ -84,8 +85,9 @@ class WebMvcLinksHandler implements LinksHandler {
@ResponseBody
@Reflective
public Map<String, Map<String, Link>> links(HttpServletRequest request, HttpServletResponse response) {
return Collections.singletonMap("_links",
WebMvcEndpointHandlerMapping.this.linksResolver.resolveLinks(request.getRequestURL().toString()));
Map<String, Link> links = WebMvcEndpointHandlerMapping.this.linksResolver
.resolveLinks(request.getRequestURL().toString());
return OperationResponseBody.of(Collections.singletonMap("_links", links));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import com.fasterxml.jackson.annotation.JsonInclude;

import org.springframework.boot.actuate.endpoint.OperationResponseBody;
import org.springframework.boot.actuate.endpoint.SanitizableData;
import org.springframework.boot.actuate.endpoint.Sanitizer;
import org.springframework.boot.actuate.endpoint.SanitizingFunction;
Expand Down Expand Up @@ -203,7 +204,7 @@ protected Object stringifyIfNecessary(Object value) {
/**
* Description of an {@link Environment}.
*/
public static final class EnvironmentDescriptor {
public static final class EnvironmentDescriptor implements OperationResponseBody {

private final List<String> activeProfiles;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.flywaydb.core.api.MigrationInfo;
import org.flywaydb.core.api.MigrationState;

import org.springframework.boot.actuate.endpoint.OperationResponseBody;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.context.ApplicationContext;
Expand Down Expand Up @@ -69,7 +70,7 @@ public FlywayBeansDescriptor flywayBeans() {
/**
* Description of an application's {@link Flyway} beans.
*/
public static final class FlywayBeansDescriptor {
public static final class FlywayBeansDescriptor implements OperationResponseBody {

private final Map<String, ContextFlywayBeansDescriptor> contexts;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 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.
Expand All @@ -18,6 +18,8 @@

import com.fasterxml.jackson.annotation.JsonUnwrapped;

import org.springframework.boot.actuate.endpoint.OperationResponseBody;

/**
* A component that contributes data to results returned from the {@link HealthEndpoint}.
*
Expand All @@ -26,7 +28,7 @@
* @see Health
* @see CompositeHealth
*/
public abstract class HealthComponent {
public abstract class HealthComponent implements OperationResponseBody {

HealthComponent() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.List;
import java.util.Map;

import org.springframework.boot.actuate.endpoint.OperationResponseBody;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.util.Assert;
Expand Down Expand Up @@ -51,7 +52,7 @@ public Map<String, Object> info() {
for (InfoContributor contributor : this.infoContributors) {
contributor.contribute(builder);
}
return builder.build().getDetails();
return OperationResponseBody.of(builder.build().getDetails());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.springframework.aot.hint.BindingReflectionHintsRegistrar;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.boot.actuate.endpoint.OperationResponseBody;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.boot.actuate.endpoint.annotation.WriteOperation;
Expand Down Expand Up @@ -99,7 +100,7 @@ public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
/**
* Description of a {@link Graph}.
*/
public static class GraphDescriptor {
public static class GraphDescriptor implements OperationResponseBody {

private final Map<String, Object> contentDescriptor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import liquibase.database.jvm.JdbcConnection;
import liquibase.integration.spring.SpringLiquibase;

import org.springframework.boot.actuate.endpoint.OperationResponseBody;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.context.ApplicationContext;
Expand Down Expand Up @@ -106,7 +107,7 @@ private LiquibaseBeanDescriptor createReport(SpringLiquibase liquibase, Database
/**
* Description of an application's {@link SpringLiquibase} beans.
*/
public static final class LiquibaseBeansDescriptor {
public static final class LiquibaseBeansDescriptor implements OperationResponseBody {

private final Map<String, ContextLiquibaseBeansDescriptor> contexts;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.TreeSet;

import org.springframework.aot.hint.annotation.RegisterReflectionForBinding;
import org.springframework.boot.actuate.endpoint.OperationResponseBody;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.boot.actuate.endpoint.annotation.Selector;
Expand Down Expand Up @@ -121,7 +122,7 @@ private Map<String, LoggerLevelsDescriptor> getLoggers(Collection<LoggerConfigur
/**
* Description of loggers.
*/
public static class LoggersDescriptor {
public static class LoggersDescriptor implements OperationResponseBody {

/**
* Empty description.
Expand Down Expand Up @@ -158,7 +159,7 @@ public Map<String, GroupLoggerLevelsDescriptor> getGroups() {
/**
* Description of levels configured for a given logger.
*/
public static class LoggerLevelsDescriptor {
public static class LoggerLevelsDescriptor implements OperationResponseBody {

private String configuredLevel;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.List;
import java.util.function.Function;

import org.springframework.boot.actuate.endpoint.OperationResponseBody;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;

Expand Down Expand Up @@ -54,7 +55,7 @@ private <T> T getFormattedThreadDump(Function<ThreadInfo[], T> formatter) {
/**
* Description of a thread dump.
*/
public static final class ThreadDumpDescriptor {
public static final class ThreadDumpDescriptor implements OperationResponseBody {

private final List<ThreadInfo> threads;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import io.micrometer.core.instrument.composite.CompositeMeterRegistry;

import org.springframework.boot.actuate.endpoint.InvalidEndpointRequestException;
import org.springframework.boot.actuate.endpoint.OperationResponseBody;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.boot.actuate.endpoint.annotation.Selector;
Expand Down Expand Up @@ -159,7 +160,7 @@ private <K, V, T> List<T> asList(Map<K, V> map, BiFunction<K, V, T> mapper) {
/**
* Description of metric names.
*/
public static final class MetricNamesDescriptor {
public static final class MetricNamesDescriptor implements OperationResponseBody {

private final Set<String> names;

Expand All @@ -176,7 +177,7 @@ public Set<String> getNames() {
/**
* Description of a metric.
*/
public static final class MetricDescriptor {
public static final class MetricDescriptor implements OperationResponseBody {

private final String name;

Expand Down
Loading

0 comments on commit 3d2071d

Please sign in to comment.