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:
@@ -31,6 +31,8 @@ import org.springframework.web.multipart.MultipartException;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||
import org.springframework.web.multipart.MultipartResolver;
|
||||
import org.springframework.web.util.WebUtils;
|
||||
|
||||
|
||||
/**
|
||||
* {@link ServerHttpRequest} implementation that accesses one part of a multipart
|
||||
@@ -81,8 +83,9 @@ public class RequestPartServletServerHttpRequest extends ServletServerHttpReques
|
||||
}
|
||||
|
||||
private static MultipartHttpServletRequest asMultipartRequest(HttpServletRequest request) {
|
||||
if (request instanceof MultipartHttpServletRequest) {
|
||||
return (MultipartHttpServletRequest) request;
|
||||
MultipartHttpServletRequest unwrapped = WebUtils.getNativeRequest(request, MultipartHttpServletRequest.class);
|
||||
if (unwrapped != null) {
|
||||
return unwrapped;
|
||||
}
|
||||
else if (ClassUtils.hasMethod(HttpServletRequest.class, "getParts")) {
|
||||
// Servlet 3.0 available ..
|
||||
@@ -91,11 +94,13 @@ public class RequestPartServletServerHttpRequest extends ServletServerHttpReques
|
||||
throw new IllegalArgumentException("Expected MultipartHttpServletRequest: is a MultipartResolver configured?");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public HttpHeaders getHeaders() {
|
||||
return this.headers;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public InputStream getBody() throws IOException {
|
||||
if (this.multipartRequest instanceof StandardMultipartHttpServletRequest) {
|
||||
|
||||
Reference in New Issue
Block a user