@Test public void shouldValidateWhenSizeLimitExceededExceptionOccurs() throws Exception { interceptor = new CommonsUploadMultipartInterceptor(request, parameters, config, validator, mockCreator); when(mockUpload.parseRequest(request)).thenThrow(new FileUploadBase.SizeLimitExceededException("", 0L, 0L)); interceptor.intercept(stack, method, instance); verify(validator).add(any(I18nMessage.class)); }
public void intercept(InterceptorStack stack, ResourceMethod method, Object instance) throws InterceptionException { logger.info("Request contains multipart data. Try to parse with commons-upload."); FileItemFactory factory = createFactoryForDiskBasedFileItems(config.getDirectory()); indexes = HashMultiset.create(); ServletFileUpload uploader = fileUploadCreator.create(factory); uploader.setSizeMax(config.getSizeLimit()); try { final List<FileItem> items = uploader.parseRequest(request); logger.debug("Found {} attributes in the multipart form submission. Parsing them.", items.size()); final Multimap<String, String> params = LinkedListMultimap.create(); for (FileItem item : items) { String name = item.getFieldName(); name = fixIndexedParameters(name); if (item.isFormField()) { logger.debug("{} is a field", name); params.put(name, getValue(item)); } else if (isNotEmpty(item)) { logger.debug("{} is a file", name); processFile(item, name); } else { logger.debug("A file field was empty: {}", item.getFieldName()); } } for (String paramName : params.keySet()) { Collection<String> paramValues = params.get(paramName); parameters.setParameter(paramName, paramValues.toArray(new String[paramValues.size()])); } } catch (final SizeLimitExceededException e) { reportSizeLimitExceeded(e); } catch (FileUploadException e) { reportFileUploadException(e); } stack.next(method, instance); }
CommonsUploadMultipartInterceptor implements MultipartInterceptor { public void intercept(InterceptorStack stack, ResourceMethod method, Object instance) throws InterceptionException { logger.info("Request contains multipart data. Try to parse with commons-upload."); FileItemFactory factory = createFactoryForDiskBasedFileItems(config.getDirectory()); indexes = HashMultiset.create(); ServletFileUpload uploader = fileUploadCreator.create(factory); uploader.setSizeMax(config.getSizeLimit()); try { final List<FileItem> items = uploader.parseRequest(request); logger.debug("Found {} attributes in the multipart form submission. Parsing them.", items.size()); final Multimap<String, String> params = LinkedListMultimap.create(); for (FileItem item : items) { String name = item.getFieldName(); name = fixIndexedParameters(name); if (item.isFormField()) { logger.debug("{} is a field", name); params.put(name, getValue(item)); } else if (isNotEmpty(item)) { logger.debug("{} is a file", name); processFile(item, name); } else { logger.debug("A file field was empty: {}", item.getFieldName()); } } for (String paramName : params.keySet()) { Collection<String> paramValues = params.get(paramName); parameters.setParameter(paramName, paramValues.toArray(new String[paramValues.size()])); } } catch (final SizeLimitExceededException e) { reportSizeLimitExceeded(e); } catch (FileUploadException e) { reportFileUploadException(e); } stack.next(method, instance); } }
CommonsUploadMultipartInterceptor implements MultipartInterceptor { public void intercept(InterceptorStack stack, ResourceMethod method, Object instance) throws InterceptionException { logger.info("Request contains multipart data. Try to parse with commons-upload."); FileItemFactory factory = createFactoryForDiskBasedFileItems(config.getDirectory()); indexes = HashMultiset.create(); ServletFileUpload uploader = fileUploadCreator.create(factory); uploader.setSizeMax(config.getSizeLimit()); try { final List<FileItem> items = uploader.parseRequest(request); logger.debug("Found {} attributes in the multipart form submission. Parsing them.", items.size()); final Multimap<String, String> params = LinkedListMultimap.create(); for (FileItem item : items) { String name = item.getFieldName(); name = fixIndexedParameters(name); if (item.isFormField()) { logger.debug("{} is a field", name); params.put(name, getValue(item)); } else if (isNotEmpty(item)) { logger.debug("{} is a file", name); processFile(item, name); } else { logger.debug("A file field was empty: {}", item.getFieldName()); } } for (String paramName : params.keySet()) { Collection<String> paramValues = params.get(paramName); parameters.setParameter(paramName, paramValues.toArray(new String[paramValues.size()])); } } catch (final SizeLimitExceededException e) { reportSizeLimitExceeded(e); } catch (FileUploadException e) { reportFileUploadException(e); } stack.next(method, instance); } CommonsUploadMultipartInterceptor(HttpServletRequest request, MutableRequest parameters, MultipartConfig cfg,
		Validator validator, ServletFileUploadCreator fileUploadCreator); }
CommonsUploadMultipartInterceptor implements MultipartInterceptor { public void intercept(InterceptorStack stack, ResourceMethod method, Object instance) throws InterceptionException { logger.info("Request contains multipart data. Try to parse with commons-upload."); FileItemFactory factory = createFactoryForDiskBasedFileItems(config.getDirectory()); indexes = HashMultiset.create(); ServletFileUpload uploader = fileUploadCreator.create(factory); uploader.setSizeMax(config.getSizeLimit()); try { final List<FileItem> items = uploader.parseRequest(request); logger.debug("Found {} attributes in the multipart form submission. Parsing them.", items.size()); final Multimap<String, String> params = LinkedListMultimap.create(); for (FileItem item : items) { String name = item.getFieldName(); name = fixIndexedParameters(name); if (item.isFormField()) { logger.debug("{} is a field", name); params.put(name, getValue(item)); } else if (isNotEmpty(item)) { logger.debug("{} is a file", name); processFile(item, name); } else { logger.debug("A file field was empty: {}", item.getFieldName()); } } for (String paramName : params.keySet()) { Collection<String> paramValues = params.get(paramName); parameters.setParameter(paramName, paramValues.toArray(new String[paramValues.size()])); } } catch (final SizeLimitExceededException e) { reportSizeLimitExceeded(e); } catch (FileUploadException e) { reportFileUploadException(e); } stack.next(method, instance); } CommonsUploadMultipartInterceptor(HttpServletRequest request, MutableRequest parameters, MultipartConfig cfg,
		Validator validator, ServletFileUploadCreator fileUploadCreator); boolean accepts(ResourceMethod method); void intercept(InterceptorStack stack, ResourceMethod method, Object instance); }
CommonsUploadMultipartInterceptor implements MultipartInterceptor { public void intercept(InterceptorStack stack, ResourceMethod method, Object instance) throws InterceptionException { logger.info("Request contains multipart data. Try to parse with commons-upload."); FileItemFactory factory = createFactoryForDiskBasedFileItems(config.getDirectory()); indexes = HashMultiset.create(); ServletFileUpload uploader = fileUploadCreator.create(factory); uploader.setSizeMax(config.getSizeLimit()); try { final List<FileItem> items = uploader.parseRequest(request); logger.debug("Found {} attributes in the multipart form submission. Parsing them.", items.size()); final Multimap<String, String> params = LinkedListMultimap.create(); for (FileItem item : items) { String name = item.getFieldName(); name = fixIndexedParameters(name); if (item.isFormField()) { logger.debug("{} is a field", name); params.put(name, getValue(item)); } else if (isNotEmpty(item)) { logger.debug("{} is a file", name); processFile(item, name); } else { logger.debug("A file field was empty: {}", item.getFieldName()); } } for (String paramName : params.keySet()) { Collection<String> paramValues = params.get(paramName); parameters.setParameter(paramName, paramValues.toArray(new String[paramValues.size()])); } } catch (final SizeLimitExceededException e) { reportSizeLimitExceeded(e); } catch (FileUploadException e) { reportFileUploadException(e); } stack.next(method, instance); } CommonsUploadMultipartInterceptor(HttpServletRequest request, MutableRequest parameters, MultipartConfig cfg,
		Validator validator, ServletFileUploadCreator fileUploadCreator); boolean accepts(ResourceMethod method); void intercept(InterceptorStack stack, ResourceMethod method, Object instance);  }