Search in sources :

Example 11 with HandlerMethod

use of org.springframework.web.method.HandlerMethod in project spring-framework by spring-projects.

the class PrintingResultHandler method printHandler.

/**
	 * Print the handler.
	 */
protected void printHandler(Object handler, HandlerInterceptor[] interceptors) throws Exception {
    if (handler == null) {
        this.printer.printValue("Type", null);
    } else {
        if (handler instanceof HandlerMethod) {
            HandlerMethod handlerMethod = (HandlerMethod) handler;
            this.printer.printValue("Type", handlerMethod.getBeanType().getName());
            this.printer.printValue("Method", handlerMethod);
        } else {
            this.printer.printValue("Type", handler.getClass().getName());
        }
    }
}
Also used : HandlerMethod(org.springframework.web.method.HandlerMethod)

Example 12 with HandlerMethod

use of org.springframework.web.method.HandlerMethod in project spring-boot by spring-projects.

the class MvcEndpointSecurityInterceptorTests method setup.

@Before
public void setup() throws Exception {
    this.roles = Arrays.asList("SUPER_HERO");
    this.securityInterceptor = new MvcEndpointSecurityInterceptor(true, this.roles);
    this.endpoint = new TestEndpoint("a");
    this.mvcEndpoint = new TestMvcEndpoint(this.endpoint);
    this.handlerMethod = new HandlerMethod(this.mvcEndpoint, "invoke");
    this.servletContext = new MockServletContext();
    this.request = new MockHttpServletRequest(this.servletContext);
    this.response = mock(HttpServletResponse.class);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) HandlerMethod(org.springframework.web.method.HandlerMethod) MockServletContext(org.springframework.mock.web.MockServletContext) Before(org.junit.Before)

Example 13 with HandlerMethod

use of org.springframework.web.method.HandlerMethod in project spring-boot by spring-projects.

the class NoSpringSecurityMvcEndpointSecurityInterceptorTests method setup.

@Before
public void setup() throws Exception {
    this.roles = Arrays.asList("SUPER_HERO");
    this.securityInterceptor = new MvcEndpointSecurityInterceptor(true, this.roles);
    this.endpoint = new TestEndpoint("a");
    this.mvcEndpoint = new TestMvcEndpoint(this.endpoint);
    this.handlerMethod = new HandlerMethod(this.mvcEndpoint, "invoke");
    this.servletContext = new MockServletContext();
    this.request = new MockHttpServletRequest(this.servletContext);
    this.response = mock(HttpServletResponse.class);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) HandlerMethod(org.springframework.web.method.HandlerMethod) MockServletContext(org.springframework.mock.web.MockServletContext) Before(org.junit.Before)

Example 14 with HandlerMethod

use of org.springframework.web.method.HandlerMethod in project spring-boot by spring-projects.

the class EndpointHandlerMappingTests method withoutPrefix.

@Test
public void withoutPrefix() throws Exception {
    TestMvcEndpoint endpointA = new TestMvcEndpoint(new TestEndpoint("a"));
    TestMvcEndpoint endpointB = new TestMvcEndpoint(new TestEndpoint("b"));
    EndpointHandlerMapping mapping = new EndpointHandlerMapping(Arrays.asList(endpointA, endpointB));
    mapping.setApplicationContext(this.context);
    mapping.afterPropertiesSet();
    assertThat(mapping.getHandler(request("GET", "/a")).getHandler()).isEqualTo(new HandlerMethod(endpointA, this.method));
    assertThat(mapping.getHandler(request("GET", "/b")).getHandler()).isEqualTo(new HandlerMethod(endpointB, this.method));
    assertThat(mapping.getHandler(request("GET", "/c"))).isNull();
}
Also used : HandlerMethod(org.springframework.web.method.HandlerMethod) Test(org.junit.Test)

Example 15 with HandlerMethod

use of org.springframework.web.method.HandlerMethod in project spring-boot by spring-projects.

the class CloudFoundryEndpointHandlerMappingTests method registersCloudFoundryHealthEndpoint.

@Test
public void registersCloudFoundryHealthEndpoint() throws Exception {
    StaticApplicationContext context = new StaticApplicationContext();
    HealthEndpoint delegate = new HealthEndpoint(new OrderedHealthAggregator(), Collections.<String, HealthIndicator>emptyMap());
    CloudFoundryEndpointHandlerMapping handlerMapping = new CloudFoundryEndpointHandlerMapping(Collections.singleton(new TestHealthMvcEndpoint(delegate)), null, null);
    handlerMapping.setPrefix("/test");
    handlerMapping.setApplicationContext(context);
    handlerMapping.afterPropertiesSet();
    HandlerExecutionChain handler = handlerMapping.getHandler(new MockHttpServletRequest("GET", "/test/health"));
    HandlerMethod handlerMethod = (HandlerMethod) handler.getHandler();
    Object handlerMethodBean = handlerMethod.getBean();
    assertThat(handlerMethodBean).isInstanceOf(CloudFoundryHealthMvcEndpoint.class);
}
Also used : HealthEndpoint(org.springframework.boot.actuate.endpoint.HealthEndpoint) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) HandlerExecutionChain(org.springframework.web.servlet.HandlerExecutionChain) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) OrderedHealthAggregator(org.springframework.boot.actuate.health.OrderedHealthAggregator) HandlerMethod(org.springframework.web.method.HandlerMethod) Test(org.junit.Test)

Aggregations

HandlerMethod (org.springframework.web.method.HandlerMethod)235 Test (org.junit.jupiter.api.Test)87 Method (java.lang.reflect.Method)68 ModelAndView (org.springframework.web.servlet.ModelAndView)44 InvocableHandlerMethod (org.springframework.web.method.support.InvocableHandlerMethod)42 ArrayList (java.util.ArrayList)28 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)26 MethodParameter (org.springframework.core.MethodParameter)25 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)25 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)24 Test (org.junit.Test)19 ByteArrayHttpMessageConverter (org.springframework.http.converter.ByteArrayHttpMessageConverter)19 ResourceHttpMessageConverter (org.springframework.http.converter.ResourceHttpMessageConverter)17 AllEncompassingFormHttpMessageConverter (org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter)17 MappingJackson2XmlHttpMessageConverter (org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter)17 IOException (java.io.IOException)14 RequestMethod (org.springframework.web.bind.annotation.RequestMethod)14 MockHttpServletRequest (org.springframework.web.testfixture.servlet.MockHttpServletRequest)14 Map (java.util.Map)13 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)12