|
|
|
|
@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
|
|
|
|
|
/* |
|
|
|
|
* Copyright 2002-2015 the original author or authors. |
|
|
|
|
* Copyright 2002-2019 the original author or authors. |
|
|
|
|
* |
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
|
@ -17,6 +17,7 @@
@@ -17,6 +17,7 @@
|
|
|
|
|
package org.springframework.web.servlet.mvc.method.annotation; |
|
|
|
|
|
|
|
|
|
import java.lang.reflect.Method; |
|
|
|
|
import java.lang.reflect.Type; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Arrays; |
|
|
|
|
import java.util.Collections; |
|
|
|
|
@ -29,10 +30,12 @@ import org.junit.BeforeClass;
@@ -29,10 +30,12 @@ import org.junit.BeforeClass;
|
|
|
|
|
import org.junit.Test; |
|
|
|
|
|
|
|
|
|
import org.springframework.core.MethodParameter; |
|
|
|
|
import org.springframework.http.HttpInputMessage; |
|
|
|
|
import org.springframework.http.HttpStatus; |
|
|
|
|
import org.springframework.http.MediaType; |
|
|
|
|
import org.springframework.http.ResponseEntity; |
|
|
|
|
import org.springframework.http.converter.HttpMessageConverter; |
|
|
|
|
import org.springframework.http.converter.StringHttpMessageConverter; |
|
|
|
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; |
|
|
|
|
import org.springframework.http.converter.json.MappingJacksonValue; |
|
|
|
|
import org.springframework.http.server.ServerHttpRequest; |
|
|
|
|
@ -61,6 +64,7 @@ import static org.junit.Assert.assertTrue;
@@ -61,6 +64,7 @@ import static org.junit.Assert.assertTrue;
|
|
|
|
|
* Unit tests for {@link RequestMappingHandlerAdapter}. |
|
|
|
|
* |
|
|
|
|
* @author Rossen Stoyanchev |
|
|
|
|
* @author Sam Brannen |
|
|
|
|
* @see ServletAnnotationControllerHandlerMethodTests |
|
|
|
|
* @see HandlerMethodAnnotationDetectionTests |
|
|
|
|
* @see RequestMappingHandlerAdapterIntegrationTests |
|
|
|
|
@ -382,8 +386,15 @@ public class RequestMappingHandlerAdapterTests {
@@ -382,8 +386,15 @@ public class RequestMappingHandlerAdapterTests {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* This class additionally implements {@link RequestBodyAdvice} solely for the purpose |
|
|
|
|
* of verifying that controller advice implementing both {@link ResponseBodyAdvice} |
|
|
|
|
* and {@link RequestBodyAdvice} does not get registered twice. |
|
|
|
|
* |
|
|
|
|
* @see <a href="https://github.com/spring-projects/spring-framework/pull/22638">gh-22638</a> |
|
|
|
|
*/ |
|
|
|
|
@ControllerAdvice |
|
|
|
|
private static class ResponseCodeSuppressingAdvice extends AbstractMappingJacksonResponseBodyAdvice { |
|
|
|
|
private static class ResponseCodeSuppressingAdvice extends AbstractMappingJacksonResponseBodyAdvice implements RequestBodyAdvice { |
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
|
@Override |
|
|
|
|
@ -398,6 +409,35 @@ public class RequestMappingHandlerAdapterTests {
@@ -398,6 +409,35 @@ public class RequestMappingHandlerAdapterTests {
|
|
|
|
|
map.put("message", bodyContainer.getValue()); |
|
|
|
|
bodyContainer.setValue(map); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean supports(MethodParameter methodParameter, Type targetType, |
|
|
|
|
Class<? extends HttpMessageConverter<?>> converterType) { |
|
|
|
|
|
|
|
|
|
return StringHttpMessageConverter.class.equals(converterType); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter parameter, |
|
|
|
|
Type targetType, Class<? extends HttpMessageConverter<?>> converterType) { |
|
|
|
|
|
|
|
|
|
return inputMessage; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Object afterBodyRead(Object body, HttpInputMessage inputMessage, MethodParameter parameter, |
|
|
|
|
Type targetType, Class<? extends HttpMessageConverter<?>> converterType) { |
|
|
|
|
|
|
|
|
|
return body; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Object handleEmptyBody(Object body, HttpInputMessage inputMessage, MethodParameter parameter, |
|
|
|
|
Type targetType, Class<? extends HttpMessageConverter<?>> converterType) { |
|
|
|
|
|
|
|
|
|
return "default value for empty body"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ControllerAdvice |
|
|
|
|
|