org.apache.commons.fileupload.FileUploadBase.SizeLimitExceededException Java Examples
The following examples show how to use
org.apache.commons.fileupload.FileUploadBase.SizeLimitExceededException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FilesApiServiceImpl.java From multiapps-controller with Apache License 2.0 | 5 votes |
private FileItemIterator createFileIterator(HttpServletRequest request) throws IOException, FileUploadException { long maxUploadSize = new Configuration().getMaxUploadSize(); ServletFileUpload upload = getFileUploadServlet(); upload.setSizeMax(maxUploadSize); try { return upload.getItemIterator(request); } catch (SizeLimitExceededException ex) { throw new SLException(MessageFormat.format(Messages.MAX_UPLOAD_SIZE_EXCEEDED, maxUploadSize)); } }
Example #2
Source File: AdminPageJspBeanTest.java From lutece-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void testDoModifyPage( ) throws AccessDeniedException, SizeLimitExceededException, FileUploadException { MockHttpServletRequest request = new MockHttpServletRequest( ); String descriptionMod = _page.getDescription( ) + "_mod"; assertEquals( _randomPageName, _page.getDescription( ) ); Map<String, String [ ]> parameters = new HashMap<>( ); parameters.put( Parameters.PAGE_ID, new String [ ] { Integer.toString( _page.getId( ) ) } ); parameters.put( Parameters.PAGE_DESCRIPTION, new String [ ] { descriptionMod } ); parameters.put( Parameters.PAGE_TEMPLATE_ID, new String [ ] { Integer.toString( _page.getPageTemplateId( ) ) } ); parameters.put( Parameters.META_KEYWORDS, new String [ ] { _page.getMetaKeywords( ) } ); parameters.put( Parameters.META_DESCRIPTION, new String [ ] { _page.getMetaDescription( ) } ); parameters.put( "node_status", new String [ ] { Integer.toString( _page.getNodeStatus( ) ) } ); parameters.put( Parameters.PAGE_NAME, new String [ ] { _page.getName( ) } ); parameters.put( Parameters.PARENT_ID, new String [ ] { Integer.toString( _page.getParentPageId( ) ) } ); parameters.put( SecurityTokenService.PARAMETER_TOKEN, new String [ ] { SecurityTokenService.getInstance( ).getToken( request, "admin/site/admin_page_block_property.html" ) } ); _bean.doModifyPage( new MultipartHttpServletRequest( request, Collections.emptyMap( ), parameters ) ); AdminMessage message = AdminMessageService.getMessage( request ); assertNull( message ); Page page = PageHome.findByPrimaryKey( _page.getId( ) ); assertEquals( descriptionMod, page.getDescription( ) ); }
Example #3
Source File: AdminPageJspBeanTest.java From lutece-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void testDoModifyPagePageDataError( ) throws AccessDeniedException, SizeLimitExceededException, FileUploadException { MockHttpServletRequest request = new MockHttpServletRequest( ); Map<String, String [ ]> parameters = new HashMap<>( ); parameters.put( Parameters.PAGE_ID, new String [ ] { Integer.toString( _page.getId( ) ) } ); parameters.put( Parameters.PAGE_DESCRIPTION, new String [ ] { _page.getDescription( ) } ); parameters.put( Parameters.PAGE_TEMPLATE_ID, new String [ ] { Integer.toString( _page.getPageTemplateId( ) ) } ); parameters.put( Parameters.META_KEYWORDS, new String [ ] { _page.getMetaKeywords( ) } ); parameters.put( Parameters.META_DESCRIPTION, new String [ ] { _page.getMetaDescription( ) } ); parameters.put( "node_status", new String [ ] { Integer.toString( _page.getNodeStatus( ) ) } ); // empty page name parameter parameters.put( Parameters.PAGE_NAME, new String [ ] { "" } ); parameters.put( Parameters.PARENT_ID, new String [ ] { Integer.toString( _page.getParentPageId( ) ) } ); parameters.put( SecurityTokenService.PARAMETER_TOKEN, new String [ ] { SecurityTokenService.getInstance( ).getToken( request, "admin/site/admin_page_block_property.html" ) } ); _bean.doModifyPage( new MultipartHttpServletRequest( request, Collections.emptyMap( ), parameters ) ); AdminMessage message = AdminMessageService.getMessage( request ); assertNotNull( message ); assertEquals( AdminMessage.TYPE_STOP, message.getType( ) ); Page page = PageHome.findByPrimaryKey( _page.getId( ) ); assertEquals( _randomPageName, page.getName( ) ); }
Example #4
Source File: AdminPageJspBeanTest.java From lutece-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void testDoModifyPageInexistentParentPage( ) throws AccessDeniedException, SizeLimitExceededException, FileUploadException { int origParentPageId = _page.getParentPageId( ); MockHttpServletRequest request = new MockHttpServletRequest( ); Map<String, String [ ]> parameters = new HashMap<>( ); parameters.put( Parameters.PAGE_ID, new String [ ] { Integer.toString( _page.getId( ) ) } ); parameters.put( Parameters.PAGE_DESCRIPTION, new String [ ] { _page.getDescription( ) } ); parameters.put( Parameters.PAGE_TEMPLATE_ID, new String [ ] { Integer.toString( _page.getPageTemplateId( ) ) } ); parameters.put( Parameters.META_KEYWORDS, new String [ ] { _page.getMetaKeywords( ) } ); parameters.put( Parameters.META_DESCRIPTION, new String [ ] { _page.getMetaDescription( ) } ); parameters.put( "node_status", new String [ ] { Integer.toString( _page.getNodeStatus( ) ) } ); parameters.put( Parameters.PAGE_NAME, new String [ ] { _page.getName( ) } ); parameters.put( Parameters.PARENT_ID, new String [ ] { "567894535" } ); parameters.put( SecurityTokenService.PARAMETER_TOKEN, new String [ ] { SecurityTokenService.getInstance( ).getToken( request, "admin/site/admin_page_block_property.html" ) } ); _bean.doModifyPage( new MultipartHttpServletRequest( request, Collections.emptyMap( ), parameters ) ); AdminMessage message = AdminMessageService.getMessage( request ); assertNotNull( message ); assertEquals( AdminMessage.TYPE_STOP, message.getType( ) ); Page page = PageHome.findByPrimaryKey( _page.getId( ) ); assertEquals( origParentPageId, page.getParentPageId( ) ); }
Example #5
Source File: AdviceController.java From seezoon-framework-all with Apache License 2.0 | 4 votes |
/** * @throws IOException 测试无法拦截 */ @ResponseBody @ExceptionHandler({MaxUploadSizeExceededException.class,SizeLimitExceededException.class}) public ResponeModel maxUploadSizeExceededExceptionHandler() { return ResponeModel.error("文件超过" + maxUploadSize/1024 + "KB"); }
Example #6
Source File: FilesApiServiceImplTest.java From multiapps-controller with Apache License 2.0 | 4 votes |
@Test public void testUploadMtaFileErrorSizeExceeded() throws Exception { Mockito.when(servletFileUpload.getItemIterator(Mockito.eq(request))) .thenThrow(new SizeLimitExceededException("size limit exceeded", MAX_PERMITTED_SIZE + 1024, MAX_PERMITTED_SIZE)); Assertions.assertThrows(SLException.class, () -> testedClass.uploadFile(request, SPACE_GUID, null)); }
Example #7
Source File: AdminPageJspBeanTest.java From lutece-core with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void testDoModifyPagePictureError( ) throws AccessDeniedException, SizeLimitExceededException, FileUploadException { MockHttpServletRequest request = new MockHttpServletRequest( ); Map<String, String [ ]> parameters = new HashMap<>( ); parameters.put( Parameters.PAGE_ID, new String [ ] { Integer.toString( _page.getId( ) ) } ); parameters.put( Parameters.PAGE_DESCRIPTION, new String [ ] { _page.getDescription( ) } ); parameters.put( Parameters.PAGE_TEMPLATE_ID, new String [ ] { Integer.toString( _page.getPageTemplateId( ) ) } ); parameters.put( Parameters.META_KEYWORDS, new String [ ] { _page.getMetaKeywords( ) } ); parameters.put( Parameters.META_DESCRIPTION, new String [ ] { _page.getMetaDescription( ) } ); parameters.put( "node_status", new String [ ] { Integer.toString( _page.getNodeStatus( ) ) } ); parameters.put( Parameters.PAGE_NAME, new String [ ] { _page.getName( ) } ); parameters.put( Parameters.PARENT_ID, new String [ ] { Integer.toString( _page.getParentPageId( ) ) } ); parameters.put( "update_image", new String [ ] { "update_image" } ); parameters.put( SecurityTokenService.PARAMETER_TOKEN, new String [ ] { SecurityTokenService.getInstance( ).getToken( request, "admin/site/admin_page_block_property.html" ) } ); Map<String, List<FileItem>> fileItems = new HashMap<>( ); List<FileItem> items = new ArrayList<>( ); FileItem fileItem = new DiskFileItemFactory( ).createItem( "image_content", "", true, "" ); items.add( fileItem ); fileItems.put( "image_content", items ); _bean.doModifyPage( new MultipartHttpServletRequest( request, fileItems, parameters ) ); AdminMessage message = AdminMessageService.getMessage( request ); assertNotNull( message ); assertEquals( AdminMessage.TYPE_STOP, message.getType( ) ); Page page = PageHome.findByPrimaryKey( _page.getId( ) ); assertNull( page.getImageContent( ) ); assertNull( page.getMimeType( ) ); }
Example #8
Source File: AdminPageJspBeanTest.java From lutece-core with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void testDoModifyPageInvalidToken( ) throws AccessDeniedException, SizeLimitExceededException, FileUploadException { MockHttpServletRequest request = new MockHttpServletRequest( ); String descriptionMod = _page.getDescription( ) + "_mod"; assertEquals( _randomPageName, _page.getDescription( ) ); Map<String, String [ ]> parameters = new HashMap<>( ); parameters.put( Parameters.PAGE_ID, new String [ ] { Integer.toString( _page.getId( ) ) } ); parameters.put( Parameters.PAGE_DESCRIPTION, new String [ ] { descriptionMod } ); parameters.put( Parameters.PAGE_TEMPLATE_ID, new String [ ] { Integer.toString( _page.getPageTemplateId( ) ) } ); parameters.put( Parameters.META_KEYWORDS, new String [ ] { _page.getMetaKeywords( ) } ); parameters.put( Parameters.META_DESCRIPTION, new String [ ] { _page.getMetaDescription( ) } ); parameters.put( "node_status", new String [ ] { Integer.toString( _page.getNodeStatus( ) ) } ); parameters.put( Parameters.PAGE_NAME, new String [ ] { _page.getName( ) } ); parameters.put( Parameters.PARENT_ID, new String [ ] { Integer.toString( _page.getParentPageId( ) ) } ); parameters.put( SecurityTokenService.PARAMETER_TOKEN, new String [ ] { SecurityTokenService.getInstance( ).getToken( request, "admin/site/admin_page_block_property.html" ) + "b" } ); try { _bean.doModifyPage( new MultipartHttpServletRequest( request, Collections.emptyMap( ), parameters ) ); fail( "Should have thrown" ); } catch( AccessDeniedException e ) { Page page = PageHome.findByPrimaryKey( _page.getId( ) ); assertEquals( _randomPageName, page.getDescription( ) ); } }
Example #9
Source File: AdminPageJspBeanTest.java From lutece-core with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void testDoModifyPageNoToken( ) throws AccessDeniedException, SizeLimitExceededException, FileUploadException { MockHttpServletRequest request = new MockHttpServletRequest( ); String descriptionMod = _page.getDescription( ) + "_mod"; assertEquals( _randomPageName, _page.getDescription( ) ); Map<String, String [ ]> parameters = new HashMap<>( ); parameters.put( Parameters.PAGE_ID, new String [ ] { Integer.toString( _page.getId( ) ) } ); parameters.put( Parameters.PAGE_DESCRIPTION, new String [ ] { descriptionMod } ); parameters.put( Parameters.PAGE_TEMPLATE_ID, new String [ ] { Integer.toString( _page.getPageTemplateId( ) ) } ); parameters.put( Parameters.META_KEYWORDS, new String [ ] { _page.getMetaKeywords( ) } ); parameters.put( Parameters.META_DESCRIPTION, new String [ ] { _page.getMetaDescription( ) } ); parameters.put( "node_status", new String [ ] { Integer.toString( _page.getNodeStatus( ) ) } ); parameters.put( Parameters.PAGE_NAME, new String [ ] { _page.getName( ) } ); parameters.put( Parameters.PARENT_ID, new String [ ] { Integer.toString( _page.getParentPageId( ) ) } ); try { _bean.doModifyPage( new MultipartHttpServletRequest( request, Collections.emptyMap( ), parameters ) ); fail( "Should have thrown" ); } catch( AccessDeniedException e ) { Page page = PageHome.findByPrimaryKey( _page.getId( ) ); assertEquals( _randomPageName, page.getDescription( ) ); } }
Example #10
Source File: AdminPageJspBeanTest.java From lutece-core with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void testDoModifyPageUpdateDateError( ) throws AccessDeniedException, SizeLimitExceededException, FileUploadException { MockHttpServletRequest request = new MockHttpServletRequest( ); Map<String, String [ ]> parameters = new HashMap<>( ); parameters.put( Parameters.PAGE_ID, new String [ ] { Integer.toString( _page.getId( ) ) } ); parameters.put( Parameters.PAGE_DESCRIPTION, new String [ ] { _page.getDescription( ) } ); parameters.put( Parameters.PAGE_TEMPLATE_ID, new String [ ] { Integer.toString( _page.getPageTemplateId( ) ) } ); parameters.put( Parameters.META_KEYWORDS, new String [ ] { _page.getMetaKeywords( ) } ); parameters.put( Parameters.META_DESCRIPTION, new String [ ] { _page.getMetaDescription( ) } ); parameters.put( "node_status", new String [ ] { Integer.toString( _page.getNodeStatus( ) ) } ); parameters.put( Parameters.PAGE_NAME, new String [ ] { _page.getName( ) } ); parameters.put( Parameters.PARENT_ID, new String [ ] { Integer.toString( _page.getParentPageId( ) ) } ); parameters.put( SecurityTokenService.PARAMETER_TOKEN, new String [ ] { SecurityTokenService.getInstance( ).getToken( request, "admin/site/admin_page_block_property.html" ) } ); parameters.put( Parameters.PARAMETER_DISPLAY_UPDATE_DATE, new String [ ] { Boolean.toString( _page.getDisplayDateUpdate( ) ) } ); parameters.put( Parameters.PARAMETER_ENABLE_MANUAL_UPDATE_DATE, new String [ ] { Boolean.toString( _page.getIsManualDateUpdate( ) ) } ); // Missing Update Date value parameters.put( Parameters.PARAMETER_MANUAL_UPDATE_DATE, new String [ ] { "" } ); _bean.doModifyPage( new MultipartHttpServletRequest( request, Collections.emptyMap( ), parameters ) ); AdminMessage message = AdminMessageService.getMessage( request ); assertNotNull( message ); assertEquals( AdminMessage.TYPE_STOP, message.getType( ) ); }
Example #11
Source File: AdminPageJspBeanTest.java From lutece-core with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void testDoCreateChildPage( ) throws AccessDeniedException, SizeLimitExceededException, FileUploadException, IOException { MockHttpServletRequest request = new MockHttpServletRequest( ); Map<String, String [ ]> parameters = new HashMap<>( ); parameters.put( Parameters.PAGE_ID, new String [ ] { Integer.toString( _page.getId( ) ) } ); parameters.put( Parameters.PAGE_DESCRIPTION, new String [ ] { _page.getDescription( ) } ); parameters.put( Parameters.PAGE_TEMPLATE_ID, new String [ ] { Integer.toString( _page.getPageTemplateId( ) ) } ); parameters.put( Parameters.META_KEYWORDS, new String [ ] { _page.getMetaKeywords( ) } ); parameters.put( Parameters.META_DESCRIPTION, new String [ ] { _page.getMetaDescription( ) } ); parameters.put( "node_status", new String [ ] { Integer.toString( _page.getNodeStatus( ) ) } ); parameters.put( Parameters.PAGE_NAME, new String [ ] { _page.getName( ) + "_child" } ); parameters.put( Parameters.PARENT_ID, new String [ ] { Integer.toString( _page.getParentPageId( ) ) } ); parameters.put( Parameters.PARAMETER_DISPLAY_UPDATE_DATE, new String [ ] { Boolean.toString( _page.getDisplayDateUpdate( ) ) } ); parameters.put( Parameters.PARAMETER_ENABLE_MANUAL_UPDATE_DATE, new String [ ] { Boolean.toString( _page.getIsManualDateUpdate( ) ) } ); parameters.put( Parameters.PARAMETER_MANUAL_UPDATE_DATE, new String [ ] { "01/01/2017" } ); parameters.put( SecurityTokenService.PARAMETER_TOKEN, new String [ ] { SecurityTokenService.getInstance( ).getToken( request, "admin/site/admin_page_block_childpage.html" ) } ); Collection<Page> children = PageHome.getChildPages( _page.getId( ) ); assertNotNull( children ); assertTrue( children.isEmpty( ) ); Map<String, List<FileItem>> fileItems = new HashMap<>( ); List<FileItem> listItems = new ArrayList<>( ); FileItem pageImageFile = new DiskFileItemFactory( ).createItem( "image_content", "", false, "" ); pageImageFile.getOutputStream( ).write( new byte [ 1] ); listItems.add( pageImageFile ); fileItems.put( "image_content", listItems ); _bean.doCreateChildPage( new MultipartHttpServletRequest( request, fileItems, parameters ) ); AdminMessage message = AdminMessageService.getMessage( request ); assertNull( message ); children = PageHome.getChildPages( _page.getId( ) ); assertNotNull( children ); assertFalse( children.isEmpty( ) ); assertTrue( children.stream( ).allMatch( page -> page.getParentPageId( ) == _page.getId( ) && page.getName( ).equals( _page.getName( ) + "_child" ) ) ); }
Example #12
Source File: AdminPageJspBeanTest.java From lutece-core with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void testDoCreateChildPageInvalidToken( ) throws AccessDeniedException, SizeLimitExceededException, FileUploadException, IOException { MockHttpServletRequest request = new MockHttpServletRequest( ); Map<String, String [ ]> parameters = new HashMap<>( ); parameters.put( Parameters.PAGE_ID, new String [ ] { Integer.toString( _page.getId( ) ) } ); parameters.put( Parameters.PAGE_DESCRIPTION, new String [ ] { _page.getDescription( ) } ); parameters.put( Parameters.PAGE_TEMPLATE_ID, new String [ ] { Integer.toString( _page.getPageTemplateId( ) ) } ); parameters.put( Parameters.META_KEYWORDS, new String [ ] { _page.getMetaKeywords( ) } ); parameters.put( Parameters.META_DESCRIPTION, new String [ ] { _page.getMetaDescription( ) } ); parameters.put( "node_status", new String [ ] { Integer.toString( _page.getNodeStatus( ) ) } ); parameters.put( Parameters.PAGE_NAME, new String [ ] { _page.getName( ) + "_child" } ); parameters.put( Parameters.PARENT_ID, new String [ ] { Integer.toString( _page.getParentPageId( ) ) } ); parameters.put( SecurityTokenService.PARAMETER_TOKEN, new String [ ] { SecurityTokenService.getInstance( ).getToken( request, "admin/site/admin_page_block_childpage.html" ) + "b" } ); Collection<Page> children = PageHome.getChildPages( _page.getId( ) ); assertNotNull( children ); assertTrue( children.isEmpty( ) ); Map<String, List<FileItem>> fileItems = new HashMap<>( ); List<FileItem> listItems = new ArrayList<>( ); FileItem pageImageFile = new DiskFileItemFactory( ).createItem( "image_content", "", false, "" ); pageImageFile.getOutputStream( ).write( new byte [ 1] ); listItems.add( pageImageFile ); fileItems.put( "image_content", listItems ); try { _bean.doCreateChildPage( new MultipartHttpServletRequest( request, fileItems, parameters ) ); fail( "Should have thrown" ); } catch( AccessDeniedException e ) { children = PageHome.getChildPages( _page.getId( ) ); assertNotNull( children ); assertTrue( children.isEmpty( ) ); } }
Example #13
Source File: AdminPageJspBeanTest.java From lutece-core with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void testDoCreateChildPageNoToken( ) throws AccessDeniedException, SizeLimitExceededException, FileUploadException, IOException { MockHttpServletRequest request = new MockHttpServletRequest( ); Map<String, String [ ]> parameters = new HashMap<>( ); parameters.put( Parameters.PAGE_ID, new String [ ] { Integer.toString( _page.getId( ) ) } ); parameters.put( Parameters.PAGE_DESCRIPTION, new String [ ] { _page.getDescription( ) } ); parameters.put( Parameters.PAGE_TEMPLATE_ID, new String [ ] { Integer.toString( _page.getPageTemplateId( ) ) } ); parameters.put( Parameters.META_KEYWORDS, new String [ ] { _page.getMetaKeywords( ) } ); parameters.put( Parameters.META_DESCRIPTION, new String [ ] { _page.getMetaDescription( ) } ); parameters.put( "node_status", new String [ ] { Integer.toString( _page.getNodeStatus( ) ) } ); parameters.put( Parameters.PAGE_NAME, new String [ ] { _page.getName( ) + "_child" } ); parameters.put( Parameters.PARENT_ID, new String [ ] { Integer.toString( _page.getParentPageId( ) ) } ); Collection<Page> children = PageHome.getChildPages( _page.getId( ) ); assertNotNull( children ); assertTrue( children.isEmpty( ) ); Map<String, List<FileItem>> fileItems = new HashMap<>( ); List<FileItem> listItems = new ArrayList<>( ); FileItem pageImageFile = new DiskFileItemFactory( ).createItem( "image_content", "", false, "" ); pageImageFile.getOutputStream( ).write( new byte [ 1] ); listItems.add( pageImageFile ); fileItems.put( "image_content", listItems ); try { _bean.doCreateChildPage( new MultipartHttpServletRequest( request, fileItems, parameters ) ); fail( "Should have thrown" ); } catch( AccessDeniedException e ) { children = PageHome.getChildPages( _page.getId( ) ); assertNotNull( children ); assertTrue( children.isEmpty( ) ); } }
Example #14
Source File: CommonsUploadMultipartObserver.java From vraptor4 with Apache License 2.0 | 4 votes |
/** * This method is called when the {@link SizeLimitExceededException} was thrown. */ protected void reportSizeLimitExceeded(final SizeLimitExceededException e, Validator validator) { validator.add(new I18nMessage("upload", "file.limit.exceeded", e.getActualSize(), e.getPermittedSize())); logger.warn("The file size limit was exceeded. Actual {} permitted {}", e.getActualSize(), e.getPermittedSize()); }