From 99b3240ab270a935061b4ac68fe59053cccfcc8c Mon Sep 17 00:00:00 2001 From: Christian Dupuis Date: Mon, 21 Jul 2014 16:11:38 +0200 Subject: [PATCH] Ensure custom HTTP code mappings for /health don't remove default mappings Previously any custom http code mapping would remove the default mappings. With this commit the behaviour is changed so that default mappings will stay if a custom mapping is registered. Certainly a default mapping can be overridden. fixes #1264 --- .../EndpointWebMvcAutoConfiguration.java | 2 +- .../actuate/endpoint/mvc/HealthMvcEndpoint.java | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.java index 5e49ac59f74..3c7fc0ed908 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.java @@ -157,7 +157,7 @@ public class EndpointWebMvcAutoConfiguration implements ApplicationContextAware, public HealthMvcEndpoint healthMvcEndpoint(HealthEndpoint delegate) { HealthMvcEndpoint healthMvcEndpoint = new HealthMvcEndpoint(delegate); if (this.healthMvcEndpointProperties.getMapping() != null) { - healthMvcEndpoint.setStatusMapping(this.healthMvcEndpointProperties + healthMvcEndpoint.addStatusMapping(this.healthMvcEndpointProperties .getMapping()); } return healthMvcEndpoint; diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/HealthMvcEndpoint.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/HealthMvcEndpoint.java index 2bf10fbdce9..532f9729201 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/HealthMvcEndpoint.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/HealthMvcEndpoint.java @@ -31,7 +31,7 @@ import org.springframework.web.bind.annotation.ResponseBody; /** * Adapter to expose {@link HealthEndpoint} as an {@link MvcEndpoint}. - * + * * @author Christian Dupuis * @since 1.1.0 */ @@ -50,7 +50,7 @@ public class HealthMvcEndpoint extends EndpointMvcAdapter { } /** - * Set specific status mappings + * Set specific status mappings. * @param statusMapping a map of status code to {@link HttpStatus} */ public void setStatusMapping(Map statusMapping) { @@ -59,7 +59,16 @@ public class HealthMvcEndpoint extends EndpointMvcAdapter { } /** - * Add a status mapping to the existing set + * Add specfic status mappings to the existing set. + * @param statusMapping a map of status code to {@link HttpStatus} + */ + public void addStatusMapping(Map statusMapping) { + Assert.notNull(statusMapping, "StatusMapping must not be null"); + this.statusMapping.putAll(statusMapping); + } + + /** + * Add a status mapping to the existing set. * @param status the status to map * @param httpStatus the http status */ @@ -70,7 +79,7 @@ public class HealthMvcEndpoint extends EndpointMvcAdapter { } /** - * Add a status mapping to the existing set + * Add a status mapping to the existing set. * @param statusCode the status code to map * @param httpStatus the http status */