Skip to content

Commit 32102c6

Browse files
committed
Avoid using classes from spring-web in core web endpoint infrastructure
Closes gh-10358
1 parent 3fcaa97 commit 32102c6

File tree

7 files changed

+19
-29
lines changed

7 files changed

+19
-29
lines changed

spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/EndpointAutoConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public DefaultCachingConfigurationFactory cacheConfigurationFactory(
6363
static class EndpointWebConfiguration {
6464

6565
private static final List<String> MEDIA_TYPES = Arrays
66-
.asList(ActuatorMediaType.V2_JSON_VALUE, "application/json");
66+
.asList(ActuatorMediaType.V2_JSON, "application/json");
6767

6868
private final ApplicationContext applicationContext;
6969

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/http/ActuatorMediaType.java

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@
1616

1717
package org.springframework.boot.actuate.endpoint.http;
1818

19-
import org.springframework.http.MediaType;
20-
2119
/**
22-
* {@link MediaType MediaTypes} that can be consumed and produced by Actuator endpoints.
20+
* Media types that can be consumed and produced by Actuator endpoints.
2321
*
2422
* @author Andy Wilkinson
2523
* @author Madhura Bhave
@@ -28,24 +26,14 @@
2826
public final class ActuatorMediaType {
2927

3028
/**
31-
* {@link String} equivalent of {@link #V1_JSON}.
32-
*/
33-
public static final String V1_JSON_VALUE = "application/vnd.spring-boot.actuator.v1+json";
34-
35-
/**
36-
* {@link String} equivalent of {@link #V2_JSON}.
37-
*/
38-
public static final String V2_JSON_VALUE = "application/vnd.spring-boot.actuator.v2+json";
39-
40-
/**
41-
* The {@code application/vnd.spring-boot.actuator.v1+json} media type.
29+
* Constant for the Actuator V1 media type.
4230
*/
43-
public static final MediaType V1_JSON = MediaType.valueOf(V1_JSON_VALUE);
31+
public static final String V1_JSON = "application/vnd.spring-boot.actuator.v1+json";
4432

4533
/**
46-
* The {@code application/vnd.spring-boot.actuator.v2+json} media type.
34+
* Constant for the Actuator V2 media type.
4735
*/
48-
public static final MediaType V2_JSON = MediaType.valueOf(V2_JSON_VALUE);
36+
public static final String V2_JSON = "application/vnd.spring-boot.actuator.v2+json";
4937

5038
private ActuatorMediaType() {
5139
}

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/test/JerseyEndpointsRunner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public ResourceConfigCustomizer webEndpointRegistrar() {
9191

9292
private void customize(ResourceConfig config) {
9393
List<String> mediaTypes = Arrays.asList(MediaType.APPLICATION_JSON_VALUE,
94-
ActuatorMediaType.V2_JSON_VALUE);
94+
ActuatorMediaType.V2_JSON);
9595
WebAnnotationEndpointDiscoverer discoverer = new WebAnnotationEndpointDiscoverer(
9696
this.applicationContext,
9797
new ConversionServiceOperationParameterMapper(), (id) -> null,

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/test/WebFluxEndpointsRunner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public HttpHandler httpHandler(ApplicationContext applicationContext) {
9898
@Bean
9999
public WebFluxEndpointHandlerMapping webEndpointReactiveHandlerMapping() {
100100
List<String> mediaTypes = Arrays.asList(MediaType.APPLICATION_JSON_VALUE,
101-
ActuatorMediaType.V2_JSON_VALUE);
101+
ActuatorMediaType.V2_JSON);
102102
WebAnnotationEndpointDiscoverer discoverer = new WebAnnotationEndpointDiscoverer(
103103
this.applicationContext,
104104
new ConversionServiceOperationParameterMapper(), (id) -> null,

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/test/WebMvcEndpointRunner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public TomcatServletWebServerFactory tomcat() {
8181
@Bean
8282
public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping() {
8383
List<String> mediaTypes = Arrays.asList(MediaType.APPLICATION_JSON_VALUE,
84-
ActuatorMediaType.V2_JSON_VALUE);
84+
ActuatorMediaType.V2_JSON);
8585
WebAnnotationEndpointDiscoverer discoverer = new WebAnnotationEndpointDiscoverer(
8686
this.applicationContext,
8787
new ConversionServiceOperationParameterMapper(), (id) -> null,

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/logger/LoggersEndpointWebIntegrationTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public void setLoggerUsingApplicationJsonShouldSetLogLevel() throws Exception {
116116
@Test
117117
public void setLoggerUsingActuatorV2JsonShouldSetLogLevel() throws Exception {
118118
client.post().uri("/application/loggers/ROOT")
119-
.contentType(ActuatorMediaType.V2_JSON)
119+
.contentType(MediaType.parseMediaType(ActuatorMediaType.V2_JSON))
120120
.syncBody(Collections.singletonMap("configuredLevel", "debug")).exchange()
121121
.expectStatus().isNoContent();
122122
verify(this.loggingSystem).setLogLevel("ROOT", LogLevel.DEBUG);
@@ -134,7 +134,7 @@ public void setLoggerWithWrongLogLevelResultInBadRequestResponse() throws Except
134134
@Test
135135
public void setLoggerWithNullLogLevel() throws Exception {
136136
client.post().uri("/application/loggers/ROOT")
137-
.contentType(ActuatorMediaType.V2_JSON)
137+
.contentType(MediaType.parseMediaType(ActuatorMediaType.V2_JSON))
138138
.syncBody(Collections.singletonMap("configuredLevel", null)).exchange()
139139
.expectStatus().isNoContent();
140140
verify(this.loggingSystem).setLogLevel("ROOT", null);
@@ -143,8 +143,8 @@ public void setLoggerWithNullLogLevel() throws Exception {
143143
@Test
144144
public void setLoggerWithNoLogLevel() throws Exception {
145145
client.post().uri("/application/loggers/ROOT")
146-
.contentType(ActuatorMediaType.V2_JSON).syncBody(Collections.emptyMap())
147-
.exchange().expectStatus().isNoContent();
146+
.contentType(MediaType.parseMediaType(ActuatorMediaType.V2_JSON))
147+
.syncBody(Collections.emptyMap()).exchange().expectStatus().isNoContent();
148148
verify(this.loggingSystem).setLogLevel("ROOT", null);
149149
}
150150

spring-boot-parent/src/checkstyle/import-control.xml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,19 @@
3030
</subpackage>
3131

3232
<!-- Endpoint infrastructure -->
33-
<subpackage name="endpoint">
33+
<subpackage name="actuate.endpoint">
3434
<disallow pkg="org.springframework.http" />
3535
<disallow pkg="org.springframework.web" />
3636
<subpackage name="web">
37-
<allow pkg="org.springframework.http" />
38-
<allow pkg="org.springframework.web" />
39-
<subpackage name="mvc">
37+
<subpackage name="servlet">
4038
<disallow pkg="org.springframework.web.reactive" />
39+
<allow pkg="org.springframework.http" />
40+
<allow pkg="org.springframework.web" />
4141
</subpackage>
4242
<subpackage name="reactive">
4343
<disallow pkg="org.springframework.web.servlet" />
44+
<allow pkg="org.springframework.http" />
45+
<allow pkg="org.springframework.web" />
4446
</subpackage>
4547
</subpackage>
4648
</subpackage>

0 commit comments

Comments
 (0)