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

The following examples show how to use org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor. 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: ColaConfiguration.java    From bdf3 with 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 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 #3
Source File: ProxyExchange.java    From spring-cloud-gateway with 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
Source File: JsonViewSupportFactoryBean.java    From json-view with GNU General Public License v3.0 5 votes vote down vote up
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 File: ResponseBodyWrapFactoryBean.java    From EasyReport 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) {
            //用自己的ResponseBody包装类替换掉框架的
            //达到返回Result的效果
            ResponseBodyWrapHandler decorator = new ResponseBodyWrapHandler(handler, basePackage);
            int index = handlers.indexOf(handler);
            handlers.set(index, decorator);
            break;
        }
    }
}
 
Example #6
Source File: OpenApiWebMvcConfigurer.java    From spring-backend-boilerplate with Apache License 2.0 4 votes vote down vote up
@Override
public void addReturnValueHandlers(final List<HandlerMethodReturnValueHandler> returnValueHandlers) {
    List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
    messageConverters.add(new MappingJackson2HttpMessageConverter());
    returnValueHandlers.add(new RequestResponseBodyMethodProcessor(messageConverters));
}
 
Example #7
Source File: OpenApiWebMvcConfigurer.java    From spring-backend-boilerplate with Apache License 2.0 4 votes vote down vote up
@Override
public void addReturnValueHandlers(final List<HandlerMethodReturnValueHandler> returnValueHandlers) {
    List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
    messageConverters.add(new MappingJackson2HttpMessageConverter());
    returnValueHandlers.add(new RequestResponseBodyMethodProcessor(messageConverters));
}
 
Example #8
Source File: MultiModelAndViewReturnValueHandler.java    From xiaoyaoji with GNU General Public License v3.0 4 votes vote down vote up
@PostConstruct
public void init(){
    List<HttpMessageConverter<?>> converters = new ArrayList<>();
    converters.add(jsonMessageConverter);
    processor = new RequestResponseBodyMethodProcessor(converters);
}
 
Example #9
Source File: UifRequestMappingHandlerAdapter.java    From rice with Educational Community License v2.0 4 votes vote down vote up
/**
 * 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;
}