/** * Initialize the underlying {@code org.apache.commons.fileupload.servlet.ServletFileUpload} * instance. Can be overridden to use a custom subclass, e.g. for testing purposes. * @param fileItemFactory the Commons FileItemFactory to use * @return the new ServletFileUpload instance */ @Override protected FileUpload newFileUpload(FileItemFactory fileItemFactory) { return new ServletFileUpload(fileItemFactory); }
@Override public boolean isMultipart(HttpServletRequest request) { return ServletFileUpload.isMultipartContent(request); }
/** * Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a> * compliant <code>multipart/form-data</code> stream. * * @param request The servlet request to be parsed. * * @return A map of <code>FileItem</code> instances parsed from the request. * * @throws FileUploadException if there are problems reading/parsing * the request or storing files. * * @since 1.3 */ public Map<String, List<FileItem>> parseParameterMap(HttpServletRequest request) throws FileUploadException { return parseParameterMap(new ServletRequestContext(request)); }
@Override public FileItemIterator getFileItemIterator() { long maxFileSize = ninjaProperties.getIntegerWithDefault(NinjaConstant.UPLOADS_MAX_FILE_SIZE, -1); long maxTotalSize = ninjaProperties.getIntegerWithDefault(NinjaConstant.UPLOADS_MAX_TOTAL_SIZE, -1); ServletFileUpload upload = new ServletFileUpload(); upload.setFileSizeMax(maxFileSize); upload.setSizeMax(maxTotalSize); FileItemIterator fileItemIterator = null; try { fileItemIterator = upload.getItemIterator(httpServletRequest); } catch (FileUploadException | IOException e) { logger.error("Error while trying to process mulitpart file upload", e); } return fileItemIterator; }
private List<FileItem> parseUpload(InputStream pStream, int pLength) throws FileUploadException { String contentType = "multipart/form-data; boundary=---1234"; FileUploadBase upload = new ServletFileUpload(); upload.setFileItemFactory(new DiskFileItemFactory()); HttpServletRequest request = new MockHttpServletRequest(pStream, pLength, contentType); List<FileItem> fileItems = upload.parseRequest(new ServletRequestContext(request)); return fileItems; }
/** * Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a> * compliant <code>multipart/form-data</code> stream. * * @param request The servlet request to be parsed. * * @return A list of <code>FileItem</code> instances parsed from the * request, in the order that they were transmitted. * * @throws FileUploadException if there are problems reading/parsing * the request or storing files. */ @Override public List<FileItem> parseRequest(HttpServletRequest request) throws FileUploadException { return parseRequest(new ServletRequestContext(request)); }
public MultipartFormDataParser(HttpServletRequest request) throws ServletException { try { for( FileItem fi : (List<FileItem>)upload.parseRequest(request) ) byName.put(fi.getFieldName(),fi); } catch (FileUploadException e) { throw new ServletException(e); } }
/** * Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a> * compliant <code>multipart/form-data</code> stream. * * @param request The servlet request to be parsed. * * @return An iterator to instances of <code>FileItemStream</code> * parsed from the request, in the order that they were * transmitted. * * @throws FileUploadException if there are problems reading/parsing * the request or storing files. * @throws IOException An I/O error occurred. This may be a network * error while communicating with the client or a problem while * storing the uploaded content. */ public FileItemIterator getItemIterator(HttpServletRequest request) throws FileUploadException, IOException { return super.getItemIterator(new ServletRequestContext(request)); }
/** * Called when the web application is being destroyed. * Calls {@link FileCleaningTracker#exitWhenFinished()}. * * @param sce The servlet context, used for calling * {@link #getFileCleaningTracker(ServletContext)}. */ @Override public void contextDestroyed(ServletContextEvent sce) { getFileCleaningTracker(sce.getServletContext()).exitWhenFinished(); }
/** * Returns a string representation of this object. * * @return a string representation of this object. */ @Override public String toString() { return format("ContentLength=%s, ContentType=%s", Long.valueOf(this.contentLength()), this.getContentType()); }
/** * Called when the web application is initialized. Does * nothing. * * @param sce The servlet context, used for calling * {@link #setFileCleaningTracker(ServletContext, FileCleaningTracker)}. */ @Override public void contextInitialized(ServletContextEvent sce) { setFileCleaningTracker(sce.getServletContext(), new FileCleaningTracker()); }
/** * Initialize the underlying {@code org.apache.commons.fileupload.servlet.ServletFileUpload} * instance. Can be overridden to use a custom subclass, e.g. for testing purposes. * @param fileItemFactory the Commons FileItemFactory to use * @return the new ServletFileUpload instance */ @Override protected FileUpload newFileUpload(FileItemFactory fileItemFactory) { return new ServletFileUpload(fileItemFactory); }
private FileItemIterator parseUpload(int pLength, InputStream pStream) throws FileUploadException, IOException { String contentType = "multipart/form-data; boundary=---1234"; FileUploadBase upload = new ServletFileUpload(); upload.setFileItemFactory(new DiskFileItemFactory()); HttpServletRequest request = new MockHttpServletRequest(pStream, pLength, contentType); return upload.getItemIterator(new ServletRequestContext(request)); }
@Override public boolean isMultipart(HttpServletRequest request) { return ServletFileUpload.isMultipartContent(request); }
/** * 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); } }
/** * Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a> * compliant <code>multipart/form-data</code> stream. * * @param req The servlet request to be parsed. * * @return A list of <code>FileItem</code> instances parsed from the * request, in the order that they were transmitted. * * @throws FileUploadException if there are problems reading/parsing * the request or storing files. * * @deprecated 1.1 Use {@link ServletFileUpload#parseRequest(HttpServletRequest)} instead. */ @Deprecated public List<FileItem> parseRequest(HttpServletRequest req) throws FileUploadException { return parseRequest(new ServletRequestContext(req)); }
/** * Return a list of {@link FileUpload} implementations for parameterized tests. * @return a list of {@link FileUpload} implementations */ public static List<FileUpload> fileUploadImplementations() { return Arrays.asList( new ServletFileUpload(new DiskFileItemFactory()), new PortletFileUpload(new DiskFileItemFactory())); } }
@Override public boolean isMultipart() { return ServletFileUpload.isMultipartContent(httpServletRequest); }
public static List<FileItem> parseUpload(FileUpload upload, byte[] bytes, String contentType) throws FileUploadException { final HttpServletRequest request = new MockHttpServletRequest(bytes, contentType); List<FileItem> fileItems = upload.parseRequest(new ServletRequestContext(request)); return fileItems; }
/** * Utility method that determines whether the request contains multipart * content. * * @param req The servlet request to be evaluated. Must be non-null. * * @return <code>true</code> if the request is multipart; * <code>false</code> otherwise. * * @deprecated 1.1 Use the method on <code>ServletFileUpload</code> instead. */ @Deprecated public static boolean isMultipartContent(HttpServletRequest req) { return ServletFileUpload.isMultipartContent(req); }