Use Set (again) for enumerating MvcEndpoints
This reverts a change that I assume was orphaned from work in progress to address #1353, but is no longer needed. Anyway there is no reason to restrict MvcEndpoints to be unique by path since they can declare their own @RequestMappings (and if there are duplicates they will be detected when those are scanned). Fixes gh-1911
This commit is contained in:
parent
bc76c87d44
commit
90d25bd582
|
@ -18,10 +18,7 @@ package org.springframework.boot.actuate.endpoint.mvc;
|
|||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.Endpoint;
|
||||
|
@ -53,7 +50,7 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl
|
|||
public class EndpointHandlerMapping extends RequestMappingHandlerMapping implements
|
||||
ApplicationContextAware {
|
||||
|
||||
private final Map<String, MvcEndpoint> endpoints;
|
||||
private final Set<MvcEndpoint> endpoints;
|
||||
|
||||
private String prefix = "";
|
||||
|
||||
|
@ -65,26 +62,17 @@ public class EndpointHandlerMapping extends RequestMappingHandlerMapping impleme
|
|||
* @param endpoints
|
||||
*/
|
||||
public EndpointHandlerMapping(Collection<? extends MvcEndpoint> endpoints) {
|
||||
this.endpoints = buildEndpointsMap(endpoints);
|
||||
this.endpoints = new HashSet<MvcEndpoint>(endpoints);
|
||||
// By default the static resource handler mapping is LOWEST_PRECEDENCE - 1
|
||||
// and the RequestMappingHandlerMapping is 0 (we ideally want to be before both)
|
||||
setOrder(-100);
|
||||
}
|
||||
|
||||
private Map<String, MvcEndpoint> buildEndpointsMap(
|
||||
Collection<? extends MvcEndpoint> endpoints) {
|
||||
Map<String, MvcEndpoint> map = new LinkedHashMap<String, MvcEndpoint>();
|
||||
for (MvcEndpoint endpoint : endpoints) {
|
||||
map.put(endpoint.getPath(), endpoint);
|
||||
}
|
||||
return Collections.unmodifiableMap(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
super.afterPropertiesSet();
|
||||
if (!this.disabled) {
|
||||
for (MvcEndpoint endpoint : this.endpoints.values()) {
|
||||
for (MvcEndpoint endpoint : this.endpoints) {
|
||||
detectHandlerMethods(endpoint);
|
||||
}
|
||||
}
|
||||
|
@ -183,7 +171,7 @@ public class EndpointHandlerMapping extends RequestMappingHandlerMapping impleme
|
|||
* Return the endpoints
|
||||
*/
|
||||
public Set<? extends MvcEndpoint> getEndpoints() {
|
||||
return new HashSet<MvcEndpoint>(this.endpoints.values());
|
||||
return new HashSet<MvcEndpoint>(this.endpoints);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -133,6 +133,21 @@ public class EndpointHandlerMappingTests {
|
|||
nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void duplicatePath() throws Exception {
|
||||
TestMvcEndpoint endpoint = new TestMvcEndpoint(new TestEndpoint("/a"));
|
||||
TestActionEndpoint other = new TestActionEndpoint(new TestEndpoint("/a"));
|
||||
EndpointHandlerMapping mapping = new EndpointHandlerMapping(Arrays.asList(
|
||||
endpoint, other));
|
||||
mapping.setDisabled(true);
|
||||
mapping.setApplicationContext(this.context);
|
||||
mapping.afterPropertiesSet();
|
||||
assertThat(mapping.getHandler(new MockHttpServletRequest("GET", "/a")),
|
||||
nullValue());
|
||||
assertThat(mapping.getHandler(new MockHttpServletRequest("POST", "/a")),
|
||||
nullValue());
|
||||
}
|
||||
|
||||
private static class TestEndpoint extends AbstractEndpoint<Object> {
|
||||
|
||||
public TestEndpoint(String path) {
|
||||
|
|
Loading…
Reference in New Issue