Java Code Examples for org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor

The following examples show how to use org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor. These examples are extracted from open source projects. 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 Project: bdf3   Source File: ColaConfiguration.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void afterPropertiesSet() throws Exception {
	if (adapter != null) {
		Field field = ReflectionUtils.findField(RequestMappingHandlerAdapter.class, "contentNegotiationManager");
		field.setAccessible(true);
		ContentNegotiationManager contentNegotiationManager = (org.springframework.web.accept.ContentNegotiationManager) field.get(adapter);
		field = ReflectionUtils.findField(RequestMappingHandlerAdapter.class, "requestResponseBodyAdvice");
		field.setAccessible(true);
		List<Object> requestResponseBodyAdvice = (List<Object>) field.get(adapter);
		
		List<HandlerMethodReturnValueHandler> handlers = adapter.getReturnValueHandlers();
		List<HandlerMethodReturnValueHandler> result = new ArrayList<HandlerMethodReturnValueHandler>();
		for (HandlerMethodReturnValueHandler handler : handlers) {
			if (handler instanceof RequestResponseBodyMethodProcessor) {
				result.add(new RequestResponseBodyMethodProcessorAdapter(adapter.getMessageConverters(), contentNegotiationManager, requestResponseBodyAdvice));
			} else {
				result.add(handler);
			}
		}
		adapter.setReturnValueHandlers(result);
	}
}
 
Example 2
Source Project: RCT   Source File: ResponseConfig.java    License: 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 3
Source Project: spring-cloud-gateway   Source File: ProxyExchange.java    License: Apache License 2.0 5 votes vote down vote up
public ProxyExchange(RestTemplate rest, NativeWebRequest webRequest,
		ModelAndViewContainer mavContainer, WebDataBinderFactory binderFactory,
		Type type) {
	this.responseType = type;
	this.rest = rest;
	this.webRequest = webRequest;
	this.mavContainer = mavContainer;
	this.binderFactory = binderFactory;
	this.delegate = new RequestResponseBodyMethodProcessor(
			rest.getMessageConverters());
}
 
Example 4
protected void decorateHandlers(List<HandlerMethodReturnValueHandler> handlers) {
  List<HttpMessageConverter<?>> converters = new ArrayList<>(adapter.getMessageConverters());
  converters.add(converter);
  for(HandlerMethodReturnValueHandler handler : handlers) {
    int index = handlers.indexOf(handler);
    if(handler instanceof HttpEntityMethodProcessor) {
      handlers.set(index, new JsonViewHttpEntityMethodProcessor(converters));
    } else if(handler instanceof RequestResponseBodyMethodProcessor) {
      handlers.set(index, new JsonViewReturnValueHandler(converters, defaultView));
      break;
    }
  }
}
 
Example 5
Source Project: EasyReport   Source File: ResponseBodyWrapFactoryBean.java    License: Apache License 2.0 5 votes vote down vote up
private void decorateHandlers(List<HandlerMethodReturnValueHandler> handlers) {
    for (HandlerMethodReturnValueHandler handler : handlers) {
        if (handler instanceof RequestResponseBodyMethodProcessor) {
            //用自己的ResponseBody包装类替换掉框架的
            //达到返回Result的效果
            ResponseBodyWrapHandler decorator = new ResponseBodyWrapHandler(handler, basePackage);
            int index = handlers.indexOf(handler);
            handlers.set(index, decorator);
            break;
        }
    }
}
 
Example 6
@Override
public void addReturnValueHandlers(final List<HandlerMethodReturnValueHandler> returnValueHandlers) {
    List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
    messageConverters.add(new MappingJackson2HttpMessageConverter());
    returnValueHandlers.add(new RequestResponseBodyMethodProcessor(messageConverters));
}
 
Example 7
@Override
public void addReturnValueHandlers(final List<HandlerMethodReturnValueHandler> returnValueHandlers) {
    List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
    messageConverters.add(new MappingJackson2HttpMessageConverter());
    returnValueHandlers.add(new RequestResponseBodyMethodProcessor(messageConverters));
}
 
Example 8
@PostConstruct
public void init(){
    List<HttpMessageConverter<?>> converters = new ArrayList<>();
    converters.add(jsonMessageConverter);
    processor = new RequestResponseBodyMethodProcessor(converters);
}
 
Example 9
/**
 * Return the list of argument resolvers to use including built-in resolvers
 * and custom resolvers provided via {@link #setCustomArgumentResolvers}.
 */
protected List<HandlerMethodArgumentResolver> getUifArgumentResolvers() {
    List<HandlerMethodArgumentResolver> resolvers = new ArrayList<HandlerMethodArgumentResolver>();

    resolvers.add(new UifDefaultFormMethodArgumentResolver());

    // Annotation-based argument resolution
    resolvers.add(new RequestParamMethodArgumentResolver(getBeanFactory(), false));
    resolvers.add(new RequestParamMapMethodArgumentResolver());
    resolvers.add(new PathVariableMethodArgumentResolver());
    resolvers.add(new PathVariableMapMethodArgumentResolver());
    resolvers.add(new MatrixVariableMethodArgumentResolver());
    resolvers.add(new MatrixVariableMapMethodArgumentResolver());
    resolvers.add(new ServletModelAttributeMethodProcessor(false));
    resolvers.add(new RequestResponseBodyMethodProcessor(getMessageConverters()));
    resolvers.add(new RequestPartMethodArgumentResolver(getMessageConverters()));
    resolvers.add(new RequestHeaderMethodArgumentResolver(getBeanFactory()));
    resolvers.add(new RequestHeaderMapMethodArgumentResolver());
    resolvers.add(new ServletCookieValueMethodArgumentResolver(getBeanFactory()));
    resolvers.add(new ExpressionValueMethodArgumentResolver(getBeanFactory()));

    // Type-based argument resolution
    resolvers.add(new ServletRequestMethodArgumentResolver());
    resolvers.add(new ServletResponseMethodArgumentResolver());
    resolvers.add(new HttpEntityMethodProcessor(getMessageConverters()));
    resolvers.add(new RedirectAttributesMethodArgumentResolver());
    resolvers.add(new ModelMethodProcessor());
    resolvers.add(new MapMethodProcessor());
    resolvers.add(new ErrorsMethodArgumentResolver());
    resolvers.add(new SessionStatusMethodArgumentResolver());
    resolvers.add(new UriComponentsBuilderMethodArgumentResolver());

    // Custom arguments
    if (getCustomArgumentResolvers() != null) {
        resolvers.addAll(getCustomArgumentResolvers());
    }

    // Catch-all
    resolvers.add(new RequestParamMethodArgumentResolver(getBeanFactory(), true));
    resolvers.add(new ServletModelAttributeMethodProcessor(true));

    return resolvers;
}