Skip to content

Skip multipart checking so that multipart errors can be handled in an @Controller method using Servlet 3 <error-page> [SPR-11716] #16338

@spring-projects-issues

Description

@spring-projects-issues

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:

Referenced from: commits 5b47816, d3c9a31

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions