Search in sources :

Example 1 with MaxUploadSizeExceededException

use of org.springframework.web.multipart.MaxUploadSizeExceededException in project spring-framework by spring-projects.

the class CommonsMultipartResolver method parseRequest.

/**
	 * Parse the given servlet request, resolving its multipart elements.
	 * @param request the request to parse
	 * @return the parsing result
	 * @throws MultipartException if multipart resolution failed.
	 */
protected MultipartParsingResult parseRequest(HttpServletRequest request) throws MultipartException {
    String encoding = determineEncoding(request);
    FileUpload fileUpload = prepareFileUpload(encoding);
    try {
        List<FileItem> fileItems = ((ServletFileUpload) fileUpload).parseRequest(request);
        return parseFileItems(fileItems, encoding);
    } catch (FileUploadBase.SizeLimitExceededException ex) {
        throw new MaxUploadSizeExceededException(fileUpload.getSizeMax(), ex);
    } catch (FileUploadBase.FileSizeLimitExceededException ex) {
        throw new MaxUploadSizeExceededException(fileUpload.getFileSizeMax(), ex);
    } catch (FileUploadException ex) {
        throw new MultipartException("Failed to parse multipart servlet request", ex);
    }
}
Also used : FileItem(org.apache.commons.fileupload.FileItem) MaxUploadSizeExceededException(org.springframework.web.multipart.MaxUploadSizeExceededException) ServletFileUpload(org.apache.commons.fileupload.servlet.ServletFileUpload) FileUploadBase(org.apache.commons.fileupload.FileUploadBase) MultipartException(org.springframework.web.multipart.MultipartException) ServletFileUpload(org.apache.commons.fileupload.servlet.ServletFileUpload) FileUpload(org.apache.commons.fileupload.FileUpload) FileUploadException(org.apache.commons.fileupload.FileUploadException)

Example 2 with MaxUploadSizeExceededException

use of org.springframework.web.multipart.MaxUploadSizeExceededException in project head by mifos.

the class UncaughtExceptionHandler method checkForMaxUploadSizeExceededException.

private ModelAndView checkForMaxUploadSizeExceededException(Exception ex, HttpServletRequest request) {
    if (ex instanceof MaxUploadSizeExceededException) {
        ModelAndView modelAndView = null;
        String viewName = determineViewName(ex, request);
        if (viewName != null) {
            modelAndView = getModelAndView(viewName, ex, request);
        }
        return modelAndView;
    }
    return null;
}
Also used : MaxUploadSizeExceededException(org.springframework.web.multipart.MaxUploadSizeExceededException) ModelAndView(org.springframework.web.servlet.ModelAndView)

Example 3 with MaxUploadSizeExceededException

use of org.springframework.web.multipart.MaxUploadSizeExceededException in project spring-framework by spring-projects.

the class DispatcherServletTests method multipartResolutionFailed.

@Test
public void multipartResolutionFailed() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", "/locale.do;abc=def");
    request.addPreferredLocale(Locale.CANADA);
    request.addUserRole("role1");
    request.setAttribute("fail", Boolean.TRUE);
    MockHttpServletResponse response = new MockHttpServletResponse();
    complexDispatcherServlet.service(request, response);
    assertTrue("forwarded to failed", "failed0.jsp".equals(response.getForwardedUrl()));
    assertEquals(200, response.getStatus());
    assertTrue("correct exception", request.getAttribute(SimpleMappingExceptionResolver.DEFAULT_EXCEPTION_ATTRIBUTE) instanceof MaxUploadSizeExceededException);
}
Also used : MaxUploadSizeExceededException(org.springframework.web.multipart.MaxUploadSizeExceededException) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

MaxUploadSizeExceededException (org.springframework.web.multipart.MaxUploadSizeExceededException)3 FileItem (org.apache.commons.fileupload.FileItem)1 FileUpload (org.apache.commons.fileupload.FileUpload)1 FileUploadBase (org.apache.commons.fileupload.FileUploadBase)1 FileUploadException (org.apache.commons.fileupload.FileUploadException)1 ServletFileUpload (org.apache.commons.fileupload.servlet.ServletFileUpload)1 Test (org.junit.Test)1 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)1 MultipartException (org.springframework.web.multipart.MultipartException)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1