Browse Source

Avoid defensive check for Servlet 3.1 Part interface

Issue: SPR-14467
pull/1253/head
Juergen Hoeller 8 years ago
parent
commit
1039fa1d34
  1. 12
      spring-web/src/main/java/org/springframework/web/method/annotation/AbstractNamedValueMethodArgumentResolver.java
  2. 11
      spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolver.java

12
spring-web/src/main/java/org/springframework/web/method/annotation/AbstractNamedValueMethodArgumentResolver.java

@ -39,6 +39,7 @@ import org.springframework.web.method.support.ModelAndViewContainer; @@ -39,6 +39,7 @@ import org.springframework.web.method.support.ModelAndViewContainer;
* Abstract base class for resolving method arguments from a named value.
* Request parameters, request headers, and path variables are examples of named
* values. Each may have a name, a required flag, and a default value.
*
* <p>Subclasses define how to do the following:
* <ul>
* <li>Obtain named value information for a method parameter
@ -46,9 +47,11 @@ import org.springframework.web.method.support.ModelAndViewContainer; @@ -46,9 +47,11 @@ import org.springframework.web.method.support.ModelAndViewContainer;
* <li>Handle missing argument values when argument values are required
* <li>Optionally handle a resolved value
* </ul>
*
* <p>A default value string can contain ${...} placeholders and Spring Expression
* Language #{...} expressions. For this to work a
* {@link ConfigurableBeanFactory} must be supplied to the class constructor.
*
* <p>A {@link WebDataBinder} is created to apply type conversion to the resolved
* argument value if it doesn't match the method parameter type.
*
@ -78,7 +81,8 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle @@ -78,7 +81,8 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle
*/
public AbstractNamedValueMethodArgumentResolver(ConfigurableBeanFactory beanFactory) {
this.configurableBeanFactory = beanFactory;
this.expressionContext = (beanFactory != null ? new BeanExpressionContext(beanFactory, new RequestScope()) : null);
this.expressionContext =
(beanFactory != null ? new BeanExpressionContext(beanFactory, new RequestScope()) : null);
}
@ -204,7 +208,9 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle @@ -204,7 +208,9 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle
* @param request the current request
* @since 4.3
*/
protected void handleMissingValue(String name, MethodParameter parameter, NativeWebRequest request) throws Exception {
protected void handleMissingValue(String name, MethodParameter parameter, NativeWebRequest request)
throws Exception {
handleMissingValue(name, parameter);
}
@ -241,7 +247,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle @@ -241,7 +247,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle
* @param arg the resolved argument value
* @param name the argument name
* @param parameter the argument parameter type
* @param mavContainer the {@link ModelAndViewContainer}, which may be {@code null}
* @param mavContainer the {@link ModelAndViewContainer} (may be {@code null})
* @param webRequest the current request
*/
protected void handleResolvedValue(Object arg, String name, MethodParameter parameter,

11
spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolver.java

@ -21,6 +21,7 @@ import java.util.Collection; @@ -21,6 +21,7 @@ import java.util.Collection;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.Part;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
@ -181,7 +182,9 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod @@ -181,7 +182,9 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod
}
@Override
protected void handleMissingValue(String name, MethodParameter parameter, NativeWebRequest request) throws Exception {
protected void handleMissingValue(String name, MethodParameter parameter, NativeWebRequest request)
throws Exception {
HttpServletRequest servletRequest = request.getNativeRequest(HttpServletRequest.class);
if (MultipartResolutionDelegate.isMultipartArgument(parameter)) {
if (!MultipartResolutionDelegate.isMultipartRequest(servletRequest)) {
@ -192,7 +195,8 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod @@ -192,7 +195,8 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod
}
}
else {
throw new MissingServletRequestParameterException(name, parameter.getNestedParameterType().getSimpleName());
throw new MissingServletRequestParameterException(name,
parameter.getNestedParameterType().getSimpleName());
}
}
@ -201,8 +205,7 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod @@ -201,8 +205,7 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod
UriComponentsBuilder builder, Map<String, Object> uriVariables, ConversionService conversionService) {
Class<?> paramType = parameter.getNestedParameterType();
if (Map.class.isAssignableFrom(paramType) || MultipartFile.class == paramType ||
"javax.servlet.http.Part".equals(paramType.getName())) {
if (Map.class.isAssignableFrom(paramType) || MultipartFile.class == paramType || Part.class == paramType) {
return;
}

Loading…
Cancel
Save