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

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

Introduction

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

Prototype

public void setSizeMax(long sizeMax) 

Source Link

Document

Sets the maximum allowed upload size.

Usage

From source file:hu.sztaki.lpds.pgportal.portlets.workflow.WorkflowUploadPortlet.java

@Override
protected void doUpload(ActionRequest request, ActionResponse response) {
    PortletContext context = getPortletContext();
    context.log("[FileUploadPortlet] doUpload() called");

    try {/*  ww w.j  ava2 s  . co m*/
        DiskFileItemFactory factory = new DiskFileItemFactory();
        PortletFileUpload pfu = new PortletFileUpload(factory);
        pfu.setSizeMax(uploadMaxSize); // Maximum upload size
        pfu.setProgressListener((ProgressListener) new FileUploadProgressListener());

        PortletSession ps = request.getPortletSession();
        if (ps.getAttribute("uploads", ps.APPLICATION_SCOPE) == null)
            ps.setAttribute("uploads", new Hashtable<String, ProgressListener>());

        //get the FileItems
        String fieldName = null;

        List fileItems = pfu.parseRequest(request);
        Iterator iter = fileItems.iterator();
        File serverSideFile = null;
        Hashtable h = new Hashtable(); //fileupload
        while (iter.hasNext()) {
            FileItem item = (FileItem) iter.next();
            // retrieve hidden parameters if item is a form field
            if (item.isFormField()) {
                fieldName = item.getFieldName();
                if ("newGrafName".equals(fieldName))
                    h.put("newGrafName", item.getString());
                if ("newAbstName".equals(fieldName))
                    h.put("newAbstName", item.getString());
                if ("newRealName".equals(fieldName))
                    h.put("newRealName", item.getString());
            } else { // item is not a form field, do file upload
                Hashtable<String, ProgressListener> tmp = (Hashtable<String, ProgressListener>) ps
                        .getAttribute("uploads");//,ps.APPLICATION_SCOPE
                pfu.setProgressListener((ProgressListener) new FileUploadProgressListener());

                String s = item.getName();
                s = FilenameUtils.getName(s);
                ProgressListener pl = pfu.getProgressListener();
                tmp.put(s, pl);
                ps.setAttribute("uploads", tmp);

                String tempDir = System.getProperty("java.io.tmpdir") + "/uploads/" + request.getRemoteUser();
                File f = new File(tempDir);
                if (!f.exists())
                    f.mkdirs();
                serverSideFile = new File(tempDir, s);
                item.write(serverSideFile);
                item.delete();
                context.log("[FileUploadPortlet] - file " + s + " uploaded successfully to " + tempDir);
            }
        }
        // file upload to storage
        try {
            ServiceType st = InformationBase.getI().getService("wfs", "portal", new Hashtable(), new Vector());
            h.put("senderObj", "ZipFileSender");
            h.put("portalURL", PropertyLoader.getInstance().getProperty("service.url"));
            h.put("wfsID", st.getServiceUrl());
            h.put("userID", request.getRemoteUser());

            Hashtable hsh = new Hashtable();
            //                    st = InformationBase.getI().getService("storage", "portal", hsh, new Vector());
            //                    hsh.put("url", "http://localhost:8080/storage");
            st = InformationBase.getI().getService("storage", "portal", hsh, new Vector());
            PortalStorageClient psc = (PortalStorageClient) Class.forName(st.getClientObject()).newInstance();
            psc.setServiceURL(st.getServiceUrl());
            psc.setServiceID("/receiver");
            if (serverSideFile != null)
                psc.fileUpload(serverSideFile, "fileName", h);
        } catch (Exception ex) {
            response.setRenderParameter("full", "error.upload");
            ex.printStackTrace();
            return;
        }
        ps.removeAttribute("uploads", ps.APPLICATION_SCOPE);

    } catch (FileUploadException fue) {
        response.setRenderParameter("full", "error.upload");

        fue.printStackTrace();
        context.log("[FileUploadPortlet] - failed to upload file - " + fue.toString());
        return;
    } catch (Exception e) {
        e.printStackTrace();
        response.setRenderParameter("full", "error.exception");
        context.log("[FileUploadPortlet] - failed to upload file - " + e.toString());
        return;
    }
    response.setRenderParameter("full", "action.succesfull");
}

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

/**
 * Uploading SAML file(s)./*from   www. ja v a2s .  co  m*/
 * The parameters are filled in by the user on the saml/UploadAssertion.jsp page.
 * @param request ActionRequest
 * @param response ActionResponse
 */
@Override
public synchronized void doUpload(ActionRequest request, ActionResponse response) {
    logger.trace("");

    // logger.info("Assertion-doUpload");
    FileItem samlFile = null;
    String sresource = null; // selected resource
    String action = request.getParameter("guse");
    logger.info("Action:" + action);

    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 ("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 msg : result) {
            if (flag) {
                sb.append("<br />");
            } else {
                flag = true;
            }
            sb.append(msg);
        }
        request.setAttribute("msg", sb.toString());
    } catch (Exception e) {
        request.setAttribute("msg", "Upload failed. Reason: " + e.getMessage());
        logger.info("Upload of asseriont failed. Reason: " + e.getMessage());
        logger.debug("Exception:", e);
    }
}

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/*from www. j a  v  a2 s.c  o 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:hu.sztaki.lpds.pgportal.portlets.workflow.RealWorkflowPortlet.java

@Override
public void doUpload(ActionRequest request, ActionResponse response) {
    PortletContext context = getPortletContext();
    context.log("[FileUploadPortlet] doUpload() called");

    try {/*from www.  j  a  va2 s . c  o m*/
        DiskFileItemFactory factory = new DiskFileItemFactory();
        PortletFileUpload pfu = new PortletFileUpload(factory);
        pfu.setSizeMax(uploadMaxSize); // Maximum upload size
        pfu.setProgressListener((ProgressListener) new FileUploadProgressListener());

        PortletSession ps = request.getPortletSession();
        if (ps.getAttribute("uploaded") == null)
            ps.setAttribute("uploaded", new Vector<String>());
        ps.setAttribute("upload", pfu);

        //get the FileItems
        String fieldName = null;

        List fileItems = pfu.parseRequest(request);
        Iterator iter = fileItems.iterator();
        File serverSideFile = null;
        while (iter.hasNext()) {
            FileItem item = (FileItem) iter.next();
            // retrieve hidden parameters if item is a form field
            if (item.isFormField()) {
                fieldName = item.getFieldName();
            } else { // item is not a form field, do file upload
                Hashtable<String, ProgressListener> tmp = (Hashtable<String, ProgressListener>) ps
                        .getAttribute("uploads", ps.APPLICATION_SCOPE);

                String s = item.getName();
                s = FilenameUtils.getName(s);
                ps.setAttribute("uploading", s);

                String tempDir = System.getProperty("java.io.tmpdir") + "/uploads/" + request.getRemoteUser();
                File f = new File(tempDir);
                if (!f.exists())
                    f.mkdirs();
                serverSideFile = new File(tempDir, s);
                item.write(serverSideFile);
                item.delete();
                context.log("[FileUploadPortlet] - file " + s + " uploaded successfully to " + tempDir);
                // file upload to storage
                try {
                    Hashtable h = new Hashtable();
                    h.put("portalURL", PropertyLoader.getInstance().getProperty("service.url"));
                    h.put("userID", request.getRemoteUser());

                    String uploadField = "";
                    // retrieve hidden parameters if item is a form field
                    for (FileItem item0 : (List<FileItem>) fileItems) {
                        if (item0.isFormField())
                            h.put(item0.getFieldName(), item0.getString());
                        else
                            uploadField = item0.getFieldName();

                    }

                    Hashtable hsh = new Hashtable();
                    ServiceType st = InformationBase.getI().getService("storage", "portal", hsh, new Vector());
                    PortalStorageClient psc = (PortalStorageClient) Class.forName(st.getClientObject())
                            .newInstance();
                    psc.setServiceURL(st.getServiceUrl());
                    psc.setServiceID("/upload");
                    if (serverSideFile != null) {
                        psc.fileUpload(serverSideFile, uploadField, h);
                    }
                } catch (Exception ex) {
                    response.setRenderParameter("full", "error.upload");
                    ex.printStackTrace();
                    return;
                }
                ((Vector<String>) ps.getAttribute("uploaded")).add(s);

            }

        }
        //            ps.removeAttribute("uploads",ps.APPLICATION_SCOPE);
        ps.setAttribute("finaluploads", "");

    } catch (FileUploadException fue) {
        response.setRenderParameter("full", "error.upload");

        fue.printStackTrace();
        context.log("[FileUploadPortlet] - failed to upload file - " + fue.toString());
        return;
    } catch (Exception e) {
        e.printStackTrace();
        response.setRenderParameter("full", "error.exception");
        context.log("[FileUploadPortlet] - failed to upload file - " + e.toString());
        return;
    }
    response.setRenderParameter("full", "action.succesfull");

}

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).//  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:hu.sztaki.lpds.pgportal.portlets.workflow.EasyWorkflowPortlet.java

@Override
public void doUpload(ActionRequest request, ActionResponse response) {
    PortletContext context = getPortletContext();
    context.log("[FileUploadPortlet] doUpload() called");

    try {//w w w  .jav  a 2 s.  co m
        DiskFileItemFactory factory = new DiskFileItemFactory();
        PortletFileUpload pfu = new PortletFileUpload(factory);
        pfu.setSizeMax(uploadMaxSize); // Maximum upload size
        pfu.setProgressListener((ProgressListener) new FileUploadProgressListener());

        PortletSession ps = request.getPortletSession();
        if (ps.getAttribute("uploaded") == null)
            ps.setAttribute("uploaded", new Vector<String>());
        ps.setAttribute("upload", pfu);

        //get the FileItems
        String fieldName = null;

        List fileItems = pfu.parseRequest(request);
        Iterator iter = fileItems.iterator();
        File serverSideFile = null;
        while (iter.hasNext()) {
            FileItem item = (FileItem) iter.next();
            // retrieve hidden parameters if item is a form field
            if (item.isFormField()) {
                fieldName = item.getFieldName();
            } else { // item is not a form field, do file upload
                Hashtable<String, ProgressListener> tmp = (Hashtable<String, ProgressListener>) ps
                        .getAttribute("uploads", ps.APPLICATION_SCOPE);

                String s = item.getName();
                s = FilenameUtils.getName(s);
                ps.setAttribute("uploading", s);

                String tempDir = System.getProperty("java.io.tmpdir") + "/uploads/" + request.getRemoteUser();
                File f = new File(tempDir);
                if (!f.exists())
                    f.mkdirs();
                serverSideFile = new File(tempDir, s);
                item.write(serverSideFile);
                item.delete();
                context.log("[FileUploadPortlet] - file " + s + " uploaded successfully to " + tempDir);
                // file upload to storage
                try {
                    Hashtable h = new Hashtable();
                    h.put("portalURL", PropertyLoader.getInstance().getProperty("service.url"));
                    h.put("userID", request.getRemoteUser());

                    String uploadField = "";
                    // retrieve hidden parameters if item is a form field
                    for (FileItem item0 : (List<FileItem>) fileItems) {
                        if (item0.isFormField())
                            h.put(item0.getFieldName(), item0.getString());
                        else
                            uploadField = item0.getFieldName();

                    }

                    Hashtable hsh = new Hashtable();
                    ServiceType st = InformationBase.getI().getService("storage", "portal", hsh, new Vector());
                    PortalStorageClient psc = (PortalStorageClient) Class.forName(st.getClientObject())
                            .newInstance();
                    psc.setServiceURL(st.getServiceUrl());
                    psc.setServiceID("/upload");
                    if (serverSideFile != null) {
                        psc.fileUpload(serverSideFile, uploadField, h);
                    }
                } catch (Exception ex) {
                    response.setRenderParameter("full", "error.upload");
                    ex.printStackTrace();
                    return;
                }
                ((Vector<String>) ps.getAttribute("uploaded")).add(s);

            }

        }
        //            ps.removeAttribute("uploads",ps.APPLICATION_SCOPE);
        ps.setAttribute("finaluploads", "");

    } catch (SizeLimitExceededException see) {
        response.setRenderParameter("full", "error.upload.sizelimit");
        request.getPortletSession().setAttribute("finaluploads", "");
        see.printStackTrace();
        context.log("[FileUploadPortlet] - failed to upload file - " + see.toString());
        return;
    } catch (FileUploadException fue) {
        response.setRenderParameter("full", "error.upload");

        fue.printStackTrace();
        context.log("[FileUploadPortlet] - failed to upload file - " + fue.toString());
        return;
    } catch (Exception e) {
        e.printStackTrace();
        response.setRenderParameter("full", "error.exception");
        context.log("[FileUploadPortlet] - failed to upload file - " + e.toString());
        return;
    }
    response.setRenderParameter("full", "action.succesfull");

}

From source file:hu.sztaki.lpds.pgportal.portlets.file.LFCFileStoragePortlet.java

@Override
public void processAction(ActionRequest request, ActionResponse response) throws PortletException {
    try {// w w  w. j a  v a 2  s.co m
        String userId = request.getRemoteUser();

        /*      if(request.getAttribute(SportletProperties.ACTION_EVENT)!=null)
        action=(""+request.getAttribute(SportletProperties.ACTION_EVENT)).split("=")[1];
         */
        String action = null;
        if ((request.getParameter("action") != null) && (!request.getParameter("action").equals(""))) {
            action = request.getParameter("action");
        }

        if (PortletFileUpload.isMultipartContent(request)) {

            DiskFileItemFactory factory = new DiskFileItemFactory();
            PortletFileUpload pfu = new PortletFileUpload(factory);
            pfu.setSizeMax(10485760); // Maximum upload size
            //pfu.setProgressListener(new FileUploadProgressListener());
            /*   PortletSession ps = request.getPortletSession();
               ps.setAttribute("upload", pfu, ps.APPLICATION_SCOPE);
               String actionName = null;*/
            String fieldName;
            List fileItems = pfu.parseRequest(request);
            Iterator iter = fileItems.iterator();
            HashMap params = new HashMap();
            while (iter.hasNext()) {
                FileItem item = (FileItem) iter.next();
                // retrieve hidden parameters if item is a form field
                if (item.isFormField()) {
                    //getting parameters
                    fieldName = item.getFieldName();
                    //      System.out.println("Name is : " + fieldName + "   value is : " + item.getString());
                    if (item.getFieldName().equals(new String("SEListBoxBean_select"))) {
                        params.put("se", item.getString());
                    }
                    if (item.getFieldName().equals(new String("uploadName"))) {
                        params.put("upName", item.getString());
                    }
                    if (item.getFieldName().equals(new String("ownRead"))) {
                        params.put("urBean", item.getString());
                    }
                    if (item.getFieldName().equals(new String("ownWrite"))) {
                        params.put("uwBean", item.getString());
                    }
                    if (item.getFieldName().equals(new String("ownExecute"))) {
                        params.put("uxBean", item.getString());
                    }
                    if (item.getFieldName().equals(new String("grRead"))) {
                        params.put("grBean", item.getString());
                    }
                    if (item.getFieldName().equals(new String("grWrite"))) {
                        params.put("gwBean", item.getString());
                    }
                    if (item.getFieldName().equals(new String("grExecute"))) {
                        params.put("gxBean", item.getString());
                    }
                    if (item.getFieldName().equals(new String("othRead"))) {
                        params.put("orBean", item.getString());
                    }
                    if (item.getFieldName().equals(new String("othWrite"))) {
                        params.put("owBean", item.getString());
                    }
                    if (item.getFieldName().equals(new String("othExecute"))) {
                        params.put("oxBean", item.getString());
                    }

                } else { // item is not a form field, do file upload
                    String s = item.getName();
                    s = FilenameUtils.getName(s);
                    String tempDir = System.getProperty("java.io.tmpdir") + "/uploads/"
                            + request.getRemoteUser();
                    String origfile = tempDir + "/" + s;
                    params.put("origfile", origfile);

                    File f = new File(tempDir);
                    if (!f.exists())
                        f.mkdirs();
                    File serverSideFile = new File(tempDir, s);
                    item.write(serverSideFile);
                    item.delete();

                }
            }
            if (action == null) {
                doUpload(request, response, params);
            }
        }

        if (action != null) {
            try {
                Method method = this.getClass().getMethod(action,
                        new Class[] { ActionRequest.class, ActionResponse.class });
                method.invoke(this, new Object[] { request, response });
            } catch (IllegalArgumentException ex) {

                Logger.getLogger(LFCFileStoragePortlet.class.getName()).log(Level.SEVERE, null, ex);
            } catch (InvocationTargetException ex) {

                Logger.getLogger(LFCFileStoragePortlet.class.getName()).log(Level.SEVERE, null, ex);
            } catch (NoSuchMethodException e) {
                System.out.println("-----------------------Nincs ilyen metdus:");
            } catch (IllegalAccessException e) {
                System.out.println("----------------------Nincs jogod a metdushoz");
            }
        }
        PortletMode pMode = request.getPortletMode();
        // upload -- enctype="multipart/form-data"

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

From source file:org.apache.tapestry5.portlet.multipart.PortletMultipartDecoderImpl.java

private PortletFileUpload createFileUpload() {

    PortletFileUpload upload = new PortletFileUpload(_fileItemFactory);

    // set maximum file upload size
    upload.setSizeMax(_maxRequestSize);
    upload.setFileSizeMax(_maxFileSize);

    return upload;
}

From source file:org.apache.tapestry5.portlet.upload.internal.services.PortletMultipartDecoderImpl.java

private PortletFileUpload createPortletFileUpload() {

    PortletFileUpload upload = new PortletFileUpload(fileItemFactory);

    // set maximum file upload size
    upload.setSizeMax(maxRequestSize);
    upload.setFileSizeMax(maxFileSize);/*from   w  w w  . ja v a2 s.  co m*/

    return upload;
}

From source file:org.danann.cernunnos.runtime.web.CernunnosPortlet.java

@SuppressWarnings("unchecked")
private void runScript(URL u, PortletRequest req, PortletResponse res, RuntimeRequestResponse rrr) {

    // Choose the right Task...
    Task k = getTask(u);/* w w w.  j  a v  a2s  .co m*/

    // Basic, guaranteed request attributes...
    rrr.setAttribute(WebAttributes.REQUEST, req);
    rrr.setAttribute(WebAttributes.RESPONSE, res);

    // Also let's check the request for multi-part form 
    // data & convert to request attributes if we find any...
    List<InputStream> streams = new LinkedList<InputStream>();
    if (req instanceof ActionRequest && PortletFileUpload.isMultipartContent((ActionRequest) req)) {

        if (log.isDebugEnabled()) {
            log.debug("Multipart form data detected (preparing to process).");
        }

        try {
            final DiskFileItemFactory fac = new DiskFileItemFactory();
            final PortletFileUpload pfu = new PortletFileUpload(fac);
            final long maxSize = pfu.getFileSizeMax(); // FixMe!!
            pfu.setFileSizeMax(maxSize);
            pfu.setSizeMax(maxSize);
            fac.setSizeThreshold((int) (maxSize + 1L));
            List<FileItem> items = pfu.parseRequest((ActionRequest) req);
            for (FileItem f : items) {
                if (log.isDebugEnabled()) {
                    log.debug("Processing file upload:  name='" + f.getName() + "',fieldName='"
                            + f.getFieldName() + "'");
                }
                InputStream inpt = f.getInputStream();
                rrr.setAttribute(f.getFieldName(), inpt);
                rrr.setAttribute(f.getFieldName() + "_FileItem", f);
                streams.add(inpt);
            }
        } catch (Throwable t) {
            String msg = "Cernunnos portlet failed to process multipart " + "form data from the request.";
            throw new RuntimeException(msg, t);
        }

    } else {

        if (log.isDebugEnabled()) {
            log.debug("Multipart form data was not detected.");
        }
    }

    // Anything that should be included from the spring_context?
    if (spring_context != null && spring_context.containsBean("requestAttributes")) {
        Map<String, Object> requestAttributes = (Map<String, Object>) spring_context
                .getBean("requestAttributes");
        for (Map.Entry entry : requestAttributes.entrySet()) {
            rrr.setAttribute((String) entry.getKey(), entry.getValue());
        }
    }

    runner.run(k, rrr);

    // Clean up resources...
    if (streams.size() > 0) {
        try {
            for (InputStream inpt : streams) {
                inpt.close();
            }
        } catch (Throwable t) {
            String msg = "Cernunnos portlet failed to release resources.";
            throw new RuntimeException(msg, t);
        }
    }

}