Example usage for org.apache.commons.fileupload.portlet PortletFileUpload parseRequest

List of usage examples for org.apache.commons.fileupload.portlet PortletFileUpload parseRequest

Introduction

In this page you can find the example usage for org.apache.commons.fileupload.portlet PortletFileUpload parseRequest.

Prototype

public List  parseRequest(ActionRequest request) throws FileUploadException 

Source Link

Document

Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a> compliant <code>multipart/form-data</code> stream.

Usage

From source file:hu.sztaki.lpds.pgportal.portlets.credential.AssertionPortlet.java

/**
 * Uploading SAML file(s) for interaction with the Java Applet.
 * The parameters are filled in by the SAML assiertion applet.
 * This function contains a fallback to the help provider of gUSE.
 * @param request ResourceRequest/*  www . j  a v  a2 s  . co  m*/
 * @param response ResouceResponse
 * @throws PortletException
 * @throws IOException
 */
@Override
public void serveResource(ResourceRequest request, ResourceResponse response)
        throws PortletException, IOException {
    logger.debug("serveResource: guse=" + request.getParameter("guse"));
    if (!"doAppletUpload".equals(request.getParameter("guse"))) {
        super.serveResource(request, response);
        return;
    }

    String msg;

    try {
        logger.debug("Assertion-doUpload");
        FileItem samlFile = null;
        String sresource = null; // selected resource

        try {
            DiskFileItemFactory factory = new DiskFileItemFactory();
            PortletFileUpload pfu = new PortletFileUpload(factory);

            pfu.setSizeMax(1048576); // Maximum upload size 1Mb

            Iterator iter = pfu.parseRequest(PortalUtil.getHttpServletRequest(request)).iterator();

            while (iter.hasNext()) {
                FileItem item = (FileItem) iter.next();

                if (item.isFormField()) { // retrieve parameters if item is a form field
                    if ("sresource".equals(item.getFieldName())) {
                        sresource = item.getString();
                    }
                } else {
                    if ("samlFile".equals(item.getFieldName())) {
                        samlFile = item;
                    }
                }
            }

            List<String> result = uploadSaml(request.getPortletSession(), samlFile, sresource,
                    request.getRemoteUser());

            StringBuilder sb = new StringBuilder();
            boolean flag = false;
            for (String m : result) {
                if (flag) {
                    sb.append("\n");
                } else {
                    flag = true;
                }
                sb.append(m);
            }

            msg = sb.toString();
        } catch (Exception e) {
            msg = "Upload failed. Reason: " + e.getMessage();
            logger.info("Upload of assertion failed. Reason: " + e.getMessage());
            logger.debug("Exception:", e);
        }

        response.setContentType("text/plain");
        response.addProperty("Cache-Control", "no-cache");

        response.getWriter().write(msg);

        logger.info("Returning: " + msg);

    } catch (Exception e2) {
        logger.error("Error in " + getClass().getName() + "\n", e2);
    }
    return;
}

From source file:it.eng.spago.dispatching.httpchannel.AdapterPortlet.java

/**
 * Handle multipart form./* w w w.  j a  v a 2s  .  c  o m*/
 * 
 * @param request the request
 * @param requestContext the request context
 * 
 * @throws Exception the exception
 */
private void handleMultipartForm(ActionRequest request, RequestContextIFace requestContext) throws Exception {
    SourceBean serviceRequest = requestContext.getServiceRequest();

    // Create a factory for disk-based file items
    FileItemFactory factory = new DiskFileItemFactory();

    // Create a new file upload handler
    PortletFileUpload upload = new PortletFileUpload(factory);

    // Parse the request
    List fileItems = upload.parseRequest(request);
    Iterator iter = fileItems.iterator();
    while (iter.hasNext()) {
        FileItem item = (FileItem) iter.next();

        if (item.isFormField()) {
            String name = item.getFieldName();
            String value = item.getString();
            serviceRequest.setAttribute(name, value);
        } else {
            processFileField(item, requestContext);
        }
    }
}

From source file:hu.sztaki.lpds.pgportal.portlets.asm.ClientError.java

public void doUpload(ActionRequest request, ActionResponse response) throws PortletException {
    try {//w w w  . j av  a  2 s .  c o m
        String jobport = "";
        String selected_wf = "";
        //getting upload parameters
        ActionRequest temp_req = request;

        DiskFileItemFactory factory = new DiskFileItemFactory();
        PortletFileUpload pfu = new PortletFileUpload(factory);

        List fileItems = pfu.parseRequest(temp_req);

        Iterator iter = fileItems.iterator();
        FileItem file2upload = null;
        while (iter.hasNext()) {
            FileItem item = (FileItem) iter.next();

            // retrieve hidden parameters if item is a form field
            if (item.isFormField()) {
                if (item.getFieldName().equals(new String("where2upload"))) {
                    jobport = item.getString();
                }
                if (item.getFieldName().startsWith(new String("instance_upload"))) {
                    selected_wf = item.getString();
                }
            } else {
                file2upload = item;
            }
        }

        String[] splitted = jobport.split("@");
        String selected_job = splitted[0];

        String selected_port = splitted[1];

        String userId = request.getRemoteUser();

        File uploadedFile = asm_service.uploadFiletoPortalServer(file2upload, userId, file2upload.getName());
        asm_service.placeUploadedFile(request.getRemoteUser(), uploadedFile, selected_wf, selected_job,
                selected_port);

    } catch (Exception ex) {
        ex.printStackTrace();
        Logger.getLogger(ASM_SamplePortlet.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:hu.sztaki.lpds.pgportal.portlets.asm.ClientError.java

@SuppressWarnings("empty-statement")
public void doUploadLigands(ActionRequest request, ActionResponse response) {
    try {//  w ww . java  2  s.  co m
        // MULTIPART REQUEST
        ActionRequest temp_req = request;

        DiskFileItemFactory factory = new DiskFileItemFactory();
        PortletFileUpload pfu = new PortletFileUpload(factory);

        List fileItems = pfu.parseRequest(temp_req);

        // ligands
        Iterator iter = fileItems.iterator();
        ArrayList<FileItem> file2upload = new ArrayList<FileItem>();
        FileItem receptorFileItem = null;
        FileItem configFileItem = null;
        String vina_configuration = "";
        String vina_best_result = "";
        String rep_owner = "";
        String task_name = "";

        while (iter.hasNext()) {
            FileItem item = (FileItem) iter.next();
            if (item.isFormField()) {
                // TEXT FIELD
                if (item.getFieldName().equals("vina_configuration")) {
                    vina_configuration = item.getString();
                }
                if (item.getFieldName().startsWith("vina_best_result")) {
                    vina_best_result = item.getString();
                }
                if (item.getFieldName().startsWith("rep_owner")) {
                    rep_owner = item.getString();
                }
                if (item.getFieldName().startsWith("task_name")) {
                    task_name = item.getString();
                }

            } else {
                // FILE UPLOAD
                String fieldName = item.getFieldName();
                String fileName = item.getName();
                long sizeInBytes = item.getSize();
                if (fieldName.equals("receptor")) {
                    receptorFileItem = item;
                }
                if (fieldName.equals("ligands")) {
                    file2upload.add(item);
                }
                if (fieldName.equals("vina_config_file")) {
                    configFileItem = item;
                }
            }
        }

        //IMPORT NEW WORKFLOW INSTANCE
        // selected_wf_type="122";
        String newWfinstanceID = selected_wf_type + "_" + task_name;
        String ruser = request.getRemoteUser();
        rep_owner = ruser;
        String userId = rep_owner;
        String rowner = request.getParameter("owner");
        selected_wf = importWorkflow(rep_owner, ruser, selected_wf_type, newWfinstanceID);

        if (selected_wf.length() < 3) {
            throwError("Import " + newWfinstanceID + " workflow is failed", 1);
        }

        String job_generator = "Generator";

        String port_input_receptor = "5"; //input-receptor.pdbqt
        String port_vina_config = "4"; //vina-config.txt
        String port_input_ligands = "3"; //input-ligands.zip
        String cmd_parameter_wus_nr = ""; // number of WUs

        String job_collector = "collector.sh";

        String cmd_parameter_best = ""; // number of Best results

        // UPLOAD LIGAND ZIP FILE

        String selected_job = job_generator;
        String selected_port = port_input_ligands;

        for (FileItem f : file2upload) {
            if (f.getName().endsWith(".zip")) {
                File uploadedFile = asm_service.uploadFiletoPortalServer(f, userId, f.getName());
                asm_service.placeUploadedFile(userId, uploadedFile, selected_wf, selected_job, selected_port);
            }
        }

        /*
                    // UPLOAD MULTIPLE PDBQT LIGAND FILE
                    String ligandDir="/tmp/wf_dir_ligands";
                    String zipName="upload.zip";
                
                    Runtime.getRuntime().exec("rm -rf "+ligandDir+"/"+zipName);
                
                    for(FileItem f:file2upload){
        File uploadedFile = asm_service.uploadFiletoPortalServer(f, userId, f.getName());
        System.out.println("jaj"+uploadedFile.getAbsolutePath());
        // PREPARE UPLOADED FILES to SUBMIT MOVE AND COMPRESS
        Runtime.getRuntime().exec("cp "+uploadedFile+" "+ligandDir);
        Runtime.getRuntime().exec("zip "+ligandDir+"/"+zipName+" "+ligandDir+"/"+uploadedFile.getName());
                    }
                
                    File ligandsFile=new File(ligandDir+"/"+zipName);
                    selected_port = "0";
                    asm_service.placeUploadedFile(userId, ligandsFile, selected_wf, selected_job, selected_port);
        */

        // UPLOAD RECEPTOR PDBQT FILE
        selected_port = port_input_receptor;

        File receptorFile = asm_service.uploadFiletoPortalServer(receptorFileItem, userId,
                receptorFileItem.getName());
        asm_service.placeUploadedFile(userId, receptorFile, selected_wf, selected_job, selected_port);

        // SETUP CONFIGURATION
        if (configFileItem == null) {
            String content = vina_configuration;
            selected_port = port_vina_config;
            asm_service.setInputText(userId, content, selected_wf, selected_job, selected_port);
        } else {
            selected_port = port_vina_config;
            File configFile = asm_service.uploadFiletoPortalServer(configFileItem, userId,
                    configFileItem.getName());
            asm_service.placeUploadedFile(userId, configFile, selected_wf, selected_job, selected_port);
        }
        // WUs number
        String wu_content = "5";
        asm_service.setCommandLineArg(userId, selected_wf, selected_job, wu_content);
        // setup Best result number, at the collector job argument
        String best_content = vina_best_result;
        selected_job = job_collector;
        asm_service.setCommandLineArg(userId, selected_wf, selected_job, best_content);

        asm_service.submit(userId, selected_wf, "", "");

        request.setAttribute("nextJSP", DISPLAY_PAGE);

        throwError("Wow! Submitted task! Success! Wait for run, and check eventually!", 10);
        String nextJSP = DISPLAY_PAGE;
        PortletRequestDispatcher dispatcher;
        dispatcher = getPortletContext().getRequestDispatcher(nextJSP);
        dispatcher.include(request, response);

    } catch (Exception ex) {
        throwError(ex.getMessage(), 10);
    }
}

From source file:it.infn.ct.g_hmmer_portlet.java

/**
 * This method manages the user input fields managing two cases 
 * distinguished by the type of the input <form ... statement
 * The use of upload file controls needs the use of "multipart/form-data"
 * while the else condition of the isMultipartContent check manages the 
 * standard input case. The multipart content needs a manual processing of
 * all <form items/*from   w  w  w .  j a va 2 s  .  c  o  m*/
 * All form' input items are identified by the 'name' input property
 * inside the jsp file
 * 
 * @param request   ActionRequest instance (processAction)
 * @param appInput  AppInput instance storing the jobSubmission data
 */
void getInputForm(ActionRequest request, AppInput appInput) {
    if (PortletFileUpload.isMultipartContent(request))
        try {
            FileItemFactory factory = new DiskFileItemFactory();
            PortletFileUpload upload = new PortletFileUpload(factory);
            List items = upload.parseRequest(request);
            File repositoryPath = new File("/tmp");
            DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory();
            diskFileItemFactory.setRepository(repositoryPath);
            Iterator iter = items.iterator();
            String logstring = "";
            while (iter.hasNext()) {
                FileItem item = (FileItem) iter.next();
                String fieldName = item.getFieldName();
                String fileName = item.getName();
                String contentType = item.getContentType();
                boolean isInMemory = item.isInMemory();
                long sizeInBytes = item.getSize();
                // Prepare a log string with field list
                logstring += LS + "field name: '" + fieldName + "' - '" + item.getString() + "'";
                switch (inputControlsIds.valueOf(fieldName)) {
                case file_inputFile:
                    appInput.inputFileName = item.getString();
                    processInputFile(item, appInput);
                    break;
                case inputFile:
                    appInput.inputFileText = item.getString();
                    break;
                case JobIdentifier:
                    appInput.jobIdentifier = item.getString();
                    break;
                default:
                    _log.warn("Unhandled input field: '" + fieldName + "' - '" + item.getString() + "'");
                } // switch fieldName                                                   
            } // while iter.hasNext()   
            _log.info(LS + "Reporting" + LS + "---------" + LS + logstring + LS);
        } // try
        catch (Exception e) {
            _log.info("Caught exception while processing files to upload: '" + e.toString() + "'");
        }
    // The input form do not use the "multipart/form-data" 
    else {
        // Retrieve from the input form the given application values
        appInput.inputFileName = (String) request.getParameter("file_inputFile");
        appInput.inputFileText = (String) request.getParameter("inputFile");
        appInput.jobIdentifier = (String) request.getParameter("JobIdentifier");
    } // ! isMultipartContent

    // Show into the log the taken inputs
    _log.info(LS + "Taken input parameters:" + LS + "-----------------------" + LS + "inputFileName: '"
            + appInput.inputFileName + "'" + LS + "inputFileText: '" + appInput.inputFileText + "'" + LS
            + "jobIdentifier: '" + appInput.jobIdentifier + "'" + LS);
}

From source file:it.infn.mib.AndreaPortlet.java

/**
 * This method manages the user input fields managing two cases 
 * distinguished by the type of the input <form ... statement
 * The use of upload file controls needs the use of "multipart/form-data"
 * while the else condition of the isMultipartContent check manages the 
 * standard input case. The multipart content needs a manual processing of
 * all <form items// ww w .  j ava2 s.co  m
 * All form' input items are identified by the 'name' input property
 * inside the jsp file
 * 
 * @param request   ActionRequest instance (processAction)
 * @param appInput  AppInput instance storing the jobSubmission data
 */
@SuppressWarnings("rawtypes")
void getInputForm(ActionRequest request, AppInput appInput) {
    if (PortletFileUpload.isMultipartContent(request))
        try {
            FileItemFactory factory = new DiskFileItemFactory();
            PortletFileUpload upload = new PortletFileUpload(factory);
            List items = upload.parseRequest(request);
            File repositoryPath = new File("/tmp");
            DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory();
            diskFileItemFactory.setRepository(repositoryPath);
            Iterator iter = items.iterator();
            String logstring = "";
            while (iter.hasNext()) {
                FileItem item = (FileItem) iter.next();
                String fieldName = item.getFieldName();
                //String fileName = item.getName();
                //String contentType = item.getContentType();
                //boolean isInMemory = item.isInMemory();
                //long sizeInBytes = item.getSize();
                // Prepare a log string with field list
                logstring += LS + "field name: '" + fieldName + "' - '" + item.getString() + "'";
                switch (inputControlsIds.valueOf(fieldName)) {
                case file_inputFile:
                    appInput.inputFileName = item.getString();
                    processInputFile(item, appInput);
                    break;
                case inputFile:
                    appInput.inputFileText = item.getString();
                    break;
                case JobIdentifier:
                    appInput.jobIdentifier = item.getString();
                    break;
                default:
                    _log.warn("Unhandled input field: '" + fieldName + "' - '" + item.getString() + "'");
                } // switch fieldName                                                   
            } // while iter.hasNext()   
            _log.info(LS + "Reporting" + LS + "---------" + LS + logstring + LS);
        } // try
        catch (Exception e) {
            _log.info("Caught exception while processing files to upload: '" + e.toString() + "'");
        }
    // The input form do not use the "multipart/form-data" 
    else {
        // Retrieve from the input form the given application values
        appInput.inputFileName = (String) request.getParameter("file_inputFile");
        appInput.inputFileText = (String) request.getParameter("inputFile");
        appInput.jobIdentifier = (String) request.getParameter("JobIdentifier");
    } // ! isMultipartContent

    // Show into the log the taken inputs
    _log.info(LS + "Taken input parameters:" + LS + "-----------------------" + LS + "inputFileName: '"
            + appInput.inputFileName + "'" + LS + "inputFileText: '" + appInput.inputFileText + "'" + LS
            + "jobIdentifier: '" + appInput.jobIdentifier + "'" + LS);
}

From source file:it.infn.ct.SemanticSearch_portlet.java

public void getInputForm(ActionRequest request, App_Input appInput) {
    if (PortletFileUpload.isMultipartContent(request)) {
        try {/*from  w w w  .ja  v  a  2 s. c o m*/
            FileItemFactory factory = new DiskFileItemFactory();
            PortletFileUpload upload = new PortletFileUpload(factory);
            List items = upload.parseRequest(request);
            File repositoryPath = new File("/tmp");
            DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory();
            diskFileItemFactory.setRepository(repositoryPath);
            Iterator iter = items.iterator();
            String logstring = "";

            while (iter.hasNext()) {
                FileItem item = (FileItem) iter.next();
                String fieldName = item.getFieldName();
                String fileName = item.getName();
                String contentType = item.getContentType();
                boolean isInMemory = item.isInMemory();
                long sizeInBytes = item.getSize();
                // Prepare a log string with field list
                logstring += LS + "field name: '" + fieldName + "' - '" + item.getString() + "'";
                switch (inputControlsIds.valueOf(fieldName)) {

                case JobIdentifier:
                    appInput.jobIdentifier = item.getString();
                    break;
                default:
                    _log.warn("Unhandled input field: '" + fieldName + "' - '" + item.getString() + "'");
                } // switch fieldName                                                   
            } // while iter.hasNext()   
            _log.info(LS + "Reporting" + LS + "---------" + LS + logstring + LS);
        } // try
        catch (Exception e) {
            _log.info("Caught exception while processing files to upload: '" + e.toString() + "'");
        }
    } // The input form do not use the "multipart/form-data" 
    else {
        // Retrieve from the input form the given application values
        appInput.search_word = (String) request.getParameter("search_word");
        appInput.jobIdentifier = (String) request.getParameter("JobIdentifier");
        appInput.nameSubject = (String) request.getParameter("nameSubject");

        appInput.idResouce = (String) request.getParameter("idResource");
        appInput.selected_language = (String) request.getParameter("selLanguage");
        appInput.numberPage = (String) request.getParameter("numberOfPage");
        appInput.numRecordsForPage = (String) request.getParameter("numberOfRecords");
        appInput.title_GS = (String) request.getParameter("title_GS");
        appInput.moreInfo = (String) request.getParameter("moreInfo");
        if (appInput.selected_language == null) {
            appInput.selected_language = (String) request.getParameter("nameLanguageDefault");
        }
    } // ! isMultipartContent

    // Show into the log the taken inputs
    _log.info(LS + "Taken input parameters:" + LS + "-----------------------" + LS + "Search Word: '"
            + appInput.search_word + "'" + LS + "jobIdentifier: '" + appInput.jobIdentifier + "'" + LS
            + "subject: '" + appInput.nameSubject + "'" + LS + "idResource: '" + appInput.idResouce + "'" + LS
            + "language selected: '" + appInput.selected_language + "'" + LS + "number page selected: '"
            + appInput.numberPage + "'" + LS + "number record for page: '" + appInput.numRecordsForPage + "'"
            + LS + "moreInfo: '" + appInput.moreInfo + "'" + LS);
}

From source file:hu.sztaki.lpds.pgportal.portlets.credential.MyProxyPortlet.java

/**
 * Depending on user's choice calls proper functions for uploading PEM
 * or SAML file(s).//from w  w w.j  a  v  a  2 s .  co  m
 * The parameters are filled in by the user on the upload.jsp page.
 * @param request ActionRequest
 * @param response ActionResponse
 */
public synchronized void doUpload(ActionRequest request, ActionResponse response) {
    response.setRenderParameter("nextJSP", "upload.jsp");
    FileItem samlFile = null;
    FileItem p12File = null;
    String p12FilePass = null;
    String host = null;
    String portS = null;
    String login = null;
    String pass = null;
    String lifetimeS = null;
    String keyPass = null;
    boolean RFCEnabled = false;
    FileItem kf = null, cf = null;
    boolean useDN = false;
    Boolean samlUsed = false, p12Used = false, pemUsed = false;

    try {
        DiskFileItemFactory factory = new DiskFileItemFactory();
        PortletFileUpload pfu = new PortletFileUpload(factory);
        pfu.setSizeMax(1048576); // Maximum upload size 1Mb
        Iterator iter = pfu.parseRequest(request).iterator();
        while (iter.hasNext()) {
            FileItem item = (FileItem) iter.next();
            if (item.isFormField()) {// retrieve parameters if item is a form field
                if ("auth".equals(item.getFieldName())) {
                    if ("SAML".equals(item.getString())) {
                        samlUsed = true;
                    } else if ("P12".equals(item.getString())) {
                        p12Used = true;
                    } else if ("PEM".equals(item.getString())) {
                        pemUsed = true;
                    }
                } else if ("P12".equals(item.getFieldName())) {
                    p12Used = true;
                } else if ("P12".equals(item.getFieldName())) {
                    pemUsed = true;
                } else if ("host".equals(item.getFieldName())) {
                    host = item.getString();
                } else if ("port".equals(item.getFieldName())) {
                    portS = item.getString();
                } else if ("login".equals(item.getFieldName())) {
                    login = item.getString();
                } else if ("pass".equals(item.getFieldName())) {
                    pass = item.getString();
                } else if ("lifetime".equals(item.getFieldName())) {
                    lifetimeS = item.getString();
                } else if ("keyFilePass".equals(item.getFieldName())) {
                    keyPass = item.getString();
                } else if ("dnlogin".equals(item.getFieldName())) {
                    useDN = true;
                } else if ("p12FilePass".equals(item.getFieldName())) {
                    p12FilePass = item.getString();
                } else if ("RFCEnabled".equals(item.getFieldName())) {
                    RFCEnabled = true;
                }
            } else {
                if ("samlFile".equals(item.getFieldName())) {
                    samlFile = item;
                } else if ("p12File".equals(item.getFieldName())) {
                    p12File = item;
                }
                if ("keyFile".equals(item.getFieldName())) {
                    kf = item;
                } else if ("certFile".equals(item.getFieldName())) {
                    cf = item;
                }
            }
        }

        if (samlUsed) {
            uploadSaml(request, samlFile, request.getRemoteUser());
        } else if (p12Used) {
            uploadPem(request, p12File, p12FilePass, cf, host, portS, login, pass, lifetimeS, useDN, "p12",
                    RFCEnabled);
        } else if (pemUsed) {
            uploadPem(request, kf, keyPass, cf, host, portS, login, pass, lifetimeS, useDN, "pem", RFCEnabled);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:it.infn.ct.mi_parallel_portlet.java

/**
 * This method manages the user input fields managing two cases
 * distinguished by the type of the input <form ... statement The use of
 * upload file controls needs the use of "multipart/form-data" while the
 * else condition of the isMultipartContent check manages the standard input
 * case. The multipart content needs a manual processing of all <form items
 * All form' input items are identified by the 'name' input property inside
 * the jsp file/*from   ww w.  j a v  a 2s .  c  o  m*/
 * @param request ActionRequest instance (processAction)
 * @param appInput AppInput instance storing the jobSubmission data
 */
void getInputForm(ActionRequest request, AppInput appInput) {
    if (PortletFileUpload.isMultipartContent(request)) {
        try {
            FileItemFactory factory = new DiskFileItemFactory();
            PortletFileUpload upload = new PortletFileUpload(factory);
            List items = upload.parseRequest(request);
            File repositoryPath = new File("/tmp");
            DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory();
            diskFileItemFactory.setRepository(repositoryPath);
            Iterator iter = items.iterator();
            String logstring = "";
            int i = 0;
            int j = 0;
            while (iter.hasNext()) {
                FileItem item = (FileItem) iter.next();
                String fieldName = item.getFieldName();
                //                    String fileName = item.getName();
                //                    String contentType = item.getContentType();
                //                    boolean isInMemory = item.isInMemory();
                //                    long sizeInBytes = item.getSize();
                // Prepare a log string with field list
                logstring += LS + "field name: '" + fieldName + "' - '" + item.getString() + "'";
                switch (inputControlsIds.valueOf(fieldName)) {
                case JobIdentifier:
                    appInput.jobIdentifier = item.getString();
                    break;
                case collection_type:
                    appInput.collectionType = item.getString();
                    break;
                case task_number:
                    appInput.taskNumber = item.getString();
                    break;
                case parametric_executable:
                    appInput.executable = item.getString();
                    break;
                case executables:
                    appInput.executables.add(item.getString());
                    i++;
                    break;
                case argument:
                    appInput.arguments.add(item.getString());
                    j++;
                    break;
                case final_executable:
                    appInput.finalJobExecutable = item.getString();
                    break;
                case final_argument:
                    appInput.finalJobArgument = item.getString();
                    break;
                default:
                    _log.warn("Unhandled input field: '" + fieldName + "' - '" + item.getString() + "'");
                } // switch fieldName
            } // while iter.hasNext()   
            _log.info(LS + "Reporting" + LS + "---------" + LS + logstring + LS);
        } // try
        catch (Exception e) {
            _log.info("Caught exception while processing files to upload: '" + e.toString() + "'");
        }
    } // The input form do not use the "multipart/form-data" 
    else {
        // Retrieve from the input form the given application values
        appInput.jobIdentifier = (String) request.getParameter("JobIdentifier");
        appInput.collectionType = (String) request.getParameter("collection_type");
        appInput.taskNumber = (String) request.getParameter("task_number");

    } // ! isMultipartContent

    String tmp = "";
    for (int i = 0; i < appInput.executables.size(); i++) {
        if (!appInput.collectionType.equals("JOB_PARAMETRIC")) {
            tmp += LS + "executables[" + i + "]:" + appInput.executables.get(i) + "'";
        } else {
            tmp += LS + "executable:" + appInput.executable + "'";
        }
        tmp += LS + "arguments[" + i + "]:" + appInput.arguments.get(i) + "'";
    }
    // Show into the log the taken inputs
    _log.info(LS + "Taken input parameters:" + LS + "-----------------------"
    //                + LS + "inputFileName: '" + appInput.inputFileName + "'"
    //                + LS + "inputFileText: '" + appInput.inputFileText + "'"
            + LS + "jobIdentifier: '" + appInput.jobIdentifier + "'" + LS + "collectionType: '"
            + appInput.collectionType + "'" + LS + "taskNumber: '" + appInput.taskNumber + "'" + LS + tmp + LS
            + "finalJobExecutable: '" + appInput.finalJobExecutable + "'" + LS + "finalJobArgument: '"
            + appInput.finalJobArgument + "'" + LS);

}

From source file:hu.sztaki.lpds.pgportal.portlets.asm.SymbolMap.java

public void notdoUpload(ActionRequest request, ActionResponse response) throws PortletException {
    try {/*from www  .  j  a  v a2s .c o  m*/
        String jobport = "";
        String selected_wf = "";
        //getting upload parameters
        ActionRequest temp_req = request;

        DiskFileItemFactory factory = new DiskFileItemFactory();
        PortletFileUpload pfu = new PortletFileUpload(factory);

        List fileItems = pfu.parseRequest(temp_req);

        Iterator iter = fileItems.iterator();
        FileItem file2upload = null;
        while (iter.hasNext()) {
            FileItem item = (FileItem) iter.next();

            // retrieve hidden parameters if item is a form field
            if (item.isFormField()) {
                if (item.getFieldName().equals(new String("where2upload"))) {
                    jobport = item.getString();
                }
                if (item.getFieldName().startsWith(new String("instance_upload"))) {
                    selected_wf = item.getString();
                }
            } else {
                file2upload = item;
            }
        }

        String[] splitted = jobport.split("@");
        String selected_job = splitted[0];

        String selected_port = splitted[1];

        String userId = request.getRemoteUser();

        File uploadedFile = asm_service.uploadFiletoPortalServer(file2upload, userId, file2upload.getName());
        asm_service.placeUploadedFile(request.getRemoteUser(), uploadedFile, selected_wf, selected_job,
                selected_port);

    } catch (Exception ex) {
        ex.printStackTrace();
        Logger.getLogger(ASM_SamplePortlet.class.getName()).log(Level.SEVERE, null, ex);
    }

}