Package org.apache.commons.fileupload

Examples of org.apache.commons.fileupload.FileUploadException


        //return items;
        return (filenames.length() > 0 ? filenames.substring(0, filenames.length() - 2) : filenames);
    }
    catch (IOException e)
    {
        throw new FileUploadException(e.getMessage(), e);
    }
    }
View Full Code Here


        } else {
            /*
             * For whatever reason we cannot write the
             * file to disk.
             */
            throw new FileUploadException(
                "Cannot write uploaded file to disk!");
        }
   
  }
View Full Code Here

            dumpRequestInfo(request);
        }
       
        setPortletRequestFlag(request);

        FileUploadException uploadException = null;
        if (PortletFileUpload.isMultipartContent(request)) {
            try {
                DiskFileItemFactory dfif = new DiskFileItemFactory();
                if (uploadMaxFileSize != null) {
                    dfif.setSizeThreshold(resolveSize(uploadThresholdSize));
View Full Code Here

                isExtensionValid = true;
                break;
            }
        }
        if (!isExtensionValid) {
            throw new FileUploadException(" Illegal file type." +
                                          " Allowed file extensions are " + allowedExtensionsStr);
        }
    }
View Full Code Here

                    }
                }
            } catch (Exception e) {
                String msg = "File upload failed";
                log.error(msg, e);
                throw new FileUploadException(msg, e);
            }
        }
        return uploadedFile;
    }
View Full Code Here

            out.write(uuids.toString().substring(0, uuids.length() - 1));
            out.flush();
        } catch (Exception e) {
            String msg = "File upload FAILED. File may be non-existent or invalid.";
            log.error(msg, e);
            throw new FileUploadException(msg, e);
        } finally {
            if (out != null) {
                out.close();
            }
        }
View Full Code Here

            throws FileUploadException, IOException {
        String axis2Repo = ServerConfiguration.getInstance().
                getFirstProperty(ServerConfiguration.AXIS2_CONFIG_REPO_LOCATION);
        if (CarbonUtils.isURL(axis2Repo)) {
            String msg = "You are not permitted to upload jars to URL repository";
            throw new FileUploadException(msg);
        }

        String tmpDir = (String) configurationContext.getProperty(ServerConstants.WORK_DIR);
        String uuid = String.valueOf(System.currentTimeMillis() + Math.random());
        tmpDir = tmpDir + File.separator + "artifacts" + File.separator + uuid + File.separator;
        File tmpDirFile = new File(tmpDir);
        if (!tmpDirFile.exists() && !tmpDirFile.mkdirs()) {
            log.warn("Could not create " + tmpDirFile.getAbsolutePath());
        }

        response.setContentType("text/html; charset=utf-8");

        ServletRequestContext servletRequestContext = new ServletRequestContext(request);
        boolean isMultipart =
                ServletFileUpload.isMultipartContent(servletRequestContext);
        if (isMultipart) {
            PrintWriter out = null;
            try {
                out = response.getWriter();
                // Create a new file upload handler
                List items = parseRequest(servletRequestContext);
                // Process the uploaded items
                for (Iterator iter = items.iterator(); iter.hasNext();) {
                    FileItem item = (FileItem) iter.next();
                    if (!item.isFormField()) {
                        String fileName = item.getName();
                        String fileExtension = fileName;
                        fileExtension = fileExtension.toLowerCase();

                        String fileNameOnly = getFileName(fileName);
                        File uploadedFile;

                        String fieldName = item.getFieldName();

                        if (fieldName != null && fieldName.equals("jarResource")) {
                            if (fileExtension.endsWith(".jar")) {
                                File servicesDir =
                                        new File(tmpDir + File.separator + uploadDirName, "lib");
                                if (!servicesDir.exists() && !servicesDir.mkdirs()){
                                    log.warn("Could not create " + servicesDir.getAbsolutePath());
                                }
                                uploadedFile = new File(servicesDir, fileNameOnly);
                                item.write(uploadedFile);
                            }
                        } else {
                            File servicesDir = new File(tmpDir, uploadDirName);
                            if (!servicesDir.exists() && !servicesDir.mkdirs()) {
                                log.warn("Could not create " + servicesDir.getAbsolutePath());
                            }
                            uploadedFile = new File(servicesDir, fileNameOnly);
                            item.write(uploadedFile);
                        }
                    }
                }

                //First lets filter for jar resources
                String repo = configurationContext.getAxisConfiguration().getRepository().getPath();

                //Writing the artifacts to the proper location
                String parent = repo + File.separator + uploadDirName;
                File mainDir = new File(tmpDir + File.separator + uploadDirName);
                File libDir = new File(mainDir, "lib");
                File[] resourceLibFile =
                        FileManipulator.getMatchingFiles(libDir.getAbsolutePath(), null, "jar");


                for (File src : resourceLibFile) {
                    File dst = new File(parent, "lib");
                    String[] files = libDir.list();
                    for (String file : files) {
                        copyFile(src, new File(dst, file));
                    }
                }

                for (String extension : extensions) {
                    File[] mainFiles =
                            FileManipulator.getMatchingFiles(mainDir.getAbsolutePath(), null, extension);
                    for (File mainFile : mainFiles) {
                        File dst = new File(parent);
                        String[] files = mainDir.list();
                        for (String file : files) {
                            File f = new File(dst, file);
                            if (!f.isDirectory()) {
                                copyFile(mainFile, f);
                            }
                        }

                    }
                }
                response.sendRedirect(getContextRoot(request) + "/carbon/service-mgt/index.jsp?message=Files have been uploaded "
                                      + "successfully. This page will be auto refreshed shortly with "
                                      + "the status of the created " + utilityString + " service"); //TODO: why do we redirect to service-mgt ???
                return true;
            } catch (RuntimeException e) {
                throw e;
            } catch (Exception e) {
                String msg = "File upload failed";
                log.error(msg, e);
                throw new FileUploadException(msg, e);
            } finally {
                if (out != null) {
                    out.close();
                }
            }
View Full Code Here

         }
         return items;
     } catch (FileUploadIOException e) {
         throw (FileUploadException) e.getCause();
     } catch (IOException e) {
         throw new FileUploadException(e.getMessage(), e);
     }
  }
View Full Code Here

        if (!(exception instanceof FileUploadException)) {
            return;
        }

        FileUploadException fue = (FileUploadException) exception;

        String key = null;
        Object args[] = null;

        if (fue instanceof SizeLimitExceededException) {
            SizeLimitExceededException se =
                (SizeLimitExceededException) fue;

            key = "post-size-limit-exceeded-error";

            args = new Object[2];
            args[0] = se.getPermittedSize();
            args[1] = se.getActualSize();
            setError(getMessage(key, args));

        } else if (fue instanceof FileSizeLimitExceededException) {
            FileSizeLimitExceededException fse =
                (FileSizeLimitExceededException) fue;

            key = "file-size-limit-exceeded-error";

            // Parse the FileField name from the message
            String msg = fue.getMessage();
            int start = 10;
            int end = msg.indexOf(' ', start);
            String fieldName = fue.getMessage().substring(start, end);

            args = new Object[3];
            args[0] = ClickUtils.toLabel(fieldName);
            args[1] = fse.getPermittedSize();
            args[2] = fse.getActualSize();
View Full Code Here

                }
            } else {
                /*
                 * For whatever reason we cannot write the file to disk.
                 */
                throw new FileUploadException("Cannot write uploaded file to disk!");
            }
        }
    }
View Full Code Here

TOP

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

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.