Package com.oreilly.servlet

Examples of com.oreilly.servlet.MultipartRequest


try {
  String contentType = this.myRequest.getContentType();
  RE r = new RE("multipart/form-data");
  if ( r.match (" " + contentType) ) {
    // We are dealing with a multipart form
    MultipartRequest formHandler = new MultipartRequest
          (this.myRequest, tmpDir);
    Enumeration paramList = formHandler.getParameterNames();
    for (; paramList.hasMoreElements() ;) {
      String paramName = (String) paramList.nextElement();
      myParameters.put (paramName,
        (String) formHandler.getParameter (paramName));
          }
    // Ok, and then , the we store the uploaded files
    paramList = formHandler.getFileNames();
    for (; paramList.hasMoreElements() ;) {
      String paramName = (String) paramList.nextElement();
      String fileName = null;
      fileName = formHandler.getFilesystemName (paramName);
      if ( fileName != null ) {
        myParameters.put (paramName, (String) fileName);
      }
          }
  }
View Full Code Here


          tmpFile.delete();
          File tmpDir = new File(tmpDirName);
          tmpDir.mkdir();     
          tmpDir.deleteOnExit();
          //anvil.Log.log().debug("tmpDir="+tmpDir.toString());
          _multi = new MultipartRequest(request, tmpDir.toString(), 32*1024*1024);

          enu = _multi.getParameterNames();
          while(enu.hasMoreElements()) {
            String name = (String)enu.nextElement();
            parseParameter(_parameters, name, _multi.getParameterValues(name));
View Full Code Here

   * @param iFileSizeLimit maximum size of a file
   * @return true if the request is indeed a file upload, the file size is <= iFileSizeLimit and the weather outside is fine 
   */
  public MultipartRequest initMultipartRequest(final String sTempDir, final int iFileSizeLimit) {
    try {
      this.mpRequest = new MultipartRequest(this.request, sTempDir, iFileSizeLimit);
    } catch (IOException ioe) {
      Log.log(Log.FINE, "lazyj.RequestWrapper", "initMultipartRequest", ioe); //$NON-NLS-1$ //$NON-NLS-2$
      this.mpRequest = null;
    }
       
View Full Code Here

         String name = "T" + System.currentTimeMillis();
         String tmpdir = "/tmp/" + name;
         Runtime.getRuntime().exec("mkdir -m 777 -p " + tmpdir).waitFor();

         PrintWriter sume;
         MultipartRequest multi =
            new MultipartRequest(request, tmpdir, 100*1024*1024); // 100MB

         out.println("<pre>");
         Enumeration params = multi.getParameterNames();
         while (params.hasMoreElements()) {
            String pname = (String) params.nextElement();
            String pval = (String) multi.getParameter(pname);
            out.println(pname + ": " + pval);
         }  
         out.println("</pre>");
         out.flush();
         String action = multi.getParameter("action");

         if (action.equals("createNewAdminApplication")) {
            /*     
               Profile prof = sess.getUserProfile();
               if (!prof.isAllowed("iwtAdmin-execute")) throw new AccessControlException("User " + uid + " does not have Admin privileges");
            */     
            createNewAdminApplication(multi, out);
         } else {  
            String project = multi.getParameter("project");
            if (project != null)
               project.trim();
            String app = multi.getParameter("app");
            String export = multi.getParameter("export");
            String filename = null;
      
            Enumeration files = multi.getFileNames();
            if (files.hasMoreElements()) {
               filename = multi.getFilesystemName((String)files.nextElement());
               monitor.log("MONITOR " + uid + "FileUpload as "+name+ " "+project+" using " + app );
               Runtime.getRuntime().exec("/usr/bin/chmod 644 " + tmpdir + "/" + filename).waitFor();
               //
               // NOTE: enable other upload options here for multipart files
               //
               if (multi.getParameter("tar") != null) {
                  sume = new PrintWriter(new BufferedWriter(new FileWriter(new File(tmpdir, GEP_SU_SCRIPT))));
                  sume.println("cd " + tmpdir);
                  sume.println("gunzip -c " + filename + " | tar xf -");
                  sume.println("chmod -R 644 .");
                  sume.close();
                  Runtime.getRuntime().exec("/usr/bin/chmod 755 " + tmpdir + "/" + GEP_SU_SCRIPT).waitFor();
                  Process zip = Runtime.getRuntime().exec("su - " + submit_uid + " -c " + tmpdir + "/" + GEP_SU_SCRIPT);
               }
            }
            if (action.equals("createNewProject")) {
               createNewProject(uid, submit_uid, home, tmpdir,
                                filename, project, app, export, request, out);
            } else if (action.equals("updateProject"))  {
               String id = multi.getParameter("id");
               updateProject(uid, submit_uid, home, id, tmpdir,
                             filename, project, app, export, request, response)
            } else {
               unknownAction(uid, response);
            }  
View Full Code Here

    String path = APP_HOME_DIR + name;
    File directory = new File(path);
    directory.mkdirs();
    Runtime.getRuntime().exec("/usr/bin/chmod 755 " + path).waitFor();
     
    MultipartRequest multi =
      new MultipartRequest(request, path, 100*1024*1024); // 100MB
    String name1 = multi.getParameter("name1").trim();
    //String name2 = multi.getParameter("name2").trim();
    String binary = multi.getParameter("binary").trim();
    String parallel = multi.getParameter("parallel");
    String xApp = multi.getParameter("xApp");
    String form = multi.getParameter("form");
    String namef = multi.getParameter("namef").trim();
    String export = multi.getParameter("export");
    String users = multi.getParameter("users").trim();
   
    htmlHeader(out, "New Application Status");
   
    Enumeration files = multi.getFileNames();
    if (files.hasMoreElements())
      if (multi.getParameter("tar") != null) {
        String filename = multi.getFilesystemName((String)files.nextElement());
        PrintWriter sume =
          new PrintWriter(new BufferedWriter(new FileWriter(new File(directory, SUNTCP_SU_SCRIPT))));
        sume.println("cd " + path);
        sume.println("gunzip -c " + filename + " | tar xf -");
        sume.close();
        Runtime.getRuntime().exec("/usr/bin/chmod 755 " + path + "/" + SUNTCP_SU_SCRIPT).waitFor();
        Runtime.getRuntime().exec("/usr/bin/chmod 644 " + path + "/" + filename).waitFor();
     
        Runtime.getRuntime().exec("/usr/bin/ksh exec " + path + "/" + SUNTCP_SU_SCRIPT).waitFor();
     
        if (form.equals("yes"))
          Runtime.getRuntime().exec("cp " + path + "/" + namef + " " + path + "/" + SUNTCP_APP_FORM);
      } else
        Runtime.getRuntime().exec("/usr/bin/chmod 755 " + path + "/" + binary).waitFor();
     
    if (name1.length() > 0) {
      String listfile = APP_HOME_DIR + SUNTCP_LIST;
      PrintWriter list =
        new PrintWriter(new BufferedWriter(new FileWriter(listfile, true)));
      list.print(name + "\t" + name1);
      if (multi.getParameter("acl") != null)
        list.print("\t" + users);
      list.println();
      list.close();

      PrintWriter ressource =
View Full Code Here

     
         String name = "T" + System.currentTimeMillis();
         String tmpdir = "/tmp/" + name;
         Runtime.getRuntime().exec("mkdir -m 777 -p " + tmpdir).waitFor();
         PrintWriter sume;
         MultipartRequest multi =
            new MultipartRequest(request, tmpdir, 100*1024*1024); // 100MB
         String action = multi.getParameter("action");
         String project = multi.getParameter("project").trim();
         String app = multi.getParameter("app");
         String export = multi.getParameter("export");
         String filename = null;
   
         Enumeration files = multi.getFileNames();
         if (files.hasMoreElements()) {
            filename = multi.getFilesystemName((String)files.nextElement());
            Runtime.getRuntime().exec("/usr/bin/chmod 644 " + tmpdir + "/" + filename).waitFor();
            if (multi.getParameter("tar") != null) {
               sume = new PrintWriter(new BufferedWriter(new FileWriter(new File(tmpdir, SUNTCP_SU_SCRIPT))));
               sume.println("cd " + tmpdir);
               sume.println("gunzip -c " + filename + " | tar xf -");
               sume.println("chmod -R 644 .");
               sume.close();
               Runtime.getRuntime().exec("/usr/bin/chmod 755 " + tmpdir + "/" + SUNTCP_SU_SCRIPT).waitFor();
               Process zip = Runtime.getRuntime().exec("su - " + submit_uid + " -c " + tmpdir + "/" + SUNTCP_SU_SCRIPT);
            }
         }
         if (action.equals("createNewProject")) {
            createNewProject(uid, submit_uid, home, tmpdir, filename, project, app, export, request, out);
         } else if (action.equals("updateProject"))  {
            String id = multi.getParameter("id");
            updateProject(uid, submit_uid, home, id, tmpdir, filename, project, app, export, request, response)
         } else {
            unknownAction(uid, response);
         }  
      } catch (Exception e) {
View Full Code Here

            }
       
            // Construct a MultipartRequest to help read the information.
            // Pass in the request, a directory to save files to, and the
            // maximum POST size we should attempt to handle.
            MultipartRequest multipartrequest =
                new MultipartRequest( request, stringWorkingDirectory, 5 * 1024 * 1024 );
           
            // Getting all file names from the request
            Enumeration files = multipartrequest.getFileNames();
           
            // Every received file will be converted to the specified type
            while (files.hasMoreElements()) {
                // Getting the name from the element
                String stringName = (String)files.nextElement();
       
                // Getting the filename from the request
                String stringFilename =
                    multipartrequest.getFilesystemName( stringName );
               
                // Converting the given file on the server to the specified type and
                // append a special extension
                File cleanupFile = null;
                String stringSourceFile = stringWorkingDirectory + stringFilename;
               
                try {
                    String stringConvertedFile = convertDocument(stringSourceFile,
                        multipartrequest.getParameter( "converttype" ),
                        multipartrequest.getParameter( "extension" ));
                   
                    String shortFileName = stringConvertedFile.substring(
                        stringConvertedFile.lastIndexOf('/') + 1);

                    // Set the response header
                    // Set the filename, is used when the file will be saved (problem with mozilla)
                    response.addHeader( "Content-Disposition",
                                        "attachment; filename=" + shortFileName);
               
                    // Constructing the multi part response to the client
                    MultipartResponse multipartresponse = new MultipartResponse(response);
               
                    // Is the convert type HTML?
                    if ( ( multipartrequest.getParameter( "converttype" ).equals(
                               "swriter: HTML (StarWriter)" ) )
                         || ( multipartrequest.getParameter( "converttype" ).equals(
                                  "scalc: HTML (StarCalc)" ) ) ) {
                        // Setting the content type of the response being sent to the client
                        // to text
                        multipartresponse.startResponse( "text/html" );
                    } else {
View Full Code Here

    return request.getContentType() != null && request.getContentType().startsWith(MULTIPART_CONTENT_TYPE);
  }

  public MultipartHttpServletRequest resolveMultipart(HttpServletRequest request) throws MultipartException {
    try {
      MultipartRequest multipartRequest = newMultipartRequest(request);
      if (logger.isDebugEnabled()) {
        Enumeration fileNames = multipartRequest.getFileNames();
        while (fileNames.hasMoreElements()) {
          String fileName = (String) fileNames.nextElement();
          File file = multipartRequest.getFile(fileName);
          logger.debug("Found multipart file '" + fileName + "' of size " + (file != null ? file.length() : 0) +
              " bytes with original filename [" + multipartRequest.getOriginalFileName(fileName) +
              "], " + (file != null ? "stored at [" + file.getAbsolutePath() + "]" : "empty"));
        }
      }
      return new CosMultipartHttpServletRequest(request, multipartRequest);
    }
View Full Code Here

   * @throws IOException if thrown by the MultipartRequest constructor
   */
  protected MultipartRequest newMultipartRequest(HttpServletRequest request) throws IOException {
    String tempPath = this.uploadTempDir.getAbsolutePath();
    String enc = determineEncoding(request);
    return new MultipartRequest(request, tempPath, this.maxUploadSize, enc);
  }
View Full Code Here

    }
    return enc;
  }

  public void cleanupMultipart(MultipartHttpServletRequest request) {
    MultipartRequest multipartRequest = ((CosMultipartHttpServletRequest) request).getMultipartRequest();
    Enumeration fileNames = multipartRequest.getFileNames();
    while (fileNames.hasMoreElements()) {
      String fileName = (String) fileNames.nextElement();
      File file = multipartRequest.getFile(fileName);
      if (file != null) {
        if (file.exists()) {
          if (file.delete()) {
            if (logger.isDebugEnabled()) {
            logger.debug("Cleaned up multipart file '" + fileName + "' with original filename [" +
                multipartRequest.getOriginalFileName(fileName) + "], stored at [" +
                file.getAbsolutePath() + "]");
            }
          }
          else {
            logger.warn("Could not delete multipart file '" + fileName + "' with original filename [" +
                multipartRequest.getOriginalFileName(fileName) + "], stored at [" +
                file.getAbsolutePath() + "]");
          }
        }
        else {
          if (logger.isDebugEnabled()) {
            logger.debug("Multipart file '" + fileName + "' with original filename [" +
                multipartRequest.getOriginalFileName(fileName) +
                "] has already been moved - no cleanup necessary");
          }
        }
      }
    }
View Full Code Here

TOP

Related Classes of com.oreilly.servlet.MultipartRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.