Add /mappings endpoint
Lists AbstractUrlMappings and AbstractHandlerMethodMappings
in a loose Map structure. E.g.
{
"/**/favicon.ico": {
"bean": "faviconHandlerMapping"
},
"/**": {
"bean": "resourceHandlerMapping"
},
"/webjars/**": {
"bean": "resourceHandlerMapping"
},
"{[/error],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}":
{
"bean": "requestMappingHandlerMapping",
"method": "public java.util.Map<java.lang.String, java.lang.Object> org.springframework.boot.actuate.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)"
...
}
Fixes gh-378
This commit is contained in:
@@ -28,6 +28,7 @@ import org.springframework.boot.actuate.endpoint.EnvironmentEndpoint;
|
||||
import org.springframework.boot.actuate.endpoint.HealthEndpoint;
|
||||
import org.springframework.boot.actuate.endpoint.InfoEndpoint;
|
||||
import org.springframework.boot.actuate.endpoint.MetricsEndpoint;
|
||||
import org.springframework.boot.actuate.endpoint.RequestMappingEndpoint;
|
||||
import org.springframework.boot.actuate.endpoint.ShutdownEndpoint;
|
||||
import org.springframework.boot.actuate.endpoint.TraceEndpoint;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport;
|
||||
@@ -75,6 +76,7 @@ public class EndpointAutoConfigurationTests {
|
||||
assertNotNull(this.context.getBean(MetricsEndpoint.class));
|
||||
assertNotNull(this.context.getBean(ShutdownEndpoint.class));
|
||||
assertNotNull(this.context.getBean(TraceEndpoint.class));
|
||||
assertNotNull(this.context.getBean(RequestMappingEndpoint.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright 2012-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.endpoint;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping;
|
||||
import org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter;
|
||||
import org.springframework.context.support.StaticApplicationContext;
|
||||
import org.springframework.web.servlet.handler.AbstractHandlerMethodMapping;
|
||||
import org.springframework.web.servlet.handler.AbstractUrlHandlerMapping;
|
||||
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class RequestMappingEndpointTests {
|
||||
|
||||
private RequestMappingEndpoint endpoint = new RequestMappingEndpoint();
|
||||
|
||||
@Test
|
||||
public void concreteUrlMappings() {
|
||||
SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping();
|
||||
mapping.setUrlMap(Collections.singletonMap("/foo", new Object()));
|
||||
mapping.setApplicationContext(new StaticApplicationContext());
|
||||
mapping.initApplicationContext();
|
||||
this.endpoint.setHandlerMappings(Collections
|
||||
.<AbstractUrlHandlerMapping> singletonList(mapping));
|
||||
Map<String, Object> result = this.endpoint.invoke();
|
||||
assertEquals(1, result.size());
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> map = (Map<String, Object>) result.get("/foo");
|
||||
assertEquals("java.lang.Object", map.get("type"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beanUrlMappings() {
|
||||
StaticApplicationContext context = new StaticApplicationContext();
|
||||
SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping();
|
||||
mapping.setUrlMap(Collections.singletonMap("/foo", new Object()));
|
||||
mapping.setApplicationContext(context);
|
||||
mapping.initApplicationContext();
|
||||
context.getDefaultListableBeanFactory().registerSingleton("mapping", mapping);
|
||||
this.endpoint.setApplicationContext(context);
|
||||
Map<String, Object> result = this.endpoint.invoke();
|
||||
assertEquals(1, result.size());
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> map = (Map<String, Object>) result.get("/foo");
|
||||
assertEquals("mapping", map.get("bean"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beanMethodMappings() {
|
||||
StaticApplicationContext context = new StaticApplicationContext();
|
||||
EndpointHandlerMapping mapping = new EndpointHandlerMapping(
|
||||
Arrays.asList(new EndpointMvcAdapter(new DumpEndpoint())));
|
||||
mapping.setApplicationContext(new StaticApplicationContext());
|
||||
mapping.afterPropertiesSet();
|
||||
context.getDefaultListableBeanFactory().registerSingleton("mapping", mapping);
|
||||
this.endpoint.setApplicationContext(context);
|
||||
Map<String, Object> result = this.endpoint.invoke();
|
||||
assertEquals(1, result.size());
|
||||
assertTrue(result.keySet().iterator().next().contains("/dump"));
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> handler = (Map<String, Object>) result.values().iterator()
|
||||
.next();
|
||||
assertTrue(handler.containsKey("method"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void concreteMethodMappings() {
|
||||
EndpointHandlerMapping mapping = new EndpointHandlerMapping(
|
||||
Arrays.asList(new EndpointMvcAdapter(new DumpEndpoint())));
|
||||
mapping.setApplicationContext(new StaticApplicationContext());
|
||||
mapping.afterPropertiesSet();
|
||||
this.endpoint.setMethodMappings(Collections
|
||||
.<AbstractHandlerMethodMapping<?>> singletonList(mapping));
|
||||
Map<String, Object> result = this.endpoint.invoke();
|
||||
assertEquals(1, result.size());
|
||||
assertTrue(result.keySet().iterator().next().contains("/dump"));
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> handler = (Map<String, Object>) result.values().iterator()
|
||||
.next();
|
||||
assertTrue(handler.containsKey("method"));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user