diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/EndpointHandlerMapping.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/EndpointHandlerMapping.java index 16d194e466..6f26034435 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/EndpointHandlerMapping.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/EndpointHandlerMapping.java @@ -19,6 +19,7 @@ package org.springframework.boot.actuate.endpoint.mvc; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -196,9 +197,29 @@ public class EndpointHandlerMapping extends RequestMappingHandlerMapping { /** * Return the endpoints. * @return the endpoints + * @see #getEndpoints(Class) */ public Set getEndpoints() { - return new HashSet(this.endpoints); + return getEndpoints(MvcEndpoint.class); + } + + /** + * Return the endpoints of the specified type. + * @param the endpoint type + * @param type the endpoint type + * @return the endpoints + * @see #getEndpoints() + * @since 1.5.0 + */ + @SuppressWarnings("unchecked") + public Set getEndpoints(Class type) { + Set result = new HashSet(this.endpoints.size()); + for (MvcEndpoint candidate : this.endpoints) { + if (type.isInstance(candidate)) { + result.add((E) candidate); + } + } + return Collections.unmodifiableSet(result); } @Override diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/EndpointHandlerMappingTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/EndpointHandlerMappingTests.java index 77c8dc1336..981affd1d5 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/EndpointHandlerMappingTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/EndpointHandlerMappingTests.java @@ -136,6 +136,15 @@ public class EndpointHandlerMappingTests { assertThat(mapping.getHandler(request("POST", "/a"))).isNull(); } + @Test + public void getEndpointsForSpecifiedType() throws Exception { + TestMvcEndpoint endpoint = new TestMvcEndpoint(new TestEndpoint("a")); + TestActionEndpoint other = new TestActionEndpoint(new TestEndpoint("b")); + EndpointHandlerMapping mapping = new EndpointHandlerMapping( + Arrays.asList(endpoint, other)); + assertThat(mapping.getEndpoints(TestMvcEndpoint.class)).containsExactly(endpoint); + } + private MockHttpServletRequest request(String method, String requestURI) { return new MockHttpServletRequest(method, requestURI); }