Search in sources :

Example 46 with HandlerMethod

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

the class AbstractHandlerMethodMapping method getCorsConfiguration.

@Override
protected CorsConfiguration getCorsConfiguration(Object handler, ServerWebExchange exchange) {
    CorsConfiguration corsConfig = super.getCorsConfiguration(handler, exchange);
    if (handler instanceof HandlerMethod) {
        HandlerMethod handlerMethod = (HandlerMethod) handler;
        if (handlerMethod.equals(PREFLIGHT_AMBIGUOUS_MATCH)) {
            return ALLOW_CORS_CONFIG;
        }
        CorsConfiguration methodConfig = this.mappingRegistry.getCorsConfiguration(handlerMethod);
        corsConfig = (corsConfig != null ? corsConfig.combine(methodConfig) : methodConfig);
    }
    return corsConfig;
}
Also used : CorsConfiguration(org.springframework.web.cors.CorsConfiguration) HandlerMethod(org.springframework.web.method.HandlerMethod)

Example 47 with HandlerMethod

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

the class AbstractHandlerMethodMapping method createHandlerMethod.

/**
	 * Create the HandlerMethod instance.
	 * @param handler either a bean name or an actual handler instance
	 * @param method the target method
	 * @return the created HandlerMethod
	 */
protected HandlerMethod createHandlerMethod(Object handler, Method method) {
    HandlerMethod handlerMethod;
    if (handler instanceof String) {
        String beanName = (String) handler;
        handlerMethod = new HandlerMethod(beanName, getApplicationContext().getAutowireCapableBeanFactory(), method);
    } else {
        handlerMethod = new HandlerMethod(handler, method);
    }
    return handlerMethod;
}
Also used : HandlerMethod(org.springframework.web.method.HandlerMethod)

Example 48 with HandlerMethod

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

the class MessageReaderArgumentResolverTests method parameterizedMethodArgument.

// SPR-9964
@Test
public void parameterizedMethodArgument() throws Exception {
    Method method = AbstractParameterizedController.class.getMethod("handleDto", Identifiable.class);
    HandlerMethod handlerMethod = new HandlerMethod(new ConcreteParameterizedController(), method);
    MethodParameter methodParam = handlerMethod.getMethodParameters()[0];
    SimpleBean simpleBean = resolveValue(methodParam, "{\"name\" : \"Jad\"}");
    assertEquals("Jad", simpleBean.getName());
}
Also used : HandlerMethod(org.springframework.web.method.HandlerMethod) Method(java.lang.reflect.Method) ResolvableMethod(org.springframework.web.method.ResolvableMethod) MethodParameter(org.springframework.core.MethodParameter) HandlerMethod(org.springframework.web.method.HandlerMethod) Test(org.junit.Test)

Example 49 with HandlerMethod

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

the class ControllerAdviceTests method handle.

private HandlerResult handle(RequestMappingHandlerAdapter adapter, Object controller, String methodName) throws Exception {
    Method method = controller.getClass().getMethod(methodName);
    HandlerMethod handlerMethod = new HandlerMethod(controller, method);
    return adapter.handle(this.exchange, handlerMethod).block(Duration.ZERO);
}
Also used : HandlerMethod(org.springframework.web.method.HandlerMethod) Method(java.lang.reflect.Method) HandlerMethod(org.springframework.web.method.HandlerMethod)

Example 50 with HandlerMethod

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

the class RequestMappingInfoHandlerMappingTests method getHandlerEmptyPathMatch.

@Test
public void getHandlerEmptyPathMatch() throws Exception {
    Method expected = on(TestController.class).annot(requestMapping("")).resolveMethod();
    ServerWebExchange exchange = get("").toExchange();
    HandlerMethod hm = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
    assertEquals(expected, hm.getMethod());
    exchange = get("/").toExchange();
    hm = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
    assertEquals(expected, hm.getMethod());
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) HandlerMethod(org.springframework.web.method.HandlerMethod) Method(java.lang.reflect.Method) HttpMethod(org.springframework.http.HttpMethod) 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