Skip to content

DispatcherServet.checkMultipart() does not consider javax.servlet.error.exception that has a MultipartException cause [SPR-15178] #19744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Jan 23, 2017 · 0 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jan 23, 2017

Andy Wilkinson opened SPR-15178 and commented

DispatcherServlet.checkMultipart(HttpServletRequest) attempts to avoid disturbing error rendering. It does so by checking the java.servlet.error.exception request attribute and, if its value is a MultipartException, it skips multipart resolution. As described in the referenced Spring Boot issue, error rendering is still distributed when the error exception was caused by a MultipartException but is not, itself, a MultipartException.

I've tried providing a custom DispatcherServlet that overrides checkMultipart(HttpServletRequest) and searches through all of the causes:

protected HttpServletRequest checkMultipart(HttpServletRequest request) throws MultipartException {
    if (getMultipartResolver() != null && getMultipartResolver().isMultipart(request)) {
        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");
        } else {
            Throwable error = (Throwable)request.getAttribute(WebUtils.ERROR_EXCEPTION_ATTRIBUTE);
            while (error != null) {
                if (error instanceof MultipartException) {
                    logger.debug("Multipart resolution failed for current request before - " +
                            "skipping re-resolution for undisturbed error rendering");
                    return request;
                }
                error = error.getCause();
            }
            return getMultipartResolver().resolveMultipart(request);
        }
    }
    // If not returned before: return original request.
    return request;
}

It resolves the problem described above and doesn't appear to have any adverse side-effects.


Affects: 4.3.5

Reference URL: spring-projects/spring-boot#7936

Issue Links:

1 votes, 2 watchers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants