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

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


    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


      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);
      Assert.assertEquals(200, status);

      InputStream response = method.getResponseBodyAsStream();
View Full Code Here

      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));
     
      client.executeMethod(filePost);
     
      if (filePost.getStatusCode() != 200) {
          System.out.println(filePost.getResponseBodyAsString());
View Full Code Here

      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));
         
      client.executeMethod(filePost);
     
      if (filePost.getStatusCode() != 200) {
          Assert.fail("error occured");
View Full Code Here

        Part part2 = new StringPart("part2", "567890\r\n");
        Part part3 = new StringPart("part3", "3456\r\n");
       
        HttpMethodParams params = new HttpMethodParams();
        params.setBooleanParameter("testb", false);
        filePost.setRequestEntity(new MultipartRequestEntity(new Part[] {part1, part2, part3 }, params));
           
        client.executeMethod(filePost);
       
        if (filePost.getStatusCode() != 200) {
            Assert.fail("error occured");
View Full Code Here

      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());
      method.setRequestEntity(entity);
      int status = client.executeMethod(method);
      Assert.assertEquals(200, status);
      String responseBody = method.getResponseBodyAsString();
View Full Code Here

              createCustomerData("monica"));
      part1.setContentType("application/xml");
      partsList.add(part1);
      Part[] parts = partsList.toArray(new Part[partsList.size()]);
      PutMethod method = new PutMethod(uri);
      RequestEntity entity = new MultipartRequestEntity(parts, method
              .getParams());
      method.setRequestEntity(entity);
      int status = client.executeMethod(method);
      Assert.assertEquals(204, status);
      method.releaseConnection();
View Full Code Here

        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);
        Assert.assertEquals(getHttpMethodInfo(postMethod), HttpStatus.SC_CREATED, postMethod.getStatusCode());

        this.unmarshaller.unmarshal(postMethod.getResponseBodyAsStream());
View Full Code Here

            }

            // Set the multipart for the post
            int partNo = partlist.size();
            Part[] parts = partlist.toArray(new Part[partNo]);
            MultipartRequestEntity multiPart = new MultipartRequestEntity(parts, post.getParams());
            post.setRequestEntity(multiPart);

            // Set the content type
            String multiPartContentType = multiPart.getContentType();
            post.setRequestHeader(HEADER_CONTENT_TYPE, multiPartContentType);

            // If the Multipart is repeatable, we can send it first to
            // our own stream, without the actual file content, so we can return it
            if(multiPart.isRepeatable()) {
                // For all the file multiparts, we must tell it to not include
                // the actual file content
                for(int i = 0; i < partNo; i++) {
                    if(parts[i] instanceof ViewableFilePart) {
                        ((ViewableFilePart) parts[i]).setHideFileData(true); // .sendMultipartWithoutFileContent(bos);
                    }
                }
                // Write the request to our own stream
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                multiPart.writeRequest(bos);
                bos.flush();
                // We get the posted bytes using the encoding used to create it
                postedBody.append(new String(bos.toByteArray(),
                        contentEncoding == null ? "US-ASCII" // $NON-NLS-1$ this is the default used by HttpClient
                        : contentEncoding));
View Full Code Here

        }
            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);
        int responseStatus=httpClient.executeMethod(post);
       
View Full Code Here

TOP

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

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.