-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Description
steve bread opened SPR-11716 and commented
I have a multipartpart config in the web.xml to limit the max upload size
<servlet>
<!-- some elements excluded for brevity -->
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<multipart-config>
<max-file-size>2097152</max-file-size>
<max-request-size>2097152</max-request-size>
<file-size-threshold>0</file-size-threshold>
</multipart-config>
</servlet>
and a mapping to an error controller
<error-page>
<location>/error</location>
</error-page>
I'm using Tomcat. A file upload greater than the max size results in an exception which the container attempts to forward to the error controller. Following the normal dispatch behavior for the error URL, Spring attempts to create a StandardMultipartHttpServletRequest
again which once again results in a Tomcat exception for max size violation. So the error controller is not reached and instead a Tomcat error page is returned. It would be nice if there were a way to tell Spring to ignore the mutipart content for the error controller and create a regular request.
In Eclipse, I had Spring skip the multipart block in DispatcherServlet.checkMultipart
and got the desired result.
The error controller for reference
@Controller
@RequestMapping("/error")
public class ErrorController {
@RequestMapping(headers = "X-Requested-With=XMLHttpRequest")
public ResponseEntity<String> error(HttpServletRequest request, HttpServletResponse response) {
return new ResponseEntity<String>("An error occurred", HttpStatus.BAD_REQUEST);
}
}
Affects: 3.2.8
Issue Links:
- StandardServletMultipartResolver should support lazy resolution along the lines of CommonsMultipartResolver [SPR-11730] #16352 StandardServletMultipartResolver should support lazy resolution along the lines of CommonsMultipartResolver