org.springframework.web.method.support.HandlerMethodReturnValueHandler Java Examples

The following examples show how to use org.springframework.web.method.support.HandlerMethodReturnValueHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebConfigurer.java    From SpringAll with MIT License 6 votes vote down vote up
@PostConstruct
public void init() {
    // 获取当前 RequestMappingHandlerAdapter 所有的 ArgumentResolver对象
    List<HandlerMethodArgumentResolver> argumentResolvers = requestMappingHandlerAdapter.getArgumentResolvers();
    List<HandlerMethodArgumentResolver> newArgumentResolvers = new ArrayList<>(argumentResolvers.size() + 1);
    // 添加 PropertiesHandlerMethodArgumentResolver 到集合第一个位置
    newArgumentResolvers.add(0, new PropertiesHandlerMethodArgumentResolver());
    // 将原 ArgumentResolver 添加到集合中
    newArgumentResolvers.addAll(argumentResolvers);
    // 重新设置 ArgumentResolver对象集合
    requestMappingHandlerAdapter.setArgumentResolvers(newArgumentResolvers);

    // 获取当前 RequestMappingHandlerAdapter 所有的 returnValueHandlers对象
    List<HandlerMethodReturnValueHandler> returnValueHandlers = requestMappingHandlerAdapter.getReturnValueHandlers();
    List<HandlerMethodReturnValueHandler> newReturnValueHandlers = new ArrayList<>(returnValueHandlers.size() + 1);
    // 添加 PropertiesHandlerMethodReturnValueHandler 到集合第一个位置
    newReturnValueHandlers.add(0, new PropertiesHandlerMethodReturnValueHandler());
    // 将原 returnValueHandlers 添加到集合中
    newReturnValueHandlers.addAll(returnValueHandlers);
    // 重新设置 ReturnValueHandlers对象集合
    requestMappingHandlerAdapter.setReturnValueHandlers(newReturnValueHandlers);
}
 
Example #2
Source File: RaptorHandlerAdapterPostProcessor.java    From raptor with Apache License 2.0 6 votes vote down vote up
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
    if (RequestMappingHandlerAdapter.class.isAssignableFrom(ClassUtils.getUserClass(bean))) {
        RequestMappingHandlerAdapter adapter = (RequestMappingHandlerAdapter) bean;
        List<Object> advices = getRequestResponseBodyAdviceByReflect(adapter);
        RaptorHandlerMethodProcessor raptorHandlerMethodProcessor = new RaptorHandlerMethodProcessor(raptorMessageConverter,advices);

        ArrayList<HandlerMethodArgumentResolver> argumentResolvers = new ArrayList<>(adapter.getArgumentResolvers());
        argumentResolvers.add(0, raptorHandlerMethodProcessor);
        adapter.setArgumentResolvers(argumentResolvers);

        ArrayList<HandlerMethodReturnValueHandler> returnValueHandlers = new ArrayList<>(adapter.getReturnValueHandlers());
        returnValueHandlers.add(0, raptorHandlerMethodProcessor);
        adapter.setReturnValueHandlers(returnValueHandlers);
    }
    return bean;
}
 
Example #3
Source File: RequestMappingHandlerAdapterTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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());
}
 
Example #4
Source File: RequestMappingHandlerAdapterTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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());
}
 
Example #5
Source File: WebMvcConfigurationSupport.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Provide access to the shared return value handlers used by the
 * {@link RequestMappingHandlerAdapter} and the {@link ExceptionHandlerExceptionResolver}.
 * <p>This method cannot be overridden; use {@link #addReturnValueHandlers} instead.
 * @since 4.3
 */
protected final List<HandlerMethodReturnValueHandler> getReturnValueHandlers() {
	if (this.returnValueHandlers == null) {
		this.returnValueHandlers = new ArrayList<>();
		addReturnValueHandlers(this.returnValueHandlers);
	}
	return this.returnValueHandlers;
}
 
Example #6
Source File: SpringMvcPolyfill.java    From Milkomeda with MIT License 5 votes vote down vote up
/**
 * 动态添加消息体响应切面
 * @param returnValueHandlers       响应处理器列表(需要注入 {@link org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#getReturnValueHandlers()})
 * @param handlerExceptionResolver  异常处理解析器(需要注入 {@link org.springframework.web.servlet.HandlerExceptionResolver})
 * @param responseBodyAdvice        ResponseBodyAdvice
 */
public static void addDynamicResponseBodyAdvice(List<HandlerMethodReturnValueHandler> returnValueHandlers, HandlerExceptionResolver handlerExceptionResolver, ResponseBodyAdvice<?> responseBodyAdvice) {
    if (CollectionUtils.isEmpty(returnValueHandlers)) {
        return;
    }
    // 下面这行添加不起作用,由于内部构建已经完成
    // adapter.setResponseBodyAdvice(Collections.singletonList(responseBodyAdvice));
    for (HandlerMethodReturnValueHandler returnValueHandler : returnValueHandlers) {
        // 只有AbstractMessageConverterMethodArgumentResolver继承类型(主要是HttpEntityMethodProcessor、RequestResponseBodyMethodProcessor)有Advice Chain
        if (returnValueHandler instanceof AbstractMessageConverterMethodArgumentResolver) {
            // TODO <mark> 由于使用底层API, 这个advice.responseBodyAdvice属性在未来版本中可能会改
            List<Object> advices = ReflectUtil.invokeFieldPath(returnValueHandler, "advice.responseBodyAdvice");
            if (CollectionUtils.isEmpty(advices)) {
                continue;
            }
            advices.add(responseBodyAdvice);
        }
    }

    // 动态添加到异常处理(因为源码流程中的异常处理是新加载的HandlerExceptionResolver,与正常响应处理不是同个处理集)
    if (handlerExceptionResolver instanceof HandlerExceptionResolverComposite) {
        // SpringMVC默认为注册HandlerExceptionResolverComposite的Bean
        List<HandlerExceptionResolver> exceptionResolvers = ((HandlerExceptionResolverComposite) handlerExceptionResolver).getExceptionResolvers();
        if (CollectionUtils.isEmpty(exceptionResolvers)) {
            return;
        }
        for (HandlerExceptionResolver exceptionResolver : exceptionResolvers) {
            if (exceptionResolver instanceof ExceptionHandlerExceptionResolver) {
                HandlerMethodReturnValueHandlerComposite returnValueHandlerComposite = ((ExceptionHandlerExceptionResolver) exceptionResolver).getReturnValueHandlers();
                if (returnValueHandlerComposite == null) {
                    return;
                }
                SpringMvcPolyfill.addDynamicResponseBodyAdvice(returnValueHandlerComposite.getHandlers(), null, responseBodyAdvice);
            }
        }
    }
}
 
Example #7
Source File: AnnotationDrivenBeanDefinitionParserTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private void testReturnValueHandlers(Object bean) {
	assertNotNull(bean);
	Object value = new DirectFieldAccessor(bean).getPropertyValue("customReturnValueHandlers");
	assertNotNull(value);
	assertTrue(value instanceof List);
	@SuppressWarnings("unchecked")
	List<HandlerMethodReturnValueHandler> handlers = (List<HandlerMethodReturnValueHandler>) value;
	assertEquals(2, handlers.size());
	assertEquals(TestHandlerMethodReturnValueHandler.class, handlers.get(0).getClass());
	assertEquals(TestHandlerMethodReturnValueHandler.class, handlers.get(1).getClass());
	assertNotSame(handlers.get(0), handlers.get(1));
}
 
Example #8
Source File: GuavaLFReturnValueHandlerTest.java    From grpc-java-contrib with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private int indexOfType(final List<HandlerMethodReturnValueHandler> originalHandlers, Class<?> handlerClass) {
    for (int i = 0; i < originalHandlers.size(); i++) {
        final HandlerMethodReturnValueHandler valueHandler = originalHandlers.get(i);
        if (handlerClass.isAssignableFrom(valueHandler.getClass())) {
            return i;
        }
    }
    return -1;
}
 
Example #9
Source File: GuavaLFReturnValueHandler.java    From grpc-java-contrib with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public GuavaLFReturnValueHandler install(RequestMappingHandlerAdapter requestMappingHandlerAdapter) {
    final List<HandlerMethodReturnValueHandler> originalHandlers = new ArrayList<>(
            requestMappingHandlerAdapter.getReturnValueHandlers());

    final int deferredPos = indexOfType(originalHandlers, DeferredResultMethodReturnValueHandler.class);
    // Add our handler directly after the deferred handler.
    originalHandlers.add(deferredPos + 1, this);

    requestMappingHandlerAdapter.setReturnValueHandlers(originalHandlers);

    return this;
}
 
Example #10
Source File: ExceptionHandlerExceptionResolverTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void setReturnValueHandlers() {
	HandlerMethodReturnValueHandler handler = new ModelMethodProcessor();
	this.resolver.setReturnValueHandlers(Collections.singletonList(handler));
	this.resolver.afterPropertiesSet();

	assertMethodProcessorCount(RESOLVER_COUNT, 1);
}
 
Example #11
Source File: RequestMappingHandlerAdapter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Configure the complete list of supported return value types thus
 * overriding handlers that would otherwise be configured by default.
 */
public void setReturnValueHandlers(@Nullable List<HandlerMethodReturnValueHandler> returnValueHandlers) {
	if (returnValueHandlers == null) {
		this.returnValueHandlers = null;
	}
	else {
		this.returnValueHandlers = new HandlerMethodReturnValueHandlerComposite();
		this.returnValueHandlers.addHandlers(returnValueHandlers);
	}
}
 
Example #12
Source File: ExceptionHandlerExceptionResolver.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Configure the complete list of supported return value types thus
 * overriding handlers that would otherwise be configured by default.
 */
public void setReturnValueHandlers(@Nullable List<HandlerMethodReturnValueHandler> returnValueHandlers) {
	if (returnValueHandlers == null) {
		this.returnValueHandlers = null;
	}
	else {
		this.returnValueHandlers = new HandlerMethodReturnValueHandlerComposite();
		this.returnValueHandlers.addHandlers(returnValueHandlers);
	}
}
 
Example #13
Source File: ExceptionHandlerExceptionResolver.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Return the list of return value handlers to use including built-in and
 * custom handlers provided via {@link #setReturnValueHandlers}.
 */
protected 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 HttpEntityMethodProcessor(
			getMessageConverters(), this.contentNegotiationManager, this.responseBodyAdvice));

	// Annotation-based return value types
	handlers.add(new ModelAttributeMethodProcessor(false));
	handlers.add(new RequestResponseBodyMethodProcessor(
			getMessageConverters(), this.contentNegotiationManager, this.responseBodyAdvice));

	// 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
	handlers.add(new ModelAttributeMethodProcessor(true));

	return handlers;
}
 
Example #14
Source File: GuavaLFReturnValueHandler.java    From grpc-java-contrib with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private int indexOfType(final List<HandlerMethodReturnValueHandler> originalHandlers, Class<?> handlerClass) {
    for (int i = 0; i < originalHandlers.size(); i++) {
        final HandlerMethodReturnValueHandler valueHandler = originalHandlers.get(i);
        if (handlerClass.isAssignableFrom(valueHandler.getClass())) {
            return i;
        }
    }
    return -1;
}
 
Example #15
Source File: ExceptionHandlerExceptionResolver.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Configure the complete list of supported return value types thus
 * overriding handlers that would otherwise be configured by default.
 */
public void setReturnValueHandlers(@Nullable List<HandlerMethodReturnValueHandler> returnValueHandlers) {
	if (returnValueHandlers == null) {
		this.returnValueHandlers = null;
	}
	else {
		this.returnValueHandlers = new HandlerMethodReturnValueHandlerComposite();
		this.returnValueHandlers.addHandlers(returnValueHandlers);
	}
}
 
Example #16
Source File: WebMvcConfigurationSupport.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Provide access to the shared return value handlers used by the
 * {@link RequestMappingHandlerAdapter} and the
 * {@link ExceptionHandlerExceptionResolver}. This method cannot be
 * overridden, use {@link #addReturnValueHandlers(List)} instead.
 * @since 4.3
 */
protected final List<HandlerMethodReturnValueHandler> getReturnValueHandlers() {
	if (this.returnValueHandlers == null) {
		this.returnValueHandlers = new ArrayList<HandlerMethodReturnValueHandler>();
		addReturnValueHandlers(this.returnValueHandlers);
	}
	return this.returnValueHandlers;
}
 
Example #17
Source File: RequestMappingHandlerAdapterTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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);
}
 
Example #18
Source File: RequestMappingHandlerAdapter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Configure the complete list of supported return value types thus
 * overriding handlers that would otherwise be configured by default.
 */
public void setReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers) {
	if (returnValueHandlers == null) {
		this.returnValueHandlers = null;
	}
	else {
		this.returnValueHandlers = new HandlerMethodReturnValueHandlerComposite();
		this.returnValueHandlers.addHandlers(returnValueHandlers);
	}
}
 
Example #19
Source File: ResponseConfig.java    From RCT with Apache License 2.0 5 votes vote down vote up
private void decorateHandlers(List<HandlerMethodReturnValueHandler> handlers) {

			for (HandlerMethodReturnValueHandler handler : handlers) {
				if (handler instanceof RequestResponseBodyMethodProcessor) {
					ResponseBodyWrapHandler decorator = new ResponseBodyWrapHandler(handler);
					int index = handlers.indexOf(handler);
					handlers.set(index, decorator);
					break;
				}
			}

		}
 
Example #20
Source File: ExceptionHandlerExceptionResolver.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void afterPropertiesSet() {
	// Do this first, it may add ResponseBodyAdvice beans
	initExceptionHandlerAdviceCache();

	if (this.argumentResolvers == null) {
		List<HandlerMethodArgumentResolver> resolvers = getDefaultArgumentResolvers();
		this.argumentResolvers = new HandlerMethodArgumentResolverComposite().addResolvers(resolvers);
	}
	if (this.returnValueHandlers == null) {
		List<HandlerMethodReturnValueHandler> handlers = getDefaultReturnValueHandlers();
		this.returnValueHandlers = new HandlerMethodReturnValueHandlerComposite().addHandlers(handlers);
	}
}
 
Example #21
Source File: WebMvcConfigurationSupport.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Provide access to the shared return value handlers used by the
 * {@link RequestMappingHandlerAdapter} and the {@link ExceptionHandlerExceptionResolver}.
 * <p>This method cannot be overridden; use {@link #addReturnValueHandlers} instead.
 * @since 4.3
 */
protected final List<HandlerMethodReturnValueHandler> getReturnValueHandlers() {
	if (this.returnValueHandlers == null) {
		this.returnValueHandlers = new ArrayList<>();
		addReturnValueHandlers(this.returnValueHandlers);
	}
	return this.returnValueHandlers;
}
 
Example #22
Source File: ExceptionHandlerExceptionResolverTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void setCustomReturnValueHandlers() {
	HandlerMethodReturnValueHandler handler = new ViewNameMethodReturnValueHandler();
	this.resolver.setCustomReturnValueHandlers(Collections.singletonList(handler));
	this.resolver.afterPropertiesSet();

	assertTrue(this.resolver.getReturnValueHandlers().getHandlers().contains(handler));
	assertMethodProcessorCount(RESOLVER_COUNT, HANDLER_COUNT + 1);
}
 
Example #23
Source File: ExceptionHandlerExceptionResolverTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void setReturnValueHandlers() {
	HandlerMethodReturnValueHandler handler = new ModelMethodProcessor();
	this.resolver.setReturnValueHandlers(Collections.singletonList(handler));
	this.resolver.afterPropertiesSet();

	assertMethodProcessorCount(RESOLVER_COUNT, 1);
}
 
Example #24
Source File: RequestMappingHandlerAdapterTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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);
}
 
Example #25
Source File: RequestMappingHandlerAdapterTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void setReturnValueHandlers() {
	HandlerMethodReturnValueHandler handler = new ModelMethodProcessor();
	this.handlerAdapter.setReturnValueHandlers(Collections.singletonList(handler));
	this.handlerAdapter.afterPropertiesSet();

	assertMethodProcessorCount(RESOLVER_COUNT, INIT_BINDER_RESOLVER_COUNT, 1);
}
 
Example #26
Source File: AnnotationDrivenBeanDefinitionParserTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
private void testReturnValueHandlers(Object bean) {
	assertNotNull(bean);
	Object value = new DirectFieldAccessor(bean).getPropertyValue("customReturnValueHandlers");
	assertNotNull(value);
	assertTrue(value instanceof List);
	@SuppressWarnings("unchecked")
	List<HandlerMethodReturnValueHandler> handlers = (List<HandlerMethodReturnValueHandler>) value;
	assertEquals(2, handlers.size());
	assertEquals(TestHandlerMethodReturnValueHandler.class, handlers.get(0).getClass());
	assertEquals(TestHandlerMethodReturnValueHandler.class, handlers.get(1).getClass());
	assertNotSame(handlers.get(0), handlers.get(1));
}
 
Example #27
Source File: WebapiApplicationRunListener.java    From summerframework with Apache License 2.0 5 votes vote down vote up
/**
 * 反射获取HandlerMethodReturnValueHandler集合
 */
private List<HandlerMethodReturnValueHandler>
    findHandlerMethodReturnValueHandlers(RequestMappingHandlerAdapter requestMappingHandlerAdapter)
        throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    Field returnValueHandlerCompositeField =
        ReflectionUtils.findField(RequestMappingHandlerAdapter.class, "returnValueHandlers");
    returnValueHandlerCompositeField.setAccessible(true);
    Field modifiersField = Field.class.getDeclaredField("modifiers");
    modifiersField.setAccessible(true);
    modifiersField.setInt(returnValueHandlerCompositeField,
        returnValueHandlerCompositeField.getModifiers() & ~Modifier.FINAL);
    HandlerMethodReturnValueHandlerComposite returnValueHandlerComposite =
        (HandlerMethodReturnValueHandlerComposite)ReflectionUtils.getField(returnValueHandlerCompositeField,
            requestMappingHandlerAdapter);
    Field returnValueHandlersField =
        ReflectionUtils.findField(HandlerMethodReturnValueHandlerComposite.class, "returnValueHandlers");
    returnValueHandlersField.setAccessible(true);
    Field returnValueHandlerModifiersField = Field.class.getDeclaredField("modifiers");
    returnValueHandlerModifiersField.setAccessible(true);
    returnValueHandlerModifiersField.setInt(returnValueHandlersField,
        returnValueHandlersField.getModifiers() & ~Modifier.FINAL);
    List<HandlerMethodReturnValueHandler> returnValueHandlers =
        (List<HandlerMethodReturnValueHandler>)ReflectionUtils.getField(returnValueHandlersField,
            returnValueHandlerComposite);
    return returnValueHandlers;

}
 
Example #28
Source File: RxJavaMvcAutoConfiguration.java    From Java-9-Spring-Webflux with Apache License 2.0 5 votes vote down vote up
@Bean
public WebMvcConfigurationSupport rxJavaWebMvcConfiguration() {
    return new WebMvcConfigurationSupport(){
        @Override
        protected void addReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers) {
            super.addReturnValueHandlers(returnValueHandlers);
            returnValueHandlers.addAll(handlers);
        }
    };
}
 
Example #29
Source File: ExceptionHandlerExceptionResolver.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Configure the complete list of supported return value types thus
 * overriding handlers that would otherwise be configured by default.
 */
public void setReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers) {
	if (returnValueHandlers == null) {
		this.returnValueHandlers = null;
	}
	else {
		this.returnValueHandlers = new HandlerMethodReturnValueHandlerComposite();
		this.returnValueHandlers.addHandlers(returnValueHandlers);
	}
}
 
Example #30
Source File: ExceptionHandlerExceptionResolver.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the list of return value handlers to use including built-in and
 * custom handlers provided via {@link #setReturnValueHandlers}.
 */
protected List<HandlerMethodReturnValueHandler> getDefaultReturnValueHandlers() {
	List<HandlerMethodReturnValueHandler> handlers = new ArrayList<HandlerMethodReturnValueHandler>();

	// Single-purpose return value types
	handlers.add(new ModelAndViewMethodReturnValueHandler());
	handlers.add(new ModelMethodProcessor());
	handlers.add(new ViewMethodReturnValueHandler());
	handlers.add(new HttpEntityMethodProcessor(
			getMessageConverters(), this.contentNegotiationManager, this.responseBodyAdvice));

	// Annotation-based return value types
	handlers.add(new ModelAttributeMethodProcessor(false));
	handlers.add(new RequestResponseBodyMethodProcessor(
			getMessageConverters(), this.contentNegotiationManager, this.responseBodyAdvice));

	// 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
	handlers.add(new ModelAttributeMethodProcessor(true));

	return handlers;
}