Package org.apache.commons.fileupload

Examples of org.apache.commons.fileupload.FileUpload


               ? RequestHandler.WS_RS_BUFFER_SIZE_VALUE : Integer.parseInt((String)context.getProperties().get(
                  RequestHandler.WS_RS_BUFFER_SIZE));
         File repo = new File((String)context.getProperties().get(RequestHandler.WS_RS_TMP_DIR));

         DefaultFileItemFactory factory = new DefaultFileItemFactory(bufferSize, repo);
         FileUpload upload = new FileUpload(factory);
         return upload.parseRequest(httpRequest).iterator();
      }
      catch (FileUploadException e)
      {
         throw new IOException("Can't process multipart data item " + e);
      }
View Full Code Here


  }
  //Process the HTTP Put request
  public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
     try {
       Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
       FileUpload upload = new FileUpload();
       List files = upload.parseRequest(request,-1,-1,getTempDir());

       String destDir = request.getParameter("target.dir");
       if (destDir==null) {
          destDir = getTempDir();
       }
View Full Code Here

   * @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 (FileUploadException ex) {
      throw new MultipartException("Could not parse multipart servlet request", ex);
    }
  }
View Full Code Here

    final MediaType contentType = outputMessage.getHeaders().getContentType();
    assertNotNull("No boundary found", contentType.getParameter("boundary"));

    // see if Commons FileUpload can read what we wrote
    FileItemFactory fileItemFactory = new DiskFileItemFactory();
    FileUpload fileUpload = new FileUpload(fileItemFactory);
    List<FileItem> items = fileUpload.parseRequest(new MockHttpOutputMessageRequestContext(outputMessage));
    assertEquals(6, items.size());
    FileItem item = items.get(0);
    assertTrue(item.isFormField());
    assertEquals("name 1", item.getFieldName());
    assertEquals("value 1", item.getString());
View Full Code Here

   * @throws MultipartException if multipart resolution failed.
   */
  @SuppressWarnings("unchecked")
  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 (FileUploadException ex) {
      throw new MultipartException("Could not parse multipart servlet request", ex);
    }
  }
View Full Code Here

   * with the same configuration other than the desired encoding.
   * @param encoding the character encoding to use
   * @return an appropriate FileUpload instance.
   */
  protected FileUpload prepareFileUpload(String encoding) {
    FileUpload fileUpload = getFileUpload();
    FileUpload actualFileUpload = fileUpload;

    // Use new temporary FileUpload instance if the request specifies
    // its own encoding that does not match the default encoding.
    if (encoding != null && !encoding.equals(fileUpload.getHeaderEncoding())) {
      actualFileUpload = newFileUpload(getFileItemFactory());
      actualFileUpload.setSizeMax(fileUpload.getSizeMax());
      actualFileUpload.setHeaderEncoding(encoding);
    }

    return actualFileUpload;
  }
View Full Code Here

               ? RequestHandler.WS_RS_BUFFER_SIZE_VALUE : Integer.parseInt(context.getProperties().get(
                  RequestHandler.WS_RS_BUFFER_SIZE));
         File repo = new File(context.getProperties().get(RequestHandler.WS_RS_TMP_DIR));

         DefaultFileItemFactory factory = new DefaultFileItemFactory(bufferSize, repo);
         final FileUpload upload = new FileUpload(factory);

         return SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<Iterator<FileItem>>()
         {
            public Iterator<FileItem> run() throws Exception
            {
               return upload.parseRequest(httpRequest).iterator();
            }
         });
      }
      catch (PrivilegedActionException pae)
      {
View Full Code Here

   * @throws MultipartException if multipart resolution failed.
   */
  @SuppressWarnings("unchecked")
  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 (FileUploadException ex) {
      throw new MultipartException("Could not parse multipart servlet request", ex);
    }
  }
View Full Code Here

   * with the same configuration other than the desired encoding.
   * @param encoding the character encoding to use
   * @return an appropriate FileUpload instance.
   */
  protected FileUpload prepareFileUpload(String encoding) {
    FileUpload fileUpload = getFileUpload();
    FileUpload actualFileUpload = fileUpload;

    // Use new temporary FileUpload instance if the request specifies
    // its own encoding that does not match the default encoding.
    if (encoding != null && !encoding.equals(fileUpload.getHeaderEncoding())) {
      actualFileUpload = newFileUpload(getFileItemFactory());
      actualFileUpload.setSizeMax(fileUpload.getSizeMax());
      actualFileUpload.setHeaderEncoding(encoding);
    }

    return actualFileUpload;
  }
View Full Code Here

        // parse data in memory
        final List<FileItem> items;

        try {
            final FileUpload upload = new FileUpload(DISK_FILE_ITEM_FACTORY);
            items = upload.parseRequest(request);
        } catch (final FileUploadException e) {
            throw new IOException("FileUploadException " + e.getMessage());
        }

        // format information for further usage
View Full Code Here

TOP

Related Classes of org.apache.commons.fileupload.FileUpload

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.