Search in sources :

Example 56 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 57 with HandlerMethod

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

the class StandaloneMockMvcBuilderTests method placeHoldersInRequestMapping.

// SPR-10825
@Test
public void placeHoldersInRequestMapping() throws Exception {
    TestStandaloneMockMvcBuilder builder = new TestStandaloneMockMvcBuilder(new PlaceholderController());
    builder.addPlaceholderValue("sys.login.ajax", "/foo");
    builder.build();
    RequestMappingHandlerMapping hm = builder.wac.getBean(RequestMappingHandlerMapping.class);
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
    HandlerExecutionChain chain = hm.getHandler(request);
    assertNotNull(chain);
    assertEquals("handleWithPlaceholders", ((HandlerMethod) chain.getHandler()).getMethod().getName());
}
Also used : HandlerExecutionChain(org.springframework.web.servlet.HandlerExecutionChain) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) RequestMappingHandlerMapping(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping) HandlerMethod(org.springframework.web.method.HandlerMethod) Test(org.junit.Test)

Example 58 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 59 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 60 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)

Aggregations

HandlerMethod (org.springframework.web.method.HandlerMethod)131 Test (org.junit.Test)81 Method (java.lang.reflect.Method)42 InvocableHandlerMethod (org.springframework.web.method.support.InvocableHandlerMethod)34 ArrayList (java.util.ArrayList)26 ModelAndView (org.springframework.web.servlet.ModelAndView)24 MethodParameter (org.springframework.core.MethodParameter)20 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)19 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)19 ByteArrayHttpMessageConverter (org.springframework.http.converter.ByteArrayHttpMessageConverter)18 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)18 ResourceHttpMessageConverter (org.springframework.http.converter.ResourceHttpMessageConverter)16 AllEncompassingFormHttpMessageConverter (org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter)16 MappingJackson2XmlHttpMessageConverter (org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter)16 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)13 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)8 HttpMethod (org.springframework.http.HttpMethod)7 ServerWebExchange (org.springframework.web.server.ServerWebExchange)7 Map (java.util.Map)6 List (java.util.List)5