Search in sources :

Example 1 with InvocableHandlerMethod

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

the class MvcNamespaceTests method setUp.

@Before
public void setUp() throws Exception {
    TestMockServletContext servletContext = new TestMockServletContext();
    appContext = new GenericWebApplicationContext();
    appContext.setServletContext(servletContext);
    LocaleContextHolder.setLocale(Locale.US);
    String attributeName = WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE;
    appContext.getServletContext().setAttribute(attributeName, appContext);
    handler = new TestController();
    Method method = TestController.class.getMethod("testBind", Date.class, Double.class, TestBean.class, BindingResult.class);
    handlerMethod = new InvocableHandlerMethod(handler, method);
}
Also used : InvocableHandlerMethod(org.springframework.web.method.support.InvocableHandlerMethod) InvocableHandlerMethod(org.springframework.web.method.support.InvocableHandlerMethod) HandlerMethod(org.springframework.web.method.HandlerMethod) Method(java.lang.reflect.Method) GenericWebApplicationContext(org.springframework.web.context.support.GenericWebApplicationContext) Before(org.junit.Before)

Example 2 with InvocableHandlerMethod

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

the class RequestMappingInfoHandlerMappingTests method testHttpOptions.

private void testHttpOptions(String requestURI, String allowHeader) throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("OPTIONS", requestURI);
    HandlerMethod handlerMethod = getHandler(request);
    ServletWebRequest webRequest = new ServletWebRequest(request);
    ModelAndViewContainer mavContainer = new ModelAndViewContainer();
    Object result = new InvocableHandlerMethod(handlerMethod).invokeForRequest(webRequest, mavContainer);
    assertNotNull(result);
    assertEquals(HttpHeaders.class, result.getClass());
    assertEquals(allowHeader, ((HttpHeaders) result).getFirst("Allow"));
}
Also used : ModelAndViewContainer(org.springframework.web.method.support.ModelAndViewContainer) InvocableHandlerMethod(org.springframework.web.method.support.InvocableHandlerMethod) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) InvocableHandlerMethod(org.springframework.web.method.support.InvocableHandlerMethod) HandlerMethod(org.springframework.web.method.HandlerMethod)

Example 3 with InvocableHandlerMethod

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

the class InitBinderDataBinderFactoryTests method createFactory.

private WebDataBinderFactory createFactory(String methodName, Class<?>... parameterTypes) throws Exception {
    Object handler = new InitBinderHandler();
    Method method = handler.getClass().getMethod(methodName, parameterTypes);
    InvocableHandlerMethod handlerMethod = new InvocableHandlerMethod(handler, method);
    handlerMethod.setHandlerMethodArgumentResolvers(this.argumentResolvers);
    handlerMethod.setDataBinderFactory(new DefaultDataBinderFactory(null));
    handlerMethod.setParameterNameDiscoverer(new LocalVariableTableParameterNameDiscoverer());
    return new InitBinderDataBinderFactory(Collections.singletonList(handlerMethod), this.bindingInitializer);
}
Also used : LocalVariableTableParameterNameDiscoverer(org.springframework.core.LocalVariableTableParameterNameDiscoverer) InvocableHandlerMethod(org.springframework.web.method.support.InvocableHandlerMethod) InvocableHandlerMethod(org.springframework.web.method.support.InvocableHandlerMethod) Method(java.lang.reflect.Method) DefaultDataBinderFactory(org.springframework.web.bind.support.DefaultDataBinderFactory)

Example 4 with InvocableHandlerMethod

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

the class RequestMappingHandlerAdapter method createModelAttributeMethod.

private InvocableHandlerMethod createModelAttributeMethod(WebDataBinderFactory factory, Object bean, Method method) {
    InvocableHandlerMethod attrMethod = new InvocableHandlerMethod(bean, method);
    if (this.argumentResolvers != null) {
        attrMethod.setHandlerMethodArgumentResolvers(this.argumentResolvers);
    }
    attrMethod.setParameterNameDiscoverer(this.parameterNameDiscoverer);
    attrMethod.setDataBinderFactory(factory);
    return attrMethod;
}
Also used : InvocableHandlerMethod(org.springframework.web.method.support.InvocableHandlerMethod)

Example 5 with InvocableHandlerMethod

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

the class RequestMappingHandlerAdapter method getModelFactory.

private ModelFactory getModelFactory(HandlerMethod handlerMethod, WebDataBinderFactory binderFactory) {
    SessionAttributesHandler sessionAttrHandler = getSessionAttributesHandler(handlerMethod);
    Class<?> handlerType = handlerMethod.getBeanType();
    Set<Method> methods = this.modelAttributeCache.get(handlerType);
    if (methods == null) {
        methods = MethodIntrospector.selectMethods(handlerType, MODEL_ATTRIBUTE_METHODS);
        this.modelAttributeCache.put(handlerType, methods);
    }
    List<InvocableHandlerMethod> attrMethods = new ArrayList<>();
    // Global methods first
    this.modelAttributeAdviceCache.forEach((controllerAdviceBean, methodSet) -> {
        if (controllerAdviceBean.isApplicableToBeanType(handlerType)) {
            Object bean = controllerAdviceBean.resolveBean();
            for (Method method : methodSet) {
                attrMethods.add(createModelAttributeMethod(binderFactory, bean, method));
            }
        }
    });
    for (Method method : methods) {
        Object bean = handlerMethod.getBean();
        attrMethods.add(createModelAttributeMethod(binderFactory, bean, method));
    }
    return new ModelFactory(attrMethods, binderFactory, sessionAttrHandler);
}
Also used : SessionAttributesHandler(org.springframework.web.method.annotation.SessionAttributesHandler) InvocableHandlerMethod(org.springframework.web.method.support.InvocableHandlerMethod) ArrayList(java.util.ArrayList) InvocableHandlerMethod(org.springframework.web.method.support.InvocableHandlerMethod) HandlerMethod(org.springframework.web.method.HandlerMethod) Method(java.lang.reflect.Method) ModelFactory(org.springframework.web.method.annotation.ModelFactory)

Aggregations

InvocableHandlerMethod (org.springframework.web.method.support.InvocableHandlerMethod)12 HandlerMethod (org.springframework.web.method.HandlerMethod)6 Method (java.lang.reflect.Method)5 ArrayList (java.util.ArrayList)3 DefaultDataBinderFactory (org.springframework.web.bind.support.DefaultDataBinderFactory)3 LocalVariableTableParameterNameDiscoverer (org.springframework.core.LocalVariableTableParameterNameDiscoverer)2 ServletWebRequest (org.springframework.web.context.request.ServletWebRequest)2 HandlerMethodArgumentResolverComposite (org.springframework.web.method.support.HandlerMethodArgumentResolverComposite)2 ModelAndViewContainer (org.springframework.web.method.support.ModelAndViewContainer)2 Before (org.junit.Before)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 HttpHeaders (org.springframework.http.HttpHeaders)1 HttpMethod (org.springframework.http.HttpMethod)1 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)1 ModelAttribute (org.springframework.web.bind.annotation.ModelAttribute)1 WebDataBinderFactory (org.springframework.web.bind.support.WebDataBinderFactory)1 GenericWebApplicationContext (org.springframework.web.context.support.GenericWebApplicationContext)1 XmlWebApplicationContext (org.springframework.web.context.support.XmlWebApplicationContext)1 ModelFactory (org.springframework.web.method.annotation.ModelFactory)1 SessionAttributesHandler (org.springframework.web.method.annotation.SessionAttributesHandler)1