Search in sources :

Example 6 with HandlerMethodArgumentResolver

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

the class RequestMappingHandlerAdapterTests method setInitBinderArgumentResolvers.

@Test
public void setInitBinderArgumentResolvers() throws Exception {
    HandlerMethodArgumentResolver resolver = new ServletRequestMethodArgumentResolver();
    this.handlerAdapter.setInitBinderArgumentResolvers(Collections.singletonList(resolver));
    this.handlerAdapter.afterPropertiesSet();
    assertMethodProcessorCount(RESOLVER_COUNT, 1, HANDLER_COUNT);
}
Also used : HandlerMethodArgumentResolver(org.springframework.web.method.support.HandlerMethodArgumentResolver) Test(org.junit.Test)

Example 7 with HandlerMethodArgumentResolver

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

the class RequestMappingHandlerAdapterTests method setAlwaysUseRedirectAttributes.

@Test
public void setAlwaysUseRedirectAttributes() throws Exception {
    HandlerMethodArgumentResolver redirectAttributesResolver = new RedirectAttributesMethodArgumentResolver();
    HandlerMethodArgumentResolver modelResolver = new ModelMethodProcessor();
    HandlerMethodReturnValueHandler viewHandler = new ViewNameMethodReturnValueHandler();
    this.handlerAdapter.setArgumentResolvers(Arrays.asList(redirectAttributesResolver, modelResolver));
    this.handlerAdapter.setReturnValueHandlers(Collections.singletonList(viewHandler));
    this.handlerAdapter.setIgnoreDefaultModelOnRedirect(true);
    this.handlerAdapter.afterPropertiesSet();
    this.request.setAttribute(DispatcherServlet.OUTPUT_FLASH_MAP_ATTRIBUTE, new FlashMap());
    HandlerMethod handlerMethod = handlerMethod(new RedirectAttributeController(), "handle", Model.class);
    ModelAndView mav = this.handlerAdapter.handle(request, response, handlerMethod);
    assertTrue("Without RedirectAttributes arg, model should be empty", mav.getModel().isEmpty());
}
Also used : HandlerMethodReturnValueHandler(org.springframework.web.method.support.HandlerMethodReturnValueHandler) FlashMap(org.springframework.web.servlet.FlashMap) ModelMethodProcessor(org.springframework.web.method.annotation.ModelMethodProcessor) ModelAndView(org.springframework.web.servlet.ModelAndView) HandlerMethodArgumentResolver(org.springframework.web.method.support.HandlerMethodArgumentResolver) InvocableHandlerMethod(org.springframework.web.method.support.InvocableHandlerMethod) HandlerMethod(org.springframework.web.method.HandlerMethod) Test(org.junit.Test)

Example 8 with HandlerMethodArgumentResolver

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

the class TestPathHelper method testArgumentResolvers.

private void testArgumentResolvers(Object bean) {
    assertNotNull(bean);
    Object value = new DirectFieldAccessor(bean).getPropertyValue("customArgumentResolvers");
    assertNotNull(value);
    assertTrue(value instanceof List);
    @SuppressWarnings("unchecked") List<HandlerMethodArgumentResolver> resolvers = (List<HandlerMethodArgumentResolver>) value;
    assertEquals(3, resolvers.size());
    assertTrue(resolvers.get(0) instanceof ServletWebArgumentResolverAdapter);
    assertTrue(resolvers.get(1) instanceof TestHandlerMethodArgumentResolver);
    assertTrue(resolvers.get(2) instanceof TestHandlerMethodArgumentResolver);
    assertNotSame(resolvers.get(1), resolvers.get(2));
}
Also used : DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) List(java.util.List) ServletWebArgumentResolverAdapter(org.springframework.web.servlet.mvc.method.annotation.ServletWebArgumentResolverAdapter) HandlerMethodArgumentResolver(org.springframework.web.method.support.HandlerMethodArgumentResolver)

Example 9 with HandlerMethodArgumentResolver

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

the class WebMvcConfigurationSupportExtensionTests method requestMappingHandlerAdapter.

@SuppressWarnings("unchecked")
@Test
public void requestMappingHandlerAdapter() throws Exception {
    RequestMappingHandlerAdapter adapter = this.config.requestMappingHandlerAdapter();
    // ConversionService
    String actual = this.config.mvcConversionService().convert(new TestBean(), String.class);
    assertEquals("converted", actual);
    // Message converters
    List<HttpMessageConverter<?>> converters = adapter.getMessageConverters();
    assertEquals(2, converters.size());
    assertEquals(StringHttpMessageConverter.class, converters.get(0).getClass());
    assertEquals(MappingJackson2HttpMessageConverter.class, converters.get(1).getClass());
    ObjectMapper objectMapper = ((MappingJackson2HttpMessageConverter) converters.get(1)).getObjectMapper();
    assertFalse(objectMapper.getDeserializationConfig().isEnabled(DEFAULT_VIEW_INCLUSION));
    assertFalse(objectMapper.getSerializationConfig().isEnabled(DEFAULT_VIEW_INCLUSION));
    assertFalse(objectMapper.getDeserializationConfig().isEnabled(FAIL_ON_UNKNOWN_PROPERTIES));
    DirectFieldAccessor fieldAccessor = new DirectFieldAccessor(adapter);
    // Custom argument resolvers and return value handlers
    List<HandlerMethodArgumentResolver> argResolvers = (List<HandlerMethodArgumentResolver>) fieldAccessor.getPropertyValue("customArgumentResolvers");
    assertEquals(1, argResolvers.size());
    List<HandlerMethodReturnValueHandler> handlers = (List<HandlerMethodReturnValueHandler>) fieldAccessor.getPropertyValue("customReturnValueHandlers");
    assertEquals(1, handlers.size());
    // Async support options
    assertEquals(ConcurrentTaskExecutor.class, fieldAccessor.getPropertyValue("taskExecutor").getClass());
    assertEquals(2500L, fieldAccessor.getPropertyValue("asyncRequestTimeout"));
    CallableProcessingInterceptor[] callableInterceptors = (CallableProcessingInterceptor[]) fieldAccessor.getPropertyValue("callableInterceptors");
    assertEquals(1, callableInterceptors.length);
    DeferredResultProcessingInterceptor[] deferredResultInterceptors = (DeferredResultProcessingInterceptor[]) fieldAccessor.getPropertyValue("deferredResultInterceptors");
    assertEquals(1, deferredResultInterceptors.length);
    assertEquals(false, fieldAccessor.getPropertyValue("ignoreDefaultModelOnRedirect"));
}
Also used : HandlerMethodReturnValueHandler(org.springframework.web.method.support.HandlerMethodReturnValueHandler) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) DeferredResultProcessingInterceptor(org.springframework.web.context.request.async.DeferredResultProcessingInterceptor) HandlerMethodArgumentResolver(org.springframework.web.method.support.HandlerMethodArgumentResolver) TestBean(org.springframework.tests.sample.beans.TestBean) CallableProcessingInterceptor(org.springframework.web.context.request.async.CallableProcessingInterceptor) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) List(java.util.List) RequestMappingHandlerAdapter(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 10 with HandlerMethodArgumentResolver

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

the class ExceptionHandlerExceptionResolverTests method setArgumentResolvers.

@Test
public void setArgumentResolvers() throws Exception {
    HandlerMethodArgumentResolver resolver = new ServletRequestMethodArgumentResolver();
    this.resolver.setArgumentResolvers(Collections.singletonList(resolver));
    this.resolver.afterPropertiesSet();
    assertMethodProcessorCount(1, HANDLER_COUNT);
}
Also used : HandlerMethodArgumentResolver(org.springframework.web.method.support.HandlerMethodArgumentResolver) Test(org.junit.Test)

Aggregations

HandlerMethodArgumentResolver (org.springframework.web.method.support.HandlerMethodArgumentResolver)12 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)4 ModelMethodProcessor (org.springframework.web.method.annotation.ModelMethodProcessor)3 List (java.util.List)2 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)2 ExpressionValueMethodArgumentResolver (org.springframework.web.method.annotation.ExpressionValueMethodArgumentResolver)2 RequestParamMapMethodArgumentResolver (org.springframework.web.method.annotation.RequestParamMapMethodArgumentResolver)2 RequestParamMethodArgumentResolver (org.springframework.web.method.annotation.RequestParamMethodArgumentResolver)2 HandlerMethodReturnValueHandler (org.springframework.web.method.support.HandlerMethodReturnValueHandler)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Before (org.junit.Before)1 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)1 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)1 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)1 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)1 TestBean (org.springframework.tests.sample.beans.TestBean)1 ConfigurableWebBindingInitializer (org.springframework.web.bind.support.ConfigurableWebBindingInitializer)1 ServletWebRequest (org.springframework.web.context.request.ServletWebRequest)1