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

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

Introduction

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

Prototype

public void setSizeMax(long sizeMax) 

Source Link

Document

Sets the maximum allowed upload size.

Usage

From source file:org.opensubsystems.core.util.servlet.WebParamUtils.java

/**
 * Parse multipart request and separate regular parameters and files. The
 * files names are also stored as values of the parameters that are used to 
 * upload them./*from   w  w  w. j  av a2s. c o  m*/
 * 
 * @param strLogPrefix - log prefix used for all log output to tie together
 *                       the same invocations
 * @param request - request to get parameter from
 * @return TwoElementStruct<Map<String, String>, Map<String, FileItem>> - the
 *                  first element is map of parameter names and their values. 
 *                  For uploaded files the files names are also stored here as 
 *                  values of the parameters that are used to upload them.
 *                  If there is only one value of the parameter then the value
 *                  is stored directly as String. If there are multiple values
 *                  then the values are stored as List<String>.
 *                  The second element is map of parameter names and the files
 *                  that are uploaded as these parameters.
 * @throws FileUploadException - an error has occurred
 */
public static TwoElementStruct<Map<String, Object>, Map<String, FileItem>> parseMultipartRequest(
        String strLogPrefix, HttpServletRequest request) throws FileUploadException {
    if (GlobalConstants.ERROR_CHECKING) {
        assert ServletFileUpload.isMultipartContent(request) : "Specified request is not multipart";
    }

    TwoElementStruct<Map<String, Object>, Map<String, FileItem>> returnValue;
    FileCleaningTracker fileCleaningTracker;
    String strTempDir;
    DiskFileItemFactory factory;
    Properties prpSettings;
    int iMaxInMemorySize;
    int iMaxSize;
    ServletFileUpload upload;
    List<FileItem> items;

    // TODO: Improve: Consider calling 
    // FileUtils.createTemporarySubdirectory
    // as done in legacy Formature.DocumentTemplateServlet.getFormToProcess
    // to store the temporary files per session and request
    strTempDir = FileUtils.getTemporaryDirectory();

    prpSettings = Config.getInstance().getProperties();
    iMaxInMemorySize = PropertyUtils.getIntPropertyInRange(prpSettings, REQUEST_UPLOAD_MEMORY_THRESHOLD,
            REQUEST_UPLOAD_MEMORY_THRESHOLD_DEFAULT, "Maximal size of uploaded file that is kept in memory", 1, // 0 is allowed 
            Integer.MAX_VALUE);
    iMaxSize = PropertyUtils.getIntPropertyInRange(prpSettings, REQUEST_UPLOAD_MAX_SIZE,
            REQUEST_UPLOAD_MAX_SIZE_DEFAULT, "Maximal size of uploaded file", 1, // 0 is allowed 
            Integer.MAX_VALUE);

    fileCleaningTracker = FileCleanerCleanup.getFileCleaningTracker(request.getServletContext());

    // Create a factory for disk-based file items
    factory = new DiskFileItemFactory();
    factory.setFileCleaningTracker(fileCleaningTracker);
    // Set factory constraints
    factory.setSizeThreshold(iMaxInMemorySize);
    factory.setRepository(new File(strTempDir));

    // Create a new file upload handler
    upload = new ServletFileUpload(factory);
    // Set overall request size constraint
    upload.setSizeMax(iMaxSize);

    // Parse the request
    items = upload.parseRequest(request);
    if ((items != null) && (!items.isEmpty())) {
        Map mpParams;
        Map mpFiles;
        String strParamName;
        String strValue;
        Object temp;
        List<String> lstValues;

        mpParams = new HashMap(items.size());
        mpFiles = new HashMap();

        returnValue = new TwoElementStruct(mpParams, mpFiles);
        for (FileItem item : items) {
            strParamName = item.getFieldName();
            if (item.isFormField()) {
                strValue = item.getString();
            } else {
                strValue = item.getName();
                mpFiles.put(strParamName, item);
            }

            temp = mpParams.put(strParamName, strValue);
            if (temp != null) {
                // There was already an value so convert it to list of values
                if (temp instanceof String) {
                    // There are currently exactly two values
                    lstValues = new ArrayList<>();
                    lstValues.add((String) temp);
                    mpParams.put(strParamName, lstValues);
                } else {
                    // There are currently more than two values
                    lstValues = (List<String>) temp;
                }
                lstValues.add(strValue);
            }
        }
    } else {
        returnValue = new TwoElementStruct(Collections.emptyMap(), Collections.emptyMap());
    }

    return returnValue;
}

From source file:org.origin.common.servlet.WebConsoleUtil.java

/**
 * An utility method, that is used to filter out simple parameter from file parameter when multipart transfer encoding is used.
 *
 * This method processes the request and sets a request attribute {@link AbstractWebConsolePlugin#ATTR_FILEUPLOAD}. The attribute value is a {@link Map}
 * where the key is a String specifying the field name and the value is a {@link org.apache.commons.fileupload.FileItem}.
 *
 * @param request// w  w w. j ava 2  s .c o  m
 *            the HTTP request coming from the user
 * @param name
 *            the name of the parameter
 * @return if not multipart transfer encoding is used - the value is the parameter value or <code>null</code> if not set. If multipart is used, and the
 *         specified parameter is field - then the value of the parameter is returned.
 */
public static final String getParameter(HttpServletRequest request, String name) {
    // just get the parameter if not a multipart/form-data POST
    if (!FileUploadBase.isMultipartContent(new ServletRequestContext(request))) {
        return request.getParameter(name);
    }

    // check, whether we already have the parameters
    Map params = (Map) request.getAttribute(ATTR_FILEUPLOAD);
    if (params == null) {
        // parameters not read yet, read now
        // Create a factory for disk-based file items
        DiskFileItemFactory factory = new DiskFileItemFactory();
        factory.setSizeThreshold(256000);
        // See https://issues.apache.org/jira/browse/FELIX-4660
        final Object repo = request.getAttribute(ATTR_FILEUPLOAD_REPO);
        if (repo instanceof File) {
            factory.setRepository((File) repo);
        }

        // Create a new file upload handler
        ServletFileUpload upload = new ServletFileUpload(factory);
        upload.setSizeMax(-1);

        // Parse the request
        params = new HashMap();
        try {
            List items = upload.parseRequest(request);
            for (Iterator fiter = items.iterator(); fiter.hasNext();) {
                FileItem fi = (FileItem) fiter.next();
                FileItem[] current = (FileItem[]) params.get(fi.getFieldName());
                if (current == null) {
                    current = new FileItem[] { fi };
                } else {
                    FileItem[] newCurrent = new FileItem[current.length + 1];
                    System.arraycopy(current, 0, newCurrent, 0, current.length);
                    newCurrent[current.length] = fi;
                    current = newCurrent;
                }
                params.put(fi.getFieldName(), current);
            }
        } catch (FileUploadException fue) {
            // TODO: log
        }
        request.setAttribute(ATTR_FILEUPLOAD, params);
    }

    FileItem[] param = (FileItem[]) params.get(name);
    if (param != null) {
        for (int i = 0; i < param.length; i++) {
            if (param[i].isFormField()) {
                return param[i].getString();
            }
        }
    }

    // no valid string parameter, fail
    return null;
}

From source file:org.oryxeditor.server.BPEL2BPMNServlet.java

protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    // Get the PrintWriter
    res.setContentType("text/html");
    res.setStatus(200);//from w  ww.ja  v  a2  s  .  com

    JSONObject object = new JSONObject();

    PrintWriter out = null;
    try {
        out = res.getWriter();
    } catch (IOException e) {
        e.printStackTrace();
    }

    // No isMultipartContent => Error
    final boolean isMultipartContent = ServletFileUpload.isMultipartContent(req);
    if (!isMultipartContent) {
        printError(object, out, "No Multipart Content transmitted.");
        return;
    }

    // Get the uploaded file
    final FileItemFactory factory = new DiskFileItemFactory();
    final ServletFileUpload servletFileUpload = new ServletFileUpload(factory);
    servletFileUpload.setSizeMax(-1);
    final List<?> items;
    try {
        items = servletFileUpload.parseRequest(req);
        if (items.size() != 1) {
            printError(object, out, "Not exactly one File.");
            return;
        }
    } catch (FileUploadException e) {
        handleException(object, out, e);
        return;
    }
    final FileItem fileItem = (FileItem) items.get(0);

    // try to parse the BPEL file
    BPELParser parser = new BPELParser();
    Document doc = parser.parseBPELFile(fileItem.getInputStream());

    if (doc == null) {
        printError(object, out, "The file could not be parsed.");
        return;
    }

    // try to map the BPEL process to BPMN
    BPMNDiagram diagram = null;
    try {
        BPEL2BPMNTransformer transformer = new BPEL2BPMNTransformer(doc);
        diagram = transformer.mapBPEL2BPMN();
    } catch (Exception e) {
        printError(object, out, "BPEL could not be mapped to BPMN.");
        return;
    }

    if (diagram == null) {
        printError(object, out, "BPMN diagram could not be created.");
        return;
    }

    // serialize the resulting BPMN
    try {
        BPMNeRDFSerializer serializer = new BPMNeRDFSerializer();
        String eRDF = serializer.serializeBPMNDiagram(diagram).replaceAll("\"", "'").replaceAll("<", "&lt;")
                .replaceAll(">", "&gt;");

        object.put("success", true);

        // check for XML schema validation errors
        if (parser.isSuccessfulValidation()) {
            object.put("successValidation", true);
            object.put("validationError", "");
        } else {
            object.put("successValidation", false);
            object.put("validationError", parser.getValidationException());
        }
        object.put("content", eRDF);

        object.write(out);
    } catch (Exception e) {
        printError(object, out, "Resulting BPMN diagram could not be serialized.");
        return;
    }
}

From source file:org.oryxeditor.server.BPEL4ChorImporter.java

/**
 * The POST request.// w  ww  . j  av a 2s .  c om
 */
protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException {

    // No isMultipartContent => Error
    final boolean isMultipartContent = ServletFileUpload.isMultipartContent(req);
    if (!isMultipartContent) {
        printError(res, "No Multipart Content transmitted.");
        return;
    }

    // Get the uploaded file
    final FileItemFactory factory = new DiskFileItemFactory();
    final ServletFileUpload servletFileUpload = new ServletFileUpload(factory);
    servletFileUpload.setSizeMax(-1);
    final List<?> items;
    try {
        items = servletFileUpload.parseRequest(req);
        if (items.size() != 1) {
            printError(res, "Not exactly one File.");
            return;
        }
    } catch (FileUploadException e) {
        handleException(res, e);
        return;
    }

    // === prepare the bpel source ===
    // Get filename and content
    final FileItem fileItem = (FileItem) items.get(0);
    final String fileName = fileItem.getName();
    final String fileContent = fileItem.getString();

    // because the namespace of bpel process is't unique, and it's difficult 
    // to handle a unknown namespace in XSLT 1.0 (it doesn't support the xPath 
    // e.g."*:process"), we remove the attribute "xmlns" before we transform
    // this file. 
    final String contentWithoutNamespace = removeAttributeXMLNS(fileContent);

    // Get the input stream   
    final InputStream inputStream = new ByteArrayInputStream(contentWithoutNamespace.getBytes());

    // Get the bpel source
    final Source bpelSource;

    if (fileName.endsWith(".bpel")) {
        bpelSource = new StreamSource(inputStream);
    } else {
        printError(res, "No file with .bepl extension uploaded.");
        return;
    }

    // === prepare the xslt source ===
    // BPEL2eRDF XSLT source
    final String xsltFilename = getServletContext().getRealPath("/xslt/BPEL2eRDF.xslt");
    //       final String xsltFilename = System.getProperty("catalina.home") + "/webapps/oryx/xslt/BPEL2eRDF.xslt";
    final File bpel2eRDFxsltFile = new File(xsltFilename);
    final Source bpel2eRDFxsltSource = new StreamSource(bpel2eRDFxsltFile);

    // Transformer Factory
    final TransformerFactory transformerFactory = TransformerFactory.newInstance();

    // === Get the eRDF result ===
    String resultString = null;
    try {
        Transformer transformer = transformerFactory.newTransformer(bpel2eRDFxsltSource);
        StringWriter writer = new StringWriter();
        transformer.transform(bpelSource, new StreamResult(writer));
        resultString = writer.toString();
    } catch (Exception e) {
        handleException(res, e);
        return;
    }

    if (resultString != null) {
        try {
            printResponse(res, resultString);
            return;
        } catch (Exception e) {
            handleException(res, e);
        }
    }
}

From source file:org.oryxeditor.server.BPELImporter.java

/**
 * The POST request.//from w  ww  .  j a v  a2 s  .  c  om
 */
protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException {
    // No isMultipartContent => Error
    final boolean isMultipartContent = ServletFileUpload.isMultipartContent(req);
    if (!isMultipartContent) {
        printError(res, "No Multipart Content transmitted.");
        return;
    }

    // Get the uploaded file
    final FileItemFactory factory = new DiskFileItemFactory();
    final ServletFileUpload servletFileUpload = new ServletFileUpload(factory);
    servletFileUpload.setSizeMax(-1);
    final List<?> items;
    try {
        items = servletFileUpload.parseRequest(req);
        if (items.size() != 1) {
            printError(res, "Not exactly one File.");
            return;
        }
    } catch (FileUploadException e) {
        handleException(res, e);
        return;
    }

    // === prepare the bpel source ===
    // Get filename and content
    final FileItem fileItem = (FileItem) items.get(0);
    final String fileName = fileItem.getName();

    if (!fileName.endsWith(".bpel")) {
        printError(res, "No file with .bepl extension uploaded.");
        return;
    }

    final String fileContent = fileItem.getString();

    // do a pre-processing on this bpel source
    // in this preprocessor the following works will be done:
    //     1. mark all node stencil sets with the attribute "isNodeStencilSet"
    //         mark all edge stencil sets with the attribute "isEdgeStencilSet"
    //         in order to avoid the prefix problem
    //     2. calculate the bounds of each shape
    //      3. generate for each shape a ID
    //     4. move the <link> elements from <links> element to
    //         top of the root <process> element, and record linkID
    //         as the value of element <outgoing> under the corresponding
    //         activity, so they could be easier to handle in BPEL2eRDF.xslt
    //      5. integrate the first <condition> and <activity> element
    //         under a If-block into a <elseIF> element, so they
    //         they could be easier to transform in BPEL2eRDF.xslt
    //      6. transform the value of attribute "opaque" from "yes" to "true"
    final String newContent = preprocessSource(res, fileContent);

    log.fine("newContent:");
    log.fine(newContent);

    // Get the input stream   
    final InputStream inputStream = new ByteArrayInputStream(newContent.getBytes());

    // Get the bpel source
    final Source bpelSource = new StreamSource(inputStream);

    // === prepare the xslt source ===
    // BPEL2eRDF XSLT source
    final String xsltFilename = getServletContext().getRealPath("/xslt/BPEL2eRDF.xslt");
    //       final String xsltFilename = System.getProperty("catalina.home") + "/webapps/oryx/xslt/BPEL2eRDF.xslt";
    final File bpel2eRDFxsltFile = new File(xsltFilename);
    final Source bpel2eRDFxsltSource = new StreamSource(bpel2eRDFxsltFile);

    // Transformer Factory
    final TransformerFactory transformerFactory = TransformerFactory.newInstance();

    // === Get the eRDF result ===
    String resultString = null;
    try {
        Transformer transformer = transformerFactory.newTransformer(bpel2eRDFxsltSource);
        transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        StringWriter writer = new StringWriter();
        transformer.transform(bpelSource, new StreamResult(writer));
        resultString = writer.toString();
    } catch (Exception e) {
        handleException(res, e);
        return;
    }

    log.fine("reslut-XML");
    log.fine(resultString);

    if (resultString == null) {
        printResponse(res, "transformation error");
    }

    Repository rep = new Repository("");
    resultString = rep.erdfToJson(resultString, getServletContext());

    log.fine("reslut-json");
    log.fine(resultString);

    printResponse(res, resultString);
}

From source file:org.oryxeditor.server.TBPMServlet.java

protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException {

    res.setContentType("text/html");
    res.setStatus(200);/*from ww  w. j  a  v  a 2  s  .  c  o m*/
    PrintWriter out = null;
    try {
        out = res.getWriter();
    } catch (IOException e) {
        e.printStackTrace();
    }

    // No isMultipartContent => Error
    final boolean isMultipartContent = ServletFileUpload.isMultipartContent(req);
    if (!isMultipartContent) {
        printError(res, "No Multipart Content transmitted.");
        return;
    }

    final FileItemFactory factory = new DiskFileItemFactory();
    final ServletFileUpload servletFileUpload = new ServletFileUpload(factory);
    servletFileUpload.setSizeMax(-1);
    try {
        final List<?> items = servletFileUpload.parseRequest(req);
        final FileItem fileItem = (FileItem) items.get(0);
        final String fileName = fileItem.getName();
        if (!(fileName.endsWith(".png") || fileName.endsWith(".jpg") || fileName.endsWith(".JPG"))) {
            printError(res, "No file with .png or .jpg extension uploaded.");
            return;
        }
        String response = this.processUploadedFile(fileItem);
        out.write(response);

    } catch (FileUploadException e1) {
        e1.printStackTrace();
    }
}

From source file:org.ow2.proactive_grid_cloud_portal.common.server.CredentialsServlet.java

private void login(HttpServletRequest request, HttpServletResponse response) {
    response.setContentType("text/html");

    try {//from  w  ww  .j a  v  a 2  s.c  o  m
        DiskFileItemFactory factory = new DiskFileItemFactory();
        factory.setSizeThreshold(4096);
        factory.setRepository(new File(System.getProperty("java.io.tmpdir")));
        ServletFileUpload upload = new ServletFileUpload(factory);
        upload.setSizeMax(1000000);

        List<?> fileItems = upload.parseRequest(request);
        Iterator<?> i = fileItems.iterator();

        String user = "";
        String pass = "";
        String sshKey = "";

        while (i.hasNext()) {
            FileItem fi = (FileItem) i.next();

            if (fi.isFormField()) {
                String name = fi.getFieldName();
                String value = fi.getString();

                if (name.equals("username")) {
                    user = value;
                } else if (name.equals("password")) {
                    pass = value;
                }
            } else {
                String field = fi.getFieldName();
                byte[] bytes = IOUtils.toByteArray(fi.getInputStream());
                if (field.equals("sshkey")) {
                    sshKey = new String(bytes);
                }
            }
            fi.delete();
        }

        String responseS = Service.get().createCredentials(user, pass, sshKey);
        response.setHeader("Content-disposition", "attachment; filename=" + user + "_cred.txt");
        response.setHeader("Location", "" + user + ".cred.txt");
        response.getWriter().write(responseS);

    } catch (Throwable t) {
        try {
            response.getWriter().write(t.getMessage());
        } catch (IOException e1) {
            LOGGER.warn("Failed to return login error to client, error was:" + t.getMessage(), e1);
        }
    }
}

From source file:org.ow2.proactive_grid_cloud_portal.common.server.LoginServlet.java

private void login(HttpServletRequest request, HttpServletResponse response) {
    response.setContentType("text/html");
    File cred = null;/*from   ww  w.  j  a va  2s. c  om*/
    try {
        DiskFileItemFactory factory = new DiskFileItemFactory();
        factory.setSizeThreshold(4096);
        factory.setRepository(new File(System.getProperty("java.io.tmpdir")));
        ServletFileUpload upload = new ServletFileUpload(factory);
        upload.setSizeMax(1000000);

        List<?> fileItems = upload.parseRequest(request);
        Iterator<?> i = fileItems.iterator();

        String user = "";
        String pass = "";
        String sshKey = "";

        while (i.hasNext()) {
            FileItem fi = (FileItem) i.next();

            if (fi.isFormField()) {
                String name = fi.getFieldName();
                String value = fi.getString();

                if (name.equals("username")) {
                    user = value;
                } else if (name.equals("password")) {
                    pass = value;
                }
            } else {
                String field = fi.getFieldName();

                byte[] bytes = IOUtils.toByteArray(fi.getInputStream());

                if (field.equals("credential")) {
                    cred = File.createTempFile("credential", null);
                    cred.deleteOnExit();
                    fi.write(cred);
                } else if (field.equals("sshkey")) {
                    sshKey = new String(bytes);
                }
            }

            fi.delete();
        }

        String responseS = Service.get().login(user, pass, cred, sshKey);
        String s = "{ \"sessionId\" : \"" + responseS + "\" }";
        response.getWriter().write(SafeHtmlUtils.htmlEscape(s));
    } catch (Throwable t) {
        try {
            response.getWriter().write(SafeHtmlUtils.htmlEscape(t.getMessage()));
        } catch (IOException e1) {
            LOGGER.warn("Failed to return login error to client, error was:" + t.getMessage(), e1);
        }
    } finally {
        if (cred != null)
            cred.delete();
    }
}

From source file:org.ow2.proactive_grid_cloud_portal.rm.server.NSCreationServlet.java

private void createNs(HttpServletRequest request, HttpServletResponse response) {

    String sessionId = "";
    String callbackName = "";
    String nsName = "";
    String infra = "";
    String policy = "";

    ArrayList<String> infraParams = new ArrayList<>();
    ArrayList<String> infraFileParams = new ArrayList<>();
    ArrayList<String> policyParams = new ArrayList<>();
    ArrayList<String> policyFileParams = new ArrayList<>();

    boolean readingInfraParams = false;
    boolean readingPolicyParams = false;

    try {// w w  w.j  a va  2 s .com
        DiskFileItemFactory factory = new DiskFileItemFactory();
        factory.setSizeThreshold(4096);
        factory.setRepository(new File(System.getProperty("java.io.tmpdir")));
        ServletFileUpload upload = new ServletFileUpload(factory);
        upload.setSizeMax(MAX_UPLOAD_SIZE);

        List<?> fileItems = upload.parseRequest(request);
        Iterator<?> i = fileItems.iterator();
        while (i.hasNext()) {
            FileItem fi = (FileItem) i.next();
            String fieldName = fi.getFieldName();
            if (fi.isFormField()) {
                if (fieldName.equals("sessionId")) {
                    sessionId = fi.getString();
                } else if (fieldName.equals("nsCallback")) {
                    callbackName = fi.getString();
                } else if (fieldName.equals("nsName")) {
                    nsName = fi.getString();
                } else if (fieldName.equals("infra")) {
                    infra = fi.getString();
                    readingInfraParams = true;
                } else if (fieldName.equals("policy")) {
                    policy = fi.getString();
                    readingPolicyParams = true;
                    readingInfraParams = false;
                } else if (readingInfraParams) {
                    infraParams.add(fi.getString());
                } else if (readingPolicyParams) {
                    policyParams.add(fi.getString());
                } else {
                    LOGGER.warn("Unexpected param " + fieldName);
                }
            } else {
                if (readingInfraParams) {
                    byte[] bytes = IOUtils.toByteArray(fi.getInputStream());
                    infraFileParams.add(new String(bytes));
                } else if (readingPolicyParams) {
                    byte[] bytes = IOUtils.toByteArray(fi.getInputStream());
                    policyFileParams.add(new String(bytes));
                } else {
                    LOGGER.warn("Unexpected param " + fieldName);
                }
            }
        }
        String failFast = null;
        if (nsName.length() == 0) {
            failFast = "You need to pick a name for the new Node Source";
        } else if (policy.length() == 0 || policy.equals("undefined")) {
            failFast = "No Policy selected";
        } else if (infra.length() == 0 || infra.equals("undefined")) {
            failFast = "No Infrastructure selected";
        }

        if (failFast != null) {
            throw new RestServerException(failFast);
        }

        String jsonResult = ((RMServiceImpl) RMServiceImpl.get()).createNodeSource(sessionId, nsName, infra,
                toArray(infraParams), toArray(infraFileParams), policy, toArray(policyParams),
                toArray(policyFileParams));

        if (jsonResult.equals("true")) {
            jsonResult = createNonEscapedSimpleJsonPair("result", "true");
        }

        write(response, createJavascriptPayload(callbackName, jsonResult));
    } catch (Throwable t) {
        write(response, createJavascriptPayload(callbackName,
                createEscapedSimpleJsonPair("errorMessage", t.getMessage())));
    }
}

From source file:org.ow2.proactive_grid_cloud_portal.rm.server.ServletRequestTransformer.java

@SuppressWarnings("unchecked")
public List<FileItem> getFormItems(HttpServletRequest request) throws FileUploadException {
    DiskFileItemFactory factory = new DiskFileItemFactory();
    factory.setSizeThreshold(FILE_ITEM_THRESHOLD_SIZE);
    factory.setRepository(new File(System.getProperty("java.io.tmpdir")));
    ServletFileUpload upload = new ServletFileUpload(factory);
    upload.setSizeMax(MAX_FILE_UPLOAD_SIZE);
    return (List<FileItem>) upload.parseRequest(request);
}