Unwrap if necessary for MultipartHttpServletRequest
Before this commit RequestPartServletServerHttpRequest simply did an instanceof check for MultipartHttpServletRequest. That hasn't failed because request wrapping typically happens in filters before the DispatcherServlet calls the MultipartResolver. With Spring MVC Test and the Spring Security integraiton however, this order is reversed since there we prepare the multipart request upfront, i.e. there is no actual parsing. The commit unwraps the request if necessary. Issue: SPR-13317
This commit is contained in:
@@ -19,6 +19,9 @@ package org.springframework.web.multipart.support;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletRequestWrapper;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
@@ -86,6 +89,20 @@ public class RequestPartServletServerHttpRequestTests {
|
||||
assertArrayEquals(bytes, result);
|
||||
}
|
||||
|
||||
// SPR-13317
|
||||
|
||||
@Test
|
||||
public void getBodyWithWrappedRequest() throws Exception {
|
||||
byte[] bytes = "content".getBytes("UTF-8");
|
||||
MultipartFile part = new MockMultipartFile("part", "", "application/json", bytes);
|
||||
this.mockRequest.addFile(part);
|
||||
HttpServletRequest wrapped = new HttpServletRequestWrapper(this.mockRequest);
|
||||
ServerHttpRequest request = new RequestPartServletServerHttpRequest(wrapped, "part");
|
||||
|
||||
byte[] result = FileCopyUtils.copyToByteArray(request.getBody());
|
||||
assertArrayEquals(bytes, result);
|
||||
}
|
||||
|
||||
// SPR-13096
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user