Example usage for org.apache.commons.fileupload.servlet ServletFileUpload setFileItemFactory

List of usage examples for org.apache.commons.fileupload.servlet ServletFileUpload setFileItemFactory

Introduction

In this page you can find the example usage for org.apache.commons.fileupload.servlet ServletFileUpload setFileItemFactory.

Prototype

public void setFileItemFactory(FileItemFactory factory) 

Source Link

Document

Sets the factory class to use when creating file items.

Usage

From source file:com.runwaysdk.web.SecureFileUploadServlet.java

protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    ClientRequestIF clientRequest = (ClientRequestIF) req.getAttribute(ClientConstants.CLIENTREQUEST);

    boolean isMultipart = ServletFileUpload.isMultipartContent(req);

    if (!isMultipart) {
        // TODO Change exception type
        String msg = "The HTTP Request must contain multipart content.";
        throw new RuntimeException(msg);
    }/*from  w w  w . j av a2 s  . co  m*/

    String fileId = req.getParameter("sessionId").toString().trim();
    FileItemFactory factory = new ProgressMonitorFileItemFactory(req, fileId);
    ServletFileUpload upload = new ServletFileUpload();

    upload.setFileItemFactory(factory);

    try {
        // Parse the request

        FileItemIterator iter = upload.getItemIterator(req);
        while (iter.hasNext()) {
            FileItemStream item = iter.next();

            if (!item.isFormField()) {
                String fullName = item.getName();
                int extensionInd = fullName.lastIndexOf(".");
                String fileName = fullName.substring(0, extensionInd);
                String extension = fullName.substring(extensionInd + 1);
                InputStream stream = item.openStream();

                BusinessDTO fileDTO = clientRequest.newSecureFile(fileName, extension, stream);

                // return the vault id to the dhtmlxVault callback
                req.getSession().setAttribute("FileUpload.Progress." + fileId, fileDTO.getId());
            }
        }
    } catch (FileUploadException e) {
        throw new FileWriteExceptionDTO(e.getLocalizedMessage());
    } catch (RuntimeException e) {
        req.getSession().setAttribute("FileUpload.Progress." + fileId, "fail: " + e.getLocalizedMessage());
    }
}

From source file:com.runwaysdk.web.WebFileUploadServlet.java

protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    ClientRequestIF clientRequest = (ClientRequestIF) req.getAttribute(ClientConstants.CLIENTREQUEST);

    // capture the session id
    boolean isMultipart = ServletFileUpload.isMultipartContent(req);

    if (!isMultipart) {
        // TODO Change exception type
        String msg = "The HTTP Request must contain multipart content.";
        throw new RuntimeException(msg);
    }// w ww .j a  v  a2s  . c  o m

    FileItemFactory factory = new DiskFileItemFactory();
    ServletFileUpload upload = new ServletFileUpload();

    upload.setFileItemFactory(factory);

    try {
        // Parse the request
        FileItemIterator iter = upload.getItemIterator(req);

        String fileName = null;
        String extension = null;
        InputStream stream = null;
        String uploadPath = null;
        while (iter.hasNext()) {
            FileItemStream item = iter.next();
            InputStream input = item.openStream();
            if (item.isFormField() && item.getFieldName().equals(WEB_FILE_UPLOAD_PATH_FIELD_NAME)) {
                uploadPath = Streams.asString(input);
            } else if (!item.isFormField()) {
                String fullName = item.getName();
                int extensionInd = fullName.lastIndexOf(".");
                fileName = fullName.substring(0, extensionInd);
                extension = fullName.substring(extensionInd + 1);
                stream = input;
            }
        }

        if (stream != null) {
            clientRequest.newFile(uploadPath, fileName, extension, stream);
        }
    } catch (FileUploadException e) {
        throw new FileWriteExceptionDTO(e.getLocalizedMessage());
    }
}

From source file:com.esri.gpt.control.filter.MultipartWrapper.java

/**
 * Construct with a current HTTP servlet request.
 * @param request the current HTTP servlet request
 * @throws FileUploadException if an exception occurs during file upload
 *///from   w ww. j a  v a 2  s  . co  m
public MultipartWrapper(HttpServletRequest request) throws FileUploadException {
    super(request);
    getLogger().finer("Handling multipart content.");

    // initialize parameters
    _fileParameters = new HashMap<String, FileItem>();
    _formParameters = new HashMap<String, String[]>();
    int nFileSizeMax = 100000000;
    int nSizeThreshold = 500000;
    String sTmpFolder = "";

    // make the file item factory
    DiskFileItemFactory factory = new DiskFileItemFactory();
    factory.setSizeThreshold(nSizeThreshold);
    if (sTmpFolder.length() > 0) {
        File fTmpFolder = new File(sTmpFolder);
        factory.setRepository(fTmpFolder);
    }

    // make the file upload object
    ServletFileUpload fileUpload = new ServletFileUpload();
    fileUpload.setFileItemFactory(factory);
    fileUpload.setFileSizeMax(nFileSizeMax);

    // parse the parameters associated with the request
    List items = fileUpload.parseRequest(request);
    String[] aValues;
    ArrayList<String> lValues;
    for (int i = 0; i < items.size(); i++) {
        FileItem item = (FileItem) items.get(i);
        getLogger().finer("FileItem=" + item);
        if (item.isFormField()) {
            String sName = item.getFieldName();
            String sValue = item.getString();
            if (_formParameters.containsKey(sName)) {
                aValues = _formParameters.get(sName);
                lValues = new ArrayList<String>(Arrays.asList(aValues));
                lValues.add(sValue);
                aValues = lValues.toArray(new String[0]);
            } else {
                aValues = new String[1];
                aValues[0] = sValue;
            }
            _formParameters.put(sName, aValues);
        } else {
            _fileParameters.put(item.getFieldName(), item);
            request.setAttribute(item.getFieldName(), item);
        }
    }
}

From source file:com.wabacus.WabacusFacade.java

public static void uploadFile(HttpServletRequest request, HttpServletResponse response) {
    PrintWriter out = null;//from   w ww . j  a v  a2s  . com
    try {
        out = response.getWriter();
    } catch (IOException e1) {
        throw new WabacusRuntimeException("response?PrintWriter", e1);
    }
    out.println(
            "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
    out.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=" + Config.encode + "\">");
    importWebresources(out);
    if (Config.getInstance().getSystemConfigValue("prompt-dialog-type", "artdialog").equals("artdialog")) {
        out.print("<script type=\"text/javascript\"  src=\"" + Config.webroot
                + "webresources/component/artDialog/artDialog.js\"></script>");
        out.print("<script type=\"text/javascript\"  src=\"" + Config.webroot
                + "webresources/component/artDialog/plugins/iframeTools.js\"></script>");
    }
    /**if(true)
    {
    out.print("<table style=\"margin:0px;\"><tr><td style='font-size:13px;'><font color='#ff0000'>");
    out.print("???WabacusDemo????\n\rWabacusDemo.war?samples/");
    out.print("</font></td></tr></table>");
    return;
    }*/
    DiskFileItemFactory factory = new DiskFileItemFactory();
    factory.setSizeThreshold(4096);
    String repositoryPath = FilePathAssistant.getInstance().standardFilePath(Config.webroot_abspath
            + File.separator + "wxtmpfiles" + File.separator + "upload" + File.separator);
    FilePathAssistant.getInstance().checkAndCreateDirIfNotExist(repositoryPath);
    factory.setRepository(new File(repositoryPath));
    ServletFileUpload fileUploadObj = new ServletFileUpload();
    fileUploadObj.setFileItemFactory(factory);
    fileUploadObj.setHeaderEncoding(Config.encode);
    List lstFieldItems = null;
    String errorinfo = null;
    try {
        lstFieldItems = fileUploadObj.parseRequest(request);
        if (lstFieldItems == null || lstFieldItems.size() == 0) {
            errorinfo = "??";
        }
    } catch (FileUploadException e) {
        log.error("?", e);
        errorinfo = "?";
    }
    Map<String, String> mFormFieldValues = new HashMap<String, String>();
    Iterator itFieldItems = lstFieldItems.iterator();
    FileItem item;
    while (itFieldItems.hasNext()) {//??mFormFieldValues??
        item = (FileItem) itFieldItems.next();
        if (item.isFormField()) {
            try {
                mFormFieldValues.put(item.getFieldName(), item.getString(Config.encode));
                request.setAttribute(item.getFieldName(), item.getString(Config.encode));
            } catch (UnsupportedEncodingException e) {
                log.warn("??????" + Config.encode
                        + "?", e);
            }
        }
    }
    String fileuploadtype = mFormFieldValues.get("FILEUPLOADTYPE");
    AbsFileUpload fileUpload = getFileUploadObj(request, fileuploadtype);
    boolean isPromtAuto = true;
    if (fileUpload == null) {
        errorinfo = "";
    } else if (errorinfo == null || errorinfo.trim().equals("")) {
        fileUpload.setMFormFieldValues(mFormFieldValues);
        errorinfo = fileUpload.doFileUpload(lstFieldItems, out);
        if (fileUpload.getInterceptorObj() != null) {
            isPromtAuto = fileUpload.getInterceptorObj().beforeDisplayFileUploadPrompt(request, lstFieldItems,
                    fileUpload.getMFormFieldValues(), errorinfo, out);
        }
    }
    out.println("<script language='javascript'>");
    out.println("  try{hideLoadingMessage();}catch(e){}");
    out.println("</script>");
    if (isPromtAuto) {
        if (errorinfo == null || errorinfo.trim().equals("")) {
            out.println("<script language='javascript'>");
            fileUpload.promptSuccess(out, Config.getInstance()
                    .getSystemConfigValue("prompt-dialog-type", "artdialog").equals("artdialog"));
            out.println("</script>");
        } else {
            out.println("<table style=\"margin:0px;\"><tr><td style='font-size:13px;'><font color='#ff0000'>"
                    + errorinfo + "</font></td></tr></table>");
        }
    }
    if (errorinfo != null && !errorinfo.trim().equals("")) {
        if (fileUpload != null) {
            request.setAttribute("WX_FILE_UPLOAD_FIELDVALUES", fileUpload.getMFormFieldValues());
        }
        showUploadFilePage(request, out);
    } else if (!isPromtAuto) {//???????????
        out.println("<script language='javascript'>");
        if (Config.getInstance().getSystemConfigValue("prompt-dialog-type", "artdialog").equals("artdialog")) {
            out.println("art.dialog.close();");
        } else {
            out.println("parent.closePopupWin();");
        }
        out.println("</script>");
    }
}

From source file:com.amalto.core.servlet.UploadFile.java

private void uploadFile(HttpServletRequest req, Writer writer) throws ServletException, IOException {
    // upload file
    if (!ServletFileUpload.isMultipartContent(req)) {
        throw new ServletException("Upload File Error: the request is not multipart!"); //$NON-NLS-1$
    }//  w  w w . j a  v a2  s. com
    // Create a new file upload handler
    ServletFileUpload upload = new ServletFileUpload();

    // Set upload parameters
    DiskFileItemFactory factory = new DiskFileItemFactory();
    factory.setSizeThreshold(0);
    upload.setFileItemFactory(factory);
    upload.setSizeMax(-1);

    // Parse the request
    List<FileItem> items;
    try {
        items = upload.parseRequest(req);
    } catch (Exception e) {
        throw new ServletException(e.getMessage(), e);
    }

    // Process the uploaded items
    if (items != null && items.size() > 0) {
        // Only one file
        Iterator<FileItem> iter = items.iterator();
        FileItem item = iter.next();
        if (LOG.isDebugEnabled()) {
            LOG.debug(item.getFieldName());
        }

        File file = null;
        if (!item.isFormField()) {
            try {
                String filename = item.getName();
                if (req.getParameter(PARAMETER_DEPLOY_JOB) != null) {
                    String contextStr = req.getParameter(PARAMETER_CONTEXT);
                    file = writeJobFile(item, filename, contextStr);
                } else if (filename.endsWith(".bar")) { //$NON-NLS-1$
                    file = writeWorkflowFile(item, filename);
                } else {
                    throw new IllegalArgumentException("Unknown deployment for file '" + filename + "'"); //$NON-NLS-1$ //$NON-NLS-2$
                }
            } catch (Exception e) {
                throw new ServletException(e.getMessage(), e);
            }
        } else {
            throw new ServletException("Couldn't process request"); //$NON-NLS-1$);
        }
        String urlRedirect = req.getParameter("urlRedirect"); //$NON-NLS-1$
        if (Boolean.valueOf(urlRedirect)) {
            String redirectUrl = req.getContextPath() + "?mimeFile=" + file.getName(); //$NON-NLS-1$
            writer.write(redirectUrl);
        } else {
            writer.write(file.getAbsolutePath());
        }
    }
    writer.close();
}

From source file:hu.sztaki.lpds.storage.service.carmen.server.upload.UploadServlet.java

/**
 * Processes requests for <code>POST</code> methods.
 *
 * @param request//from  ww w .j a  va 2 s. com
 *            servlet request
 * @param response
 *            servlet response
 * @throws IOException channel handling error
 * @throws ServletException Servlet error
 */
protected void postProcessRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // System.out.println("");
    // System.out.println("UploadServlet postProcessRequest begin...");
    // valtozok initializalasa
    // stores the form parameters
    Map formParameters = null;
    // stores the file parameters
    Map fileParameters = null;
    // portal service url
    String portalID = new String("");
    // user name
    String userID = new String("");
    // workflow name
    String workflowID = new String("");
    // job name
    String jobID = new String("");
    // storage file name, "input_inp01", "binary"
    String sfile = new String("");
    // configuration ID
    // doConfigure generates during its call 
    // pl: userID + System.currentTimeMillis();
    String confID = new String("");
    // the number of the files to be uploaded
    int fileCounter = 0;
    // true if requestSize is more then the size of the maxRequestSize
    boolean sizeLimitError = false;
    try {
        // Check that we have a file upload request
        ServletRequestContext servletRequestContext = new ServletRequestContext(request);
        boolean isMultipart = ServletFileUpload.isMultipartContent(servletRequestContext);
        if (isMultipart) {
            // System.out.println("Is Multipart Context.");
            FileUtils.getInstance().createRepositoryDirectory();
            // use progress begin
            // Create a factory for progress-disk-based file items
            ProgressMonitorFileItemFactory progressMonitorFileItemFactory = new ProgressMonitorFileItemFactory(
                    request);
            // Set factory constraints
            progressMonitorFileItemFactory.setSizeThreshold(maxMemorySize);
            // Set repository dir
            File tempRepositoryDirectory = new File(repositoryDir);
            progressMonitorFileItemFactory.setRepository(tempRepositoryDirectory);
            // Create a new file upload handler
            ServletFileUpload servletFileUpload = new ServletFileUpload();
            servletFileUpload.setFileItemFactory(progressMonitorFileItemFactory);
            // Set overall request size constraint
            servletFileUpload.setSizeMax(maxRequestSize);
            // Parse the request, List /FileItem/
            List listFileItems = null;
            try {
                // System.out.println("before_parseRequest...");
                listFileItems = servletFileUpload.parseRequest(request);
                // System.out.println("after_parseRequest...");
                formParameters = new HashMap();
                fileParameters = new HashMap();
                for (int i = 0; i < listFileItems.size(); i++) {
                    FileItem fileItem = (FileItem) listFileItems.get(i);
                    if (fileItem.isFormField() == true) {
                        formParameters.put(fileItem.getFieldName(), fileItem.getString());
                    } else {
                        fileParameters.put(fileItem.getFieldName(), fileItem);
                        request.setAttribute(fileItem.getFieldName(), fileItem);
                    }
                }
            } catch (Exception e) {
                // e.printStackTrace();
            }
            // System.out.println("formParameters: " + formParameters);
            // System.out.println("fileParameters: " + fileParameters);
            // use progress end
            if ((listFileItems != null) && (listFileItems.size() > 0)) {
                // Process the hidden items
                Iterator iterator = listFileItems.iterator();
                while (iterator.hasNext()) {
                    FileItem fileItem = (FileItem) iterator.next();
                    // System.out.println("getFieldname : " + fileItem.getFieldName());
                    // System.out.println("getString : " + fileItem.getString());
                    if (fileItem.isFormField()) {
                        // parameterek ertelmezese
                        if (fileItem.getFieldName().equals("portalID")) {
                            portalID = FileUtils.getInstance().convertPortalIDtoDirName(fileItem.getString());
                        }
                        if (fileItem.getFieldName().equals("userID")) {
                            userID = fileItem.getString();
                        }
                        if (fileItem.getFieldName().equals("workflowID")) {
                            workflowID = fileItem.getString();
                        }
                        if (fileItem.getFieldName().equals("jobID")) {
                            jobID = fileItem.getString();
                        }
                        if (fileItem.getFieldName().equals("sfile")) {
                            sfile = fileItem.getString();
                        }
                        if (fileItem.getFieldName().equals("confID")) {
                            confID = fileItem.getString();
                        }
                    } else {
                        if ((fileItem.getName() != null) && (!fileItem.getName().equals(""))) {
                            fileCounter++;
                        }
                    }
                }
                // System.out.println("FileCounter : " + fileCounter);
                // Process the uploaded items
                if ((portalID != null) && (userID != null) && (workflowID != null) && (jobID != null)
                        && (sfile != null) && (confID != null) && (fileCounter > 0)) {
                    if ((!portalID.equals("")) && (!userID.equals("")) && (!workflowID.equals(""))
                            && (!jobID.equals("")) && (!sfile.equals("")) && (!confID.equals(""))) {
                        iterator = listFileItems.iterator();
                        while (iterator.hasNext()) {
                            FileItem fileItem = (FileItem) iterator.next();
                            if (!fileItem.isFormField()) {
                                processUploadedFiles(response, fileItem, portalID, userID, workflowID, jobID,
                                        sfile, confID);
                            }
                        }
                    }
                }
            }
        } else {
            // System.out.println("Is NOT Multipart Context !!!");
        }
    } catch (Exception e) {
        // e.printStackTrace();
        throw new ServletException(e);
    }
    if (sizeLimitError) {
        // System.out.println("SizeLimitError: Upload file size (ReqestSize)
        // > " + this.maxRequestSize + " !");
    }
    // System.out.println("UploadServlet postProcessRequest end...");
}

From source file:org.apache.openejb.server.httpd.part.CommonsFileUploadPartFactory.java

public static Collection<Part> read(final HttpRequestImpl request) { // mainly for testing
    // Create a new file upload handler
    final DiskFileItemFactory factory = new DiskFileItemFactory();
    factory.setRepository(REPO);/* www. jav  a  2  s  . com*/

    final ServletFileUpload upload = new ServletFileUpload();
    upload.setFileItemFactory(factory);

    final List<Part> parts = new ArrayList<>();
    try {
        final List<FileItem> items = upload.parseRequest(new ServletRequestContext(request));
        final String enc = request.getCharacterEncoding();
        for (final FileItem item : items) {
            final CommonsFileUploadPart part = new CommonsFileUploadPart(item, null);
            parts.add(part);
            if (part.getSubmittedFileName() == null) {
                String name = part.getName();
                String value = null;
                try {
                    String encoding = request.getCharacterEncoding();
                    if (encoding == null) {
                        if (enc == null) {
                            encoding = "UTF-8";
                        } else {
                            encoding = enc;
                        }
                    }
                    value = part.getString(encoding);
                } catch (final UnsupportedEncodingException uee) {
                    try {
                        value = part.getString("UTF-8");
                    } catch (final UnsupportedEncodingException e) {
                        // not possible
                    }
                }
                request.addInternalParameter(name, value);
            }
        }

        return parts;
    } catch (final FileUploadException e) {
        throw new IllegalStateException(e);
    }
}

From source file:org.apache.sling.engine.impl.parameters.ParameterSupport.java

private void parseMultiPartPost(ParameterMap parameters) {

    // Create a new file upload handler
    ServletFileUpload upload = new ServletFileUpload();
    upload.setSizeMax(ParameterSupport.maxRequestSize);
    upload.setFileSizeMax(ParameterSupport.maxFileSize);
    upload.setFileItemFactory(
            new DiskFileItemFactory(ParameterSupport.fileSizeThreshold, ParameterSupport.location));

    RequestContext rc = new ServletRequestContext(this.getServletRequest()) {
        @Override/*w w  w  .  j a v  a2 s . co  m*/
        public String getCharacterEncoding() {
            String enc = super.getCharacterEncoding();
            return (enc != null) ? enc : Util.ENCODING_DIRECT;
        }
    };

    // Parse the request
    List<?> /* FileItem */ items = null;
    try {
        items = upload.parseRequest(rc);
    } catch (FileUploadException fue) {
        this.log.error("parseMultiPartPost: Error parsing request", fue);
    }

    if (items != null && items.size() > 0) {
        for (Iterator<?> ii = items.iterator(); ii.hasNext();) {
            FileItem fileItem = (FileItem) ii.next();
            RequestParameter pp = new MultipartRequestParameter(fileItem);
            parameters.addParameter(pp, false);
        }
    }
}

From source file:org.apache.sling.tooling.support.install.impl.InstallServlet.java

private void installBasedOnUploadedJar(HttpServletRequest req, HttpServletResponse resp) throws IOException {

    InstallationResult result = null;//  w  w w.  j  ava 2 s.  c  o  m

    try {
        DiskFileItemFactory factory = new DiskFileItemFactory();
        // try to hold even largish bundles in memory to potentially improve performance
        factory.setSizeThreshold(UPLOAD_IN_MEMORY_SIZE_THRESHOLD);

        ServletFileUpload upload = new ServletFileUpload();
        upload.setFileItemFactory(factory);

        @SuppressWarnings("unchecked")
        List<FileItem> items = upload.parseRequest(req);
        if (items.size() != 1) {
            logAndWriteError(
                    "Found " + items.size() + " items to process, but only updating 1 bundle is supported",
                    resp);
            return;
        }

        FileItem item = items.get(0);

        JarInputStream jar = null;
        InputStream rawInput = null;
        try {
            jar = new JarInputStream(item.getInputStream());
            Manifest manifest = jar.getManifest();
            if (manifest == null) {
                logAndWriteError("Uploaded jar file does not contain a manifest", resp);
                return;
            }

            final String symbolicName = manifest.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME);

            if (symbolicName == null) {
                logAndWriteError("Manifest does not have a " + Constants.BUNDLE_SYMBOLICNAME, resp);
                return;
            }

            final String version = manifest.getMainAttributes().getValue(Constants.BUNDLE_VERSION);

            // the JarInputStream is used only for validation, we need a fresh input stream for updating
            rawInput = item.getInputStream();

            Bundle found = getBundle(symbolicName);
            try {
                installOrUpdateBundle(found, rawInput, "inputstream:" + symbolicName + "-" + version + ".jar");

                result = new InstallationResult(true, null);
                resp.setStatus(200);
                result.render(resp.getWriter());
                return;
            } catch (BundleException e) {
                logAndWriteError("Unable to install/update bundle " + symbolicName, e, resp);
                return;
            }
        } finally {
            IOUtils.closeQuietly(jar);
            IOUtils.closeQuietly(rawInput);
        }

    } catch (FileUploadException e) {
        logAndWriteError("Failed parsing uploaded bundle", e, resp);
        return;
    }
}

From source file:org.deegree.client.core.filter.InputFileWrapper.java

@SuppressWarnings("unchecked")
public InputFileWrapper(HttpServletRequest request) throws ServletException {
    super(request);
    try {/*from   w ww.ja  va 2  s  . c o  m*/
        ServletFileUpload upload = new ServletFileUpload();
        DiskFileItemFactory factory = new DiskFileItemFactory();
        upload.setFileItemFactory(factory);
        String encoding = request.getCharacterEncoding();
        List<FileItem> fileItems = upload.parseRequest(request);
        formParameters = new HashMap<String, String[]>();
        for (int i = 0; i < fileItems.size(); i++) {
            FileItem item = fileItems.get(i);
            if (item.isFormField()) {
                String[] values;
                String v;
                if (encoding != null) {
                    v = item.getString(encoding);
                } else {
                    v = item.getString();
                }
                if (formParameters.containsKey(item.getFieldName())) {
                    String[] strings = formParameters.get(item.getFieldName());
                    values = new String[strings.length + 1];
                    for (int j = 0; j < strings.length; j++) {
                        values[j] = strings[j];
                    }
                    values[strings.length] = v;
                } else {
                    values = new String[] { v };
                }
                formParameters.put(item.getFieldName(), values);
            } else if (item.getName() != null && item.getName().length() > 0 && item.getSize() > 0) {
                request.setAttribute(item.getFieldName(), item);
            }
        }
    } catch (FileUploadException fe) {
        ServletException servletEx = new ServletException();
        servletEx.initCause(fe);
        throw servletEx;
    } catch (UnsupportedEncodingException e) {
        ServletException servletEx = new ServletException();
        servletEx.initCause(e);
        throw servletEx;
    }
}