Package org.apache.commons.httpclient.methods.multipart

Examples of org.apache.commons.httpclient.methods.multipart.FilePart


  private void processMultipartRequest(ModelMap<String, Object> parameters,
      PostMethod postMethod, File[] files) throws FileNotFoundException {
    List<Part> parts = new ArrayList<Part>();
    int index = 0;
    for (File f : files) {
      parts.add(new FilePart("file_" + index++, f.getName(), f));
    }
    postMethod.setRequestEntity(new MultipartRequestEntity(parts
        .toArray(new Part[] {}), postMethod.getParams()));
  }
View Full Code Here


   {
      HttpClient client = new HttpClient();
      List<Part> partsList = new ArrayList<Part>();
      partsList.add(new StringPart("part1", "This is Value 1"));
      partsList.add(new StringPart("part2", "This is Value 2"));
      partsList.add(new FilePart("data.txt", LocateTestData.getTestData("data.txt")));
      Part[] parts = partsList.toArray(new Part[partsList.size()]);
      PostMethod method = new PostMethod(TEST_URI);
      RequestEntity entity = new MultipartRequestEntity(parts, method.getParams());
      method.setRequestEntity(entity);
      int status = client.executeMethod(method);
View Full Code Here

                                             new UsernamePasswordCredentials(userNameAndPassword[0],
                                                                             userNameAndPassword[1]));
        }

        for (Map.Entry<String, byte[]> e : uploads.entrySet()) {
            method.addPart(new FilePart("filepath",
                           new ByteArrayPartSource(e.getKey(), e.getValue())));
        }
        client.executeMethod(method);
        return method;
    }
View Full Code Here

             
      PostMethod filePost = new PostMethod("http://localhost:" + server.getLocalPort() + "/");
      org.apache.commons.httpclient.HttpClient client = new org.apache.commons.httpclient.HttpClient();
     
      File file = QAUtil.createTestfile_4k();
      Part part = new FilePart("file4k", file);
     
      HttpMethodParams params = new HttpMethodParams();
      params.setBooleanParameter("testb", false);
      filePost.setRequestEntity(new MultipartRequestEntity(new Part[] {part }, params));
     
View Full Code Here

      org.apache.commons.httpclient.HttpClient client = new org.apache.commons.httpclient.HttpClient();
     
      File file1 = QAUtil.createTestfile_40k();
      File file2 = QAUtil.createTestfile_4k();
     
      Part part1 = new FilePart("file40k", file1);
      Part part2 = new FilePart("file4k", file2);
         
      HttpMethodParams params = new HttpMethodParams();
      params.setBooleanParameter("testb", false);
      filePost.setRequestEntity(new MultipartRequestEntity(new Part[] {part1, part2 }, params));
         
View Full Code Here

   {
      HttpClient client = new HttpClient();
      List<Part> partsList = new ArrayList<Part>();
      partsList.add(new StringPart("part1", "This is Value 1"));
      partsList.add(new StringPart("part2", "This is Value 2"));
      partsList.add(new FilePart("data.txt", LocateTestData
              .getTestData("data.txt")));
      Part[] parts = partsList.toArray(new Part[partsList.size()]);
      PutMethod method = new PutMethod(TEST_URI);
      RequestEntity entity = new MultipartRequestEntity(parts, method
              .getParams());
View Full Code Here

        httpClient.getParams().setAuthenticationPreemptive(true);

        Part[] parts = new Part[1];

        ByteArrayPartSource baps = new ByteArrayPartSource(attachmentName, content.getBytes());
        parts[0] = new FilePart(attachmentName, baps);

        PostMethod postMethod = new PostMethod(attachmentsUri);
        MultipartRequestEntity mpre = new MultipartRequestEntity(parts, postMethod.getParams());
        postMethod.setRequestEntity(mpre);
        httpClient.executeMethod(postMethod);
View Full Code Here

                            + property.getValue().getClass());
                }
        }
            File f = new File(fileInfo.getLocation());
            if (f.isFile()) {
                parts.add(new FilePart(fileInfo.getName(), f));
            }
            post.setRequestEntity(new MultipartRequestEntity(parts.toArray(new Part[parts.size()]), post
                    .getParams()));
        httpClient.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(repositoryInfo.getUsername(),repositoryInfo.getPassword()));
        httpClient.getParams().setAuthenticationPreemptive(true);
View Full Code Here

            partList.add(new StringPart("action", "install"));
            partList.add(new StringPart("_noredir_", "_noredir_"));
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            IOUtils.copy(in, baos);
            PartSource partSource = new ByteArrayPartSource(fileName, baos.toByteArray());
            partList.add(new FilePart("bundlefile", partSource));
            partList.add(new StringPart("bundlestart", "start"));

            Part[] parts = partList.toArray(new Part[partList.size()]);

            filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams()));
View Full Code Here

        new LocalBundleInstaller(getHttpClient(), repositoryInfo) {

            @Override
            void configureRequest(PostMethod method) throws IOException {

                Part[] parts = new Part[] { new FilePart("bundle", new ByteArrayPartSource("bundle.jar",
                        IOUtils.toByteArray(jarredBundle))) };
                method.setRequestEntity(new MultipartRequestEntity(parts, method.getParams()));
            }
        }.installBundle();       
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.httpclient.methods.multipart.FilePart

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.