SPR-9079 Don't check for "POST" multipart request method arg resolvers
This commit is contained in:
parent
3d1fa4f6b6
commit
64a69f7cf8
|
|
@ -30,6 +30,7 @@ Changes in version 3.1.1 (2012-02-06)
|
|||
* add property to RedirectView to disable expanding URI variables in redirect URL
|
||||
* fix request mapping bug involving direct vs pattern path matches with HTTP methods
|
||||
* revise the FlashMapManager contract and implemenation to address a flaw in its design
|
||||
* Remove check for HTTP "POST" when resolving multipart request controller method arguments
|
||||
|
||||
Changes in version 3.1 GA (2011-12-12)
|
||||
--------------------------------------
|
||||
|
|
|
|||
|
|
@ -110,9 +110,7 @@ public class RequestPartMethodArgumentResolver extends AbstractMessageConverterM
|
|||
NativeWebRequest request, WebDataBinderFactory binderFactory) throws Exception {
|
||||
|
||||
HttpServletRequest servletRequest = request.getNativeRequest(HttpServletRequest.class);
|
||||
if (!isMultipartRequest(servletRequest)) {
|
||||
throw new MultipartException("The current request is not a multipart request");
|
||||
}
|
||||
assertIsMultipartRequest(servletRequest);
|
||||
|
||||
MultipartHttpServletRequest multipartRequest =
|
||||
WebUtils.getNativeRequest(servletRequest, MultipartHttpServletRequest.class);
|
||||
|
|
@ -166,12 +164,11 @@ public class RequestPartMethodArgumentResolver extends AbstractMessageConverterM
|
|||
return arg;
|
||||
}
|
||||
|
||||
private boolean isMultipartRequest(HttpServletRequest request) {
|
||||
if (!"post".equals(request.getMethod().toLowerCase())) {
|
||||
return false;
|
||||
}
|
||||
private static void assertIsMultipartRequest(HttpServletRequest request) {
|
||||
String contentType = request.getContentType();
|
||||
return (contentType != null && contentType.toLowerCase().startsWith("multipart/"));
|
||||
if (contentType == null || !contentType.toLowerCase().startsWith("multipart/")) {
|
||||
throw new MultipartException("The current request is not a multipart request");
|
||||
}
|
||||
}
|
||||
|
||||
private String getPartName(MethodParameter parameter) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 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.
|
||||
|
|
@ -227,12 +227,22 @@ public class RequestPartMethodArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test(expected=MultipartException.class)
|
||||
public void notMultipartRequest() throws Exception {
|
||||
public void isMultipartRequest() throws Exception {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
resolver.resolveArgument(paramMultipartFile, new ModelAndViewContainer(), new ServletWebRequest(request), null);
|
||||
fail("Expected exception");
|
||||
}
|
||||
|
||||
// SPR-9079
|
||||
|
||||
@Test
|
||||
public void isMultipartRequestPut() throws Exception {
|
||||
this.multipartRequest.setMethod("PUT");
|
||||
Object actual = resolver.resolveArgument(paramMultipartFile, null, webRequest, null);
|
||||
assertNotNull(actual);
|
||||
assertSame(multipartFile1, actual);
|
||||
}
|
||||
|
||||
private void testResolveArgument(SimpleBean argValue, MethodParameter parameter) throws IOException, Exception {
|
||||
MediaType contentType = MediaType.TEXT_PLAIN;
|
||||
|
||||
|
|
|
|||
|
|
@ -179,17 +179,10 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod
|
|||
}
|
||||
|
||||
private void assertIsMultipartRequest(HttpServletRequest request) {
|
||||
if (!isMultipartRequest(request)) {
|
||||
throw new MultipartException("The current request is not a multipart request.");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isMultipartRequest(HttpServletRequest request) {
|
||||
if (!"post".equals(request.getMethod().toLowerCase())) {
|
||||
return false;
|
||||
}
|
||||
String contentType = request.getContentType();
|
||||
return (contentType != null && contentType.toLowerCase().startsWith("multipart/"));
|
||||
if (contentType == null || !contentType.toLowerCase().startsWith("multipart/")) {
|
||||
throw new MultipartException("The current request is not a multipart request");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isMultipartFileCollection(MethodParameter parameter) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 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.
|
||||
|
|
@ -45,7 +45,6 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|||
import org.springframework.web.bind.annotation.RequestPart;
|
||||
import org.springframework.web.context.request.NativeWebRequest;
|
||||
import org.springframework.web.context.request.ServletWebRequest;
|
||||
import org.springframework.web.method.annotation.RequestParamMethodArgumentResolver;
|
||||
import org.springframework.web.multipart.MultipartException;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
|
|
@ -183,11 +182,27 @@ public class RequestParamMethodArgumentResolverTests {
|
|||
}
|
||||
|
||||
@Test(expected = MultipartException.class)
|
||||
public void notMultipartRequest() throws Exception {
|
||||
public void isMultipartRequest() throws Exception {
|
||||
resolver.resolveArgument(paramMultiPartFile, null, webRequest, null);
|
||||
fail("Expected exception: request is not a multipart request");
|
||||
}
|
||||
|
||||
// SPR-9079
|
||||
|
||||
@Test
|
||||
public void isMultipartRequestHttpPut() throws Exception {
|
||||
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
|
||||
MultipartFile expected = new MockMultipartFile("multipartFileList", "Hello World".getBytes());
|
||||
request.addFile(expected);
|
||||
request.setMethod("PUT");
|
||||
webRequest = new ServletWebRequest(request);
|
||||
|
||||
Object actual = resolver.resolveArgument(paramMultipartFileList, null, webRequest, null);
|
||||
|
||||
assertTrue(actual instanceof List);
|
||||
assertEquals(expected, ((List<?>) actual).get(0));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void missingMultipartFile() throws Exception {
|
||||
request.setMethod("POST");
|
||||
|
|
|
|||
Loading…
Reference in New Issue