DispatcherServlet's checkMultipart detects wrapped MultipartRequest as well
Issue: SPR-12114
This commit is contained in:
parent
439ce4a1a5
commit
786fd927fa
|
@ -1061,7 +1061,7 @@ public class DispatcherServlet extends FrameworkServlet {
|
|||
*/
|
||||
protected HttpServletRequest checkMultipart(HttpServletRequest request) throws MultipartException {
|
||||
if (this.multipartResolver != null && this.multipartResolver.isMultipart(request)) {
|
||||
if (request instanceof MultipartHttpServletRequest) {
|
||||
if (WebUtils.getNativeRequest(request, MultipartHttpServletRequest.class) != null) {
|
||||
logger.debug("Request is already a MultipartHttpServletRequest - if not in a forward, " +
|
||||
"this typically results from an additional MultipartFilter in web.xml");
|
||||
}
|
||||
|
@ -1079,13 +1079,13 @@ public class DispatcherServlet extends FrameworkServlet {
|
|||
|
||||
/**
|
||||
* Clean up any resources used by the given multipart request (if any).
|
||||
* @param servletRequest current HTTP request
|
||||
* @param request current HTTP request
|
||||
* @see MultipartResolver#cleanupMultipart
|
||||
*/
|
||||
protected void cleanupMultipart(HttpServletRequest servletRequest) {
|
||||
MultipartHttpServletRequest req = WebUtils.getNativeRequest(servletRequest, MultipartHttpServletRequest.class);
|
||||
if (req != null) {
|
||||
this.multipartResolver.cleanupMultipart(req);
|
||||
protected void cleanupMultipart(HttpServletRequest request) {
|
||||
MultipartHttpServletRequest multipartRequest = WebUtils.getNativeRequest(request, MultipartHttpServletRequest.class);
|
||||
if (multipartRequest != null) {
|
||||
this.multipartResolver.cleanupMultipart(multipartRequest);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
|
@ -67,6 +67,7 @@ import org.springframework.web.servlet.theme.SessionThemeResolver;
|
|||
import org.springframework.web.servlet.theme.ThemeChangeInterceptor;
|
||||
import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
||||
import org.springframework.web.servlet.view.ResourceBundleViewResolver;
|
||||
import org.springframework.web.util.WebUtils;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
|
@ -401,7 +402,7 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
|||
if (!(wac instanceof ComplexWebApplicationContext)) {
|
||||
throw new ServletException("Incorrect WebApplicationContext");
|
||||
}
|
||||
if (!(request instanceof MultipartHttpServletRequest)) {
|
||||
if (WebUtils.getNativeRequest(request, MultipartHttpServletRequest.class) == null) {
|
||||
throw new ServletException("Not in a MultipartHttpServletRequest");
|
||||
}
|
||||
if (request.getParameter("fail") != null) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
|
@ -23,6 +23,7 @@ import javax.servlet.ServletConfig;
|
|||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletRequestWrapper;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
@ -217,6 +218,22 @@ public class DispatcherServletTests extends TestCase {
|
|||
MultipartHttpServletRequest multipartRequest = multipartResolver.resolveMultipart(request);
|
||||
complexDispatcherServlet.service(multipartRequest, response);
|
||||
multipartResolver.cleanupMultipart(multipartRequest);
|
||||
assertNull(request.getAttribute(SimpleMappingExceptionResolver.DEFAULT_EXCEPTION_ATTRIBUTE));
|
||||
assertNotNull(request.getAttribute("cleanedUp"));
|
||||
}
|
||||
|
||||
public void testExistingMultipartRequestButWrapped() throws Exception {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", "/locale.do;abc=def");
|
||||
request.addPreferredLocale(Locale.CANADA);
|
||||
request.addUserRole("role1");
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
ComplexWebApplicationContext.MockMultipartResolver multipartResolver =
|
||||
(ComplexWebApplicationContext.MockMultipartResolver) complexDispatcherServlet.getWebApplicationContext()
|
||||
.getBean("multipartResolver");
|
||||
MultipartHttpServletRequest multipartRequest = multipartResolver.resolveMultipart(request);
|
||||
complexDispatcherServlet.service(new HttpServletRequestWrapper(multipartRequest), response);
|
||||
multipartResolver.cleanupMultipart(multipartRequest);
|
||||
assertNull(request.getAttribute(SimpleMappingExceptionResolver.DEFAULT_EXCEPTION_ATTRIBUTE));
|
||||
assertNotNull(request.getAttribute("cleanedUp"));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue