Skip to content

Commit ab72cc8

Browse files
committed
Revert "Add actuator specific ObjectMapper"
See gh-12951 See gh-20291
1 parent 4249202 commit ab72cc8

File tree

14 files changed

+117
-373
lines changed

14 files changed

+117
-373
lines changed

Diff for: spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/EndpointAutoConfiguration.java

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,7 +25,6 @@
2525
import org.springframework.boot.actuate.endpoint.invoke.ParameterValueMapper;
2626
import org.springframework.boot.actuate.endpoint.invoke.convert.ConversionServiceParameterValueMapper;
2727
import org.springframework.boot.actuate.endpoint.invoker.cache.CachingOperationInvokerAdvisor;
28-
import org.springframework.boot.actuate.endpoint.json.ActuatorJsonMapperProvider;
2928
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
3029
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
3130
import org.springframework.boot.convert.ApplicationConversionService;
@@ -76,9 +75,4 @@ public CachingOperationInvokerAdvisor endpointCachingOperationInvokerAdvisor(Env
7675
return new CachingOperationInvokerAdvisor(new EndpointIdTimeToLivePropertyFunction(environment));
7776
}
7877

79-
@Bean
80-
public ActuatorJsonMapperProvider actuatorJsonMapperProvider() {
81-
return new ActuatorJsonMapperProvider();
82-
}
83-
8478
}

Diff for: spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/jmx/JmxEndpointAutoConfiguration.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,6 +20,8 @@
2020

2121
import javax.management.MBeanServer;
2222

23+
import com.fasterxml.jackson.databind.ObjectMapper;
24+
2325
import org.springframework.beans.factory.ObjectProvider;
2426
import org.springframework.boot.actuate.autoconfigure.endpoint.ExposeExcludePropertyEndpointFilter;
2527
import org.springframework.boot.actuate.endpoint.EndpointFilter;
@@ -33,7 +35,6 @@
3335
import org.springframework.boot.actuate.endpoint.jmx.JmxEndpointsSupplier;
3436
import org.springframework.boot.actuate.endpoint.jmx.JmxOperationResponseMapper;
3537
import org.springframework.boot.actuate.endpoint.jmx.annotation.JmxEndpointDiscoverer;
36-
import org.springframework.boot.actuate.endpoint.json.ActuatorJsonMapperProvider;
3738
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
3839
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
3940
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
@@ -84,12 +85,12 @@ public JmxEndpointDiscoverer jmxAnnotationEndpointDiscoverer(ParameterValueMappe
8485
@Bean
8586
@ConditionalOnSingleCandidate(MBeanServer.class)
8687
public JmxEndpointExporter jmxMBeanExporter(MBeanServer mBeanServer, Environment environment,
87-
ActuatorJsonMapperProvider actuatorJsonMapperProvider, JmxEndpointsSupplier jmxEndpointsSupplier) {
88+
ObjectProvider<ObjectMapper> objectMapper, JmxEndpointsSupplier jmxEndpointsSupplier) {
8889
String contextId = ObjectUtils.getIdentityHexString(this.applicationContext);
8990
EndpointObjectNameFactory objectNameFactory = new DefaultEndpointObjectNameFactory(this.properties, environment,
9091
mBeanServer, contextId);
9192
JmxOperationResponseMapper responseMapper = new JacksonJmxOperationResponseMapper(
92-
actuatorJsonMapperProvider.getInstance());
93+
objectMapper.getIfAvailable());
9394
return new JmxEndpointExporter(mBeanServer, objectNameFactory, responseMapper,
9495
jmxEndpointsSupplier.getEndpoints());
9596

Diff for: spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/jersey/JerseyWebEndpointManagementContextConfiguration.java

+1-28
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,10 +22,7 @@
2222
import java.util.List;
2323

2424
import javax.annotation.PostConstruct;
25-
import javax.ws.rs.Produces;
26-
import javax.ws.rs.ext.ContextResolver;
2725

28-
import com.fasterxml.jackson.databind.ObjectMapper;
2926
import org.glassfish.jersey.server.ResourceConfig;
3027
import org.glassfish.jersey.server.model.Resource;
3128

@@ -35,8 +32,6 @@
3532
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementPortType;
3633
import org.springframework.boot.actuate.endpoint.ExposableEndpoint;
3734
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
38-
import org.springframework.boot.actuate.endpoint.http.ActuatorMediaType;
39-
import org.springframework.boot.actuate.endpoint.json.ActuatorJsonMapperProvider;
4035
import org.springframework.boot.actuate.endpoint.web.EndpointLinksResolver;
4136
import org.springframework.boot.actuate.endpoint.web.EndpointMapping;
4237
import org.springframework.boot.actuate.endpoint.web.EndpointMediaTypes;
@@ -89,12 +84,6 @@ private boolean shouldRegisterLinksMapping(Environment environment, String baseP
8984
|| ManagementPortType.get(environment).equals(ManagementPortType.DIFFERENT);
9085
}
9186

92-
@Bean
93-
ResourceConfigCustomizer actuatorResourceConfigCustomizer(ActuatorJsonMapperProvider jsonMapperProvider) {
94-
return (ResourceConfig config) -> config.register(
95-
new ActuatorJsonMapperContextResolver(jsonMapperProvider.getInstance()), ContextResolver.class);
96-
}
97-
9887
/**
9988
* Register endpoints with the {@link ResourceConfig}. The
10089
* {@link ResourceConfigCustomizer} cannot be used because we don't want to apply
@@ -156,20 +145,4 @@ private void register(Collection<Resource> resources) {
156145

157146
}
158147

159-
@Produces({ ActuatorMediaType.V3_JSON, ActuatorMediaType.V2_JSON })
160-
private static final class ActuatorJsonMapperContextResolver implements ContextResolver<ObjectMapper> {
161-
162-
private final ObjectMapper objectMapper;
163-
164-
private ActuatorJsonMapperContextResolver(ObjectMapper objectMapper) {
165-
this.objectMapper = objectMapper;
166-
}
167-
168-
@Override
169-
public ObjectMapper getContext(Class<?> type) {
170-
return this.objectMapper;
171-
}
172-
173-
}
174-
175148
}

Diff for: spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/reactive/WebFluxEndpointManagementContextConfiguration.java

+1-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,8 +26,6 @@
2626
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementPortType;
2727
import org.springframework.boot.actuate.endpoint.ExposableEndpoint;
2828
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
29-
import org.springframework.boot.actuate.endpoint.http.ActuatorMediaType;
30-
import org.springframework.boot.actuate.endpoint.json.ActuatorJsonMapperProvider;
3129
import org.springframework.boot.actuate.endpoint.web.EndpointLinksResolver;
3230
import org.springframework.boot.actuate.endpoint.web.EndpointMapping;
3331
import org.springframework.boot.actuate.endpoint.web.EndpointMediaTypes;
@@ -42,13 +40,8 @@
4240
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
4341
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
4442
import org.springframework.boot.context.properties.EnableConfigurationProperties;
45-
import org.springframework.boot.web.codec.CodecCustomizer;
4643
import org.springframework.context.annotation.Bean;
47-
import org.springframework.core.annotation.Order;
4844
import org.springframework.core.env.Environment;
49-
import org.springframework.http.MediaType;
50-
import org.springframework.http.codec.CodecConfigurer;
51-
import org.springframework.http.codec.json.Jackson2JsonEncoder;
5245
import org.springframework.http.server.reactive.HttpHandler;
5346
import org.springframework.util.StringUtils;
5447
import org.springframework.web.reactive.DispatcherHandler;
@@ -59,7 +52,6 @@
5952
*
6053
* @author Andy Wilkinson
6154
* @author Phillip Webb
62-
* @author Brian Clozel
6355
* @since 2.0.0
6456
*/
6557
@ManagementContextConfiguration(proxyBeanMethods = false)
@@ -101,16 +93,4 @@ public ControllerEndpointHandlerMapping controllerEndpointHandlerMapping(
10193
corsProperties.toCorsConfiguration());
10294
}
10395

104-
@Bean
105-
@Order(-1)
106-
public CodecCustomizer actuatorJsonCodec(ActuatorJsonMapperProvider actuatorJsonMapperProvider) {
107-
return (configurer) -> {
108-
MediaType v3MediaType = MediaType.parseMediaType(ActuatorMediaType.V3_JSON);
109-
MediaType v2MediaType = MediaType.parseMediaType(ActuatorMediaType.V2_JSON);
110-
CodecConfigurer.CustomCodecs customCodecs = configurer.customCodecs();
111-
customCodecs.register(
112-
new Jackson2JsonEncoder(actuatorJsonMapperProvider.getInstance(), v3MediaType, v2MediaType));
113-
};
114-
}
115-
11696
}

Diff for: spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/servlet/WebMvcEndpointManagementContextConfiguration.java

+1-42
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,16 +20,12 @@
2020
import java.util.Collection;
2121
import java.util.List;
2222

23-
import com.fasterxml.jackson.databind.ObjectMapper;
24-
2523
import org.springframework.boot.actuate.autoconfigure.endpoint.web.CorsEndpointProperties;
2624
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
2725
import org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration;
2826
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementPortType;
2927
import org.springframework.boot.actuate.endpoint.ExposableEndpoint;
3028
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
31-
import org.springframework.boot.actuate.endpoint.http.ActuatorMediaType;
32-
import org.springframework.boot.actuate.endpoint.json.ActuatorJsonMapperProvider;
3329
import org.springframework.boot.actuate.endpoint.web.EndpointLinksResolver;
3430
import org.springframework.boot.actuate.endpoint.web.EndpointMapping;
3531
import org.springframework.boot.actuate.endpoint.web.EndpointMediaTypes;
@@ -46,15 +42,9 @@
4642
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
4743
import org.springframework.boot.context.properties.EnableConfigurationProperties;
4844
import org.springframework.context.annotation.Bean;
49-
import org.springframework.context.annotation.Configuration;
50-
import org.springframework.core.Ordered;
5145
import org.springframework.core.env.Environment;
52-
import org.springframework.http.MediaType;
53-
import org.springframework.http.converter.HttpMessageConverter;
54-
import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter;
5546
import org.springframework.util.StringUtils;
5647
import org.springframework.web.servlet.DispatcherServlet;
57-
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
5848

5949
/**
6050
* {@link ManagementContextConfiguration @ManagementContextConfiguration} for Spring MVC
@@ -101,35 +91,4 @@ public ControllerEndpointHandlerMapping controllerEndpointHandlerMapping(
10191
corsProperties.toCorsConfiguration());
10292
}
10393

104-
@Configuration(proxyBeanMethods = false)
105-
public static class JsonWebMvcConfigurer implements WebMvcConfigurer, Ordered {
106-
107-
private final ActuatorJsonMapperProvider actuatorJsonMapperProvider;
108-
109-
public JsonWebMvcConfigurer(ActuatorJsonMapperProvider objectMapperFactory) {
110-
this.actuatorJsonMapperProvider = objectMapperFactory;
111-
}
112-
113-
@Override
114-
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
115-
converters.add(new ActuatorJsonHttpMessageConverter(this.actuatorJsonMapperProvider.getInstance()));
116-
}
117-
118-
// WebMvcAutoConfiguration is ordered at 0
119-
@Override
120-
public int getOrder() {
121-
return -1;
122-
}
123-
124-
}
125-
126-
static class ActuatorJsonHttpMessageConverter extends AbstractJackson2HttpMessageConverter {
127-
128-
ActuatorJsonHttpMessageConverter(ObjectMapper objectMapper) {
129-
super(objectMapper, MediaType.parseMediaType(ActuatorMediaType.V3_JSON),
130-
MediaType.parseMediaType(ActuatorMediaType.V2_JSON));
131-
}
132-
133-
}
134-
13594
}

Diff for: spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/WebMvcEndpointChildContextConfiguration.java

+1-32
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,13 +16,9 @@
1616

1717
package org.springframework.boot.actuate.autoconfigure.web.servlet;
1818

19-
import java.util.List;
20-
2119
import org.springframework.beans.factory.ListableBeanFactory;
22-
import org.springframework.beans.factory.ObjectProvider;
2320
import org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration;
2421
import org.springframework.boot.actuate.autoconfigure.web.ManagementContextType;
25-
import org.springframework.boot.actuate.endpoint.json.ActuatorJsonMapperProvider;
2622
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
2723
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
2824
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
@@ -37,15 +33,11 @@
3733
import org.springframework.boot.web.servlet.filter.OrderedRequestContextFilter;
3834
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
3935
import org.springframework.context.annotation.Bean;
40-
import org.springframework.context.annotation.Configuration;
4136
import org.springframework.core.Ordered;
42-
import org.springframework.http.converter.HttpMessageConverter;
43-
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
4437
import org.springframework.web.context.request.RequestContextListener;
4538
import org.springframework.web.filter.RequestContextFilter;
4639
import org.springframework.web.servlet.DispatcherServlet;
4740
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
48-
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
4941

5042
/**
5143
* {@link ManagementContextConfiguration @ManagementContextConfiguration} for Spring MVC
@@ -116,29 +108,6 @@ RequestContextFilter requestContextFilter() {
116108
return new OrderedRequestContextFilter();
117109
}
118110

119-
/**
120-
* Since {@code WebMvcEndpointManagementContextConfiguration} is adding an
121-
* actuator-specific JSON message converter, {@code @EnableWebMvc} will not register
122-
* default converters. We need to register a JSON converter for plain
123-
* {@code "application/json"} still.
124-
* WebMvcEndpointChildContextConfigurationIntegrationTests
125-
*/
126-
@Configuration(proxyBeanMethods = false)
127-
public static class FallbackJsonConverterConfigurer implements WebMvcConfigurer {
128-
129-
private final ActuatorJsonMapperProvider actuatorJsonMapperProvider;
130-
131-
FallbackJsonConverterConfigurer(ObjectProvider<ActuatorJsonMapperProvider> objectMapperSupplier) {
132-
this.actuatorJsonMapperProvider = objectMapperSupplier.getIfAvailable(ActuatorJsonMapperProvider::new);
133-
}
134-
135-
@Override
136-
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
137-
converters.add(new MappingJackson2HttpMessageConverter(this.actuatorJsonMapperProvider.getInstance()));
138-
}
139-
140-
}
141-
142111
/**
143112
* {@link WebServerFactoryCustomizer} to add an {@link ErrorPage} so that the
144113
* {@link ManagementErrorEndpoint} can be used.

Diff for: spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/ScheduledTasksEndpointDocumentationTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -52,7 +52,7 @@ class ScheduledTasksEndpointDocumentationTests extends MockMvcEndpointDocumentat
5252

5353
@Test
5454
void scheduledTasks() throws Exception {
55-
this.mockMvc.perform(get("/actuator/scheduledtasks").accept("application/json")).andExpect(status().isOk())
55+
this.mockMvc.perform(get("/actuator/scheduledtasks")).andExpect(status().isOk())
5656
.andDo(document("scheduled-tasks",
5757
preprocessResponse(replacePattern(
5858
Pattern.compile("org.*\\.ScheduledTasksEndpointDocumentationTests\\$TestConfiguration"),

Diff for: spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/jersey/JerseyWebEndpointManagementContextConfigurationTests.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@
2121
import org.glassfish.jersey.server.ResourceConfig;
2222
import org.junit.jupiter.api.Test;
2323

24-
import org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration;
2524
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointAutoConfiguration;
2625
import org.springframework.boot.actuate.autoconfigure.endpoint.web.jersey.JerseyWebEndpointManagementContextConfiguration.JerseyWebEndpointsResourcesRegistrar;
2726
import org.springframework.boot.actuate.autoconfigure.web.jersey.JerseySameManagementContextConfiguration;
@@ -42,8 +41,8 @@
4241
class JerseyWebEndpointManagementContextConfigurationTests {
4342

4443
private final WebApplicationContextRunner runner = new WebApplicationContextRunner()
45-
.withConfiguration(AutoConfigurations.of(EndpointAutoConfiguration.class,
46-
WebEndpointAutoConfiguration.class, JerseyWebEndpointManagementContextConfiguration.class))
44+
.withConfiguration(AutoConfigurations.of(WebEndpointAutoConfiguration.class,
45+
JerseyWebEndpointManagementContextConfiguration.class))
4746
.withBean(WebEndpointsSupplier.class, () -> Collections::emptyList);
4847

4948
@Test

0 commit comments

Comments
 (0)