Add v2 content type to actuator endpoints
Closes gh-7968
This commit is contained in:
@@ -250,7 +250,7 @@ public class EndpointWebMvcHypermediaManagementContextConfiguration {
|
||||
if (messageConverter instanceof TypeConstrainedMappingJackson2HttpMessageConverter) {
|
||||
List<MediaType> supportedMediaTypes = new ArrayList<>(
|
||||
messageConverter.getSupportedMediaTypes());
|
||||
supportedMediaTypes.add(ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON);
|
||||
supportedMediaTypes.add(ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON);
|
||||
((AbstractHttpMessageConverter<?>) messageConverter)
|
||||
.setSupportedMediaTypes(supportedMediaTypes);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@RequestMapping(method = RequestMethod.GET, produces = {
|
||||
ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON_VALUE,
|
||||
ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON_VALUE,
|
||||
MediaType.APPLICATION_JSON_VALUE })
|
||||
@interface ActuatorGetMapping {
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.springframework.http.MediaType;
|
||||
* {@link MediaType MediaTypes} that can be consumed and produced by Actuator endpoints.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
* @author Madhura Bhave
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public final class ActuatorMediaTypes {
|
||||
@@ -31,12 +32,23 @@ public final class ActuatorMediaTypes {
|
||||
*/
|
||||
public static final String APPLICATION_ACTUATOR_V1_JSON_VALUE = "application/vnd.spring-boot.actuator.v1+json";
|
||||
|
||||
/**
|
||||
* {@link String} equivalent of {@link #APPLICATION_ACTUATOR_V2_JSON}.
|
||||
*/
|
||||
public static final String APPLICATION_ACTUATOR_V2_JSON_VALUE = "application/vnd.spring-boot.actuator.v2+json";
|
||||
|
||||
/**
|
||||
* The {@code application/vnd.spring-boot.actuator.v1+json} media type.
|
||||
*/
|
||||
public static final MediaType APPLICATION_ACTUATOR_V1_JSON = MediaType
|
||||
.valueOf(APPLICATION_ACTUATOR_V1_JSON_VALUE);
|
||||
|
||||
/**
|
||||
* The {@code application/vnd.spring-boot.actuator.v2+json} media type.
|
||||
*/
|
||||
public static final MediaType APPLICATION_ACTUATOR_V2_JSON = MediaType
|
||||
.valueOf(APPLICATION_ACTUATOR_V2_JSON_VALUE);
|
||||
|
||||
private ActuatorMediaTypes() {
|
||||
|
||||
}
|
||||
|
||||
@@ -40,9 +40,9 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@RequestMapping(method = RequestMethod.POST, consumes = {
|
||||
ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON_VALUE,
|
||||
ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON_VALUE,
|
||||
MediaType.APPLICATION_JSON_VALUE }, produces = {
|
||||
ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON_VALUE,
|
||||
ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON_VALUE,
|
||||
MediaType.APPLICATION_JSON_VALUE })
|
||||
@interface ActuatorPostMapping {
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ public class ShutdownMvcEndpoint extends EndpointMvcAdapter {
|
||||
super(delegate);
|
||||
}
|
||||
|
||||
@PostMapping(produces = { ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON_VALUE,
|
||||
@PostMapping(produces = { ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON_VALUE,
|
||||
MediaType.APPLICATION_JSON_VALUE })
|
||||
@ResponseBody
|
||||
@Override
|
||||
|
||||
@@ -73,10 +73,10 @@ public class AuditEventsMvcEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contentTypeDefaultsToActuatorV1Json() throws Exception {
|
||||
public void contentTypeDefaultsToActuatorV2Json() throws Exception {
|
||||
this.mvc.perform(get("/auditevents")).andExpect(status().isOk())
|
||||
.andExpect(header().string("Content-Type",
|
||||
"application/vnd.spring-boot.actuator.v1+json;charset=UTF-8"));
|
||||
"application/vnd.spring-boot.actuator.v2+json;charset=UTF-8"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -79,10 +79,10 @@ public class EnvironmentMvcEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void homeContentTypeDefaultsToActuatorV1Json() throws Exception {
|
||||
public void homeContentTypeDefaultsToActuatorV2Json() throws Exception {
|
||||
this.mvc.perform(get("/env")).andExpect(status().isOk())
|
||||
.andExpect(header().string("Content-Type",
|
||||
"application/vnd.spring-boot.actuator.v1+json;charset=UTF-8"));
|
||||
"application/vnd.spring-boot.actuator.v2+json;charset=UTF-8"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -94,10 +94,10 @@ public class EnvironmentMvcEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void subContentTypeDefaultsToActuatorV1Json() throws Exception {
|
||||
public void subContentTypeDefaultsToActuatorV2Json() throws Exception {
|
||||
this.mvc.perform(get("/env/foo")).andExpect(status().isOk())
|
||||
.andExpect(header().string("Content-Type",
|
||||
"application/vnd.spring-boot.actuator.v1+json;charset=UTF-8"));
|
||||
"application/vnd.spring-boot.actuator.v2+json;charset=UTF-8"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -83,10 +83,10 @@ public class InfoMvcEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contentTypeDefaultsToActuatorV1Json() throws Exception {
|
||||
public void contentTypeDefaultsToActuatorV2Json() throws Exception {
|
||||
this.mvc.perform(get("/info")).andExpect(status().isOk())
|
||||
.andExpect(header().string("Content-Type",
|
||||
"application/vnd.spring-boot.actuator.v1+json;charset=UTF-8"));
|
||||
"application/vnd.spring-boot.actuator.v2+json;charset=UTF-8"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -130,10 +130,10 @@ public class LoggersMvcEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contentTypeForGetDefaultsToActuatorV1Json() throws Exception {
|
||||
public void contentTypeForGetDefaultsToActuatorV2Json() throws Exception {
|
||||
this.mvc.perform(get("/loggers")).andExpect(status().isOk())
|
||||
.andExpect(header().string("Content-Type",
|
||||
"application/vnd.spring-boot.actuator.v1+json;charset=UTF-8"));
|
||||
"application/vnd.spring-boot.actuator.v2+json;charset=UTF-8"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -152,9 +152,9 @@ public class LoggersMvcEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setLoggerUsingActuatorV1JsonShouldSetLogLevel() throws Exception {
|
||||
public void setLoggerUsingActuatorV2JsonShouldSetLogLevel() throws Exception {
|
||||
this.mvc.perform(post("/loggers/ROOT")
|
||||
.contentType(ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON)
|
||||
.contentType(ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON)
|
||||
.content("{\"configuredLevel\":\"debug\"}")).andExpect(status().isOk());
|
||||
verify(this.loggingSystem).setLogLevel("ROOT", LogLevel.DEBUG);
|
||||
}
|
||||
|
||||
@@ -83,10 +83,10 @@ public class MetricsMvcEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void homeContentTypeDefaultsToActuatorV1Json() throws Exception {
|
||||
public void homeContentTypeDefaultsToActuatorV2Json() throws Exception {
|
||||
this.mvc.perform(get("/metrics")).andExpect(status().isOk())
|
||||
.andExpect(header().string("Content-Type",
|
||||
"application/vnd.spring-boot.actuator.v1+json;charset=UTF-8"));
|
||||
"application/vnd.spring-boot.actuator.v2+json;charset=UTF-8"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -98,10 +98,10 @@ public class MetricsMvcEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void specificMetricContentTypeDefaultsToActuatorV1Json() throws Exception {
|
||||
public void specificMetricContentTypeDefaultsToActuatorV2Json() throws Exception {
|
||||
this.mvc.perform(get("/metrics/foo")).andExpect(status().isOk())
|
||||
.andExpect(header().string("Content-Type",
|
||||
"application/vnd.spring-boot.actuator.v1+json;charset=UTF-8"));
|
||||
"application/vnd.spring-boot.actuator.v2+json;charset=UTF-8"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -74,10 +74,10 @@ public class ShutdownMvcEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contentTypeDefaultsToActuatorV1Json() throws Exception {
|
||||
public void contentTypeDefaultsToActuatorV2Json() throws Exception {
|
||||
this.mvc.perform(post("/shutdown")).andExpect(status().isOk())
|
||||
.andExpect(header().string("Content-Type",
|
||||
"application/vnd.spring-boot.actuator.v1+json;charset=UTF-8"));
|
||||
"application/vnd.spring-boot.actuator.v2+json;charset=UTF-8"));
|
||||
assertThat(this.context.getBean(CountDownLatch.class).await(30, TimeUnit.SECONDS))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user