Search in sources :

Example 6 with HandlerMethodReturnValueHandler

use of org.springframework.web.method.support.HandlerMethodReturnValueHandler in project chassis by Kixeye.

the class SpringMvcConfiguration method returnValueHandlers.

@Bean
public List<HandlerMethodReturnValueHandler> returnValueHandlers(RequestMappingHandlerAdapter requestMappingHandlerAdapter) {
    final List<HandlerMethodReturnValueHandler> handlers = new ArrayList<>(requestMappingHandlerAdapter.getReturnValueHandlers());
    handlers.add(0, new ObserableReturnValueHandler());
    handlers.add(0, new ListenableFutureReturnValueHandler());
    requestMappingHandlerAdapter.setReturnValueHandlers(handlers);
    return handlers;
}
Also used : HandlerMethodReturnValueHandler(org.springframework.web.method.support.HandlerMethodReturnValueHandler) ObserableReturnValueHandler(com.kixeye.chassis.transport.http.ObserableReturnValueHandler) ArrayList(java.util.ArrayList) ListenableFutureReturnValueHandler(com.kixeye.chassis.transport.http.ListenableFutureReturnValueHandler) Bean(org.springframework.context.annotation.Bean)

Example 7 with HandlerMethodReturnValueHandler

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

the class RequestMappingHandlerAdapter method getDefaultReturnValueHandlers.

/**
	 * Return the list of return value handlers to use including built-in and
	 * custom handlers provided via {@link #setReturnValueHandlers}.
	 */
private List<HandlerMethodReturnValueHandler> getDefaultReturnValueHandlers() {
    List<HandlerMethodReturnValueHandler> handlers = new ArrayList<>();
    // Single-purpose return value types
    handlers.add(new ModelAndViewMethodReturnValueHandler());
    handlers.add(new ModelMethodProcessor());
    handlers.add(new ViewMethodReturnValueHandler());
    handlers.add(new ResponseBodyEmitterReturnValueHandler(getMessageConverters()));
    handlers.add(new StreamingResponseBodyReturnValueHandler());
    handlers.add(new HttpEntityMethodProcessor(getMessageConverters(), this.contentNegotiationManager, this.requestResponseBodyAdvice));
    handlers.add(new HttpHeadersReturnValueHandler());
    handlers.add(new CallableMethodReturnValueHandler());
    handlers.add(new DeferredResultMethodReturnValueHandler());
    handlers.add(new AsyncTaskMethodReturnValueHandler(this.beanFactory));
    // Annotation-based return value types
    handlers.add(new ModelAttributeMethodProcessor(false));
    handlers.add(new RequestResponseBodyMethodProcessor(getMessageConverters(), this.contentNegotiationManager, this.requestResponseBodyAdvice));
    // Multi-purpose return value types
    handlers.add(new ViewNameMethodReturnValueHandler());
    handlers.add(new MapMethodProcessor());
    // Custom return value types
    if (getCustomReturnValueHandlers() != null) {
        handlers.addAll(getCustomReturnValueHandlers());
    }
    // Catch-all
    if (!CollectionUtils.isEmpty(getModelAndViewResolvers())) {
        handlers.add(new ModelAndViewResolverMethodReturnValueHandler(getModelAndViewResolvers()));
    } else {
        handlers.add(new ModelAttributeMethodProcessor(true));
    }
    return handlers;
}
Also used : HandlerMethodReturnValueHandler(org.springframework.web.method.support.HandlerMethodReturnValueHandler) ModelMethodProcessor(org.springframework.web.method.annotation.ModelMethodProcessor) ArrayList(java.util.ArrayList) MapMethodProcessor(org.springframework.web.method.annotation.MapMethodProcessor) ModelAttributeMethodProcessor(org.springframework.web.method.annotation.ModelAttributeMethodProcessor)

Example 8 with HandlerMethodReturnValueHandler

use of org.springframework.web.method.support.HandlerMethodReturnValueHandler 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 9 with HandlerMethodReturnValueHandler

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

the class ExceptionHandlerExceptionResolverTests method setReturnValueHandlers.

@Test
public void setReturnValueHandlers() {
    HandlerMethodReturnValueHandler handler = new ModelMethodProcessor();
    this.resolver.setReturnValueHandlers(Collections.singletonList(handler));
    this.resolver.afterPropertiesSet();
    assertMethodProcessorCount(RESOLVER_COUNT, 1);
}
Also used : HandlerMethodReturnValueHandler(org.springframework.web.method.support.HandlerMethodReturnValueHandler) ModelMethodProcessor(org.springframework.web.method.annotation.ModelMethodProcessor) Test(org.junit.Test)

Example 10 with HandlerMethodReturnValueHandler

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

the class RequestMappingHandlerAdapterTests method setCustomReturnValueHandlers.

@Test
public void setCustomReturnValueHandlers() {
    HandlerMethodReturnValueHandler handler = new ViewNameMethodReturnValueHandler();
    this.handlerAdapter.setCustomReturnValueHandlers(Collections.singletonList(handler));
    this.handlerAdapter.afterPropertiesSet();
    assertTrue(this.handlerAdapter.getReturnValueHandlers().contains(handler));
    assertMethodProcessorCount(RESOLVER_COUNT, INIT_BINDER_RESOLVER_COUNT, HANDLER_COUNT + 1);
}
Also used : HandlerMethodReturnValueHandler(org.springframework.web.method.support.HandlerMethodReturnValueHandler) Test(org.junit.Test)

Aggregations

HandlerMethodReturnValueHandler (org.springframework.web.method.support.HandlerMethodReturnValueHandler)10 Test (org.junit.Test)6 ModelMethodProcessor (org.springframework.web.method.annotation.ModelMethodProcessor)5 ArrayList (java.util.ArrayList)3 List (java.util.List)2 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)2 MapMethodProcessor (org.springframework.web.method.annotation.MapMethodProcessor)2 ModelAttributeMethodProcessor (org.springframework.web.method.annotation.ModelAttributeMethodProcessor)2 HandlerMethodArgumentResolver (org.springframework.web.method.support.HandlerMethodArgumentResolver)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ListenableFutureReturnValueHandler (com.kixeye.chassis.transport.http.ListenableFutureReturnValueHandler)1 ObserableReturnValueHandler (com.kixeye.chassis.transport.http.ObserableReturnValueHandler)1 Bean (org.springframework.context.annotation.Bean)1 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)1 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)1 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)1 TestBean (org.springframework.tests.sample.beans.TestBean)1 CallableProcessingInterceptor (org.springframework.web.context.request.async.CallableProcessingInterceptor)1 DeferredResultProcessingInterceptor (org.springframework.web.context.request.async.DeferredResultProcessingInterceptor)1 HandlerMethod (org.springframework.web.method.HandlerMethod)1