Package org.apache.http.entity.mime

Examples of org.apache.http.entity.mime.MultipartEntityBuilder.addPart()


      builder.addPart("extMethod", new StringBody("uploadTest",
          ContentType.DEFAULT_TEXT));
      builder.addPart("extType", new StringBody("rpc", ContentType.DEFAULT_TEXT));
      builder.addPart("extUpload", new StringBody("true", ContentType.DEFAULT_TEXT));

      builder.addPart(
          "name",
          new StringBody("Jimöäü", ContentType.create("text/plain",
              Charset.forName("UTF-8"))));
      builder.addPart("firstName",
          new StringBody("Ralph", ContentType.DEFAULT_TEXT));
View Full Code Here


      builder.addPart(
          "name",
          new StringBody("Jimöäü", ContentType.create("text/plain",
              Charset.forName("UTF-8"))));
      builder.addPart("firstName",
          new StringBody("Ralph", ContentType.DEFAULT_TEXT));
      builder.addPart("age", new StringBody("25", ContentType.DEFAULT_TEXT));
      builder.addPart("email", new StringBody("test@test.ch",
          ContentType.DEFAULT_TEXT));
View Full Code Here

          "name",
          new StringBody("Jimöäü", ContentType.create("text/plain",
              Charset.forName("UTF-8"))));
      builder.addPart("firstName",
          new StringBody("Ralph", ContentType.DEFAULT_TEXT));
      builder.addPart("age", new StringBody("25", ContentType.DEFAULT_TEXT));
      builder.addPart("email", new StringBody("test@test.ch",
          ContentType.DEFAULT_TEXT));

      post.setEntity(builder.build());
      response = client.execute(post);
View Full Code Here

          new StringBody("Jimöäü", ContentType.create("text/plain",
              Charset.forName("UTF-8"))));
      builder.addPart("firstName",
          new StringBody("Ralph", ContentType.DEFAULT_TEXT));
      builder.addPart("age", new StringBody("25", ContentType.DEFAULT_TEXT));
      builder.addPart("email", new StringBody("test@test.ch",
          ContentType.DEFAULT_TEXT));

      post.setEntity(builder.build());
      response = client.execute(post);
      HttpEntity resEntity = response.getEntity();
View Full Code Here

                                        sb = new StringBody(body, HTTPClientUtil.getContentType(ct));
                                    }
                                    else {
                                        sb = new StringBody(body, org.apache.http.entity.ContentType.DEFAULT_TEXT);
                                    }
                                    meb.addPart(part.getName(), sb);
                                }
                                else if(part instanceof ReqEntityFilePart) {
                                    ReqEntityFilePart p = (ReqEntityFilePart)part;
                                    File body = p.getPart();
                                    ContentType ct = p.getContentType();
View Full Code Here

                                        fb = new FileBody(body, HTTPClientUtil.getContentType(ct), p.getFilename());
                                    }
                                    else {
                                        fb = new FileBody(body, org.apache.http.entity.ContentType.DEFAULT_BINARY, p.getFilename());
                                    }
                                    meb.addPart(p.getName(), fb);
                                }
                            }
                           
                            reqBuilder.setEntity(meb.build());
                        }
View Full Code Here

    private HttpEntity createHttpEntity(String name, URL archiveUrl) throws OpenESBClientException {
        try {
            MultipartEntityBuilder multipartEntity = MultipartEntityBuilder.create();
            multipartEntity.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
            multipartEntity.addPart(name, new FileBody(new File(archiveUrl.toURI())));

            return multipartEntity.build();
        } catch (URISyntaxException ex) {
            logger.log(Level.SEVERE, "Unable to create an HTTP entity to upload file : " + archiveUrl, ex);
            throw new OpenESBClientException("Unable to create an HTTP entity to upload file : " + archiveUrl, ex);
View Full Code Here

    public String uploadFile(String uri, String partName, String filename, String mimeType, byte[] contents, int expectedResponseCode) throws URISyntaxException, IOException {
        try (CloseableHttpClient client = HttpClients.createDefault()) {
            HttpPost post = new HttpPost(uri);
            ByteArrayBody contentBody = new ByteArrayBody(contents, ContentType.create(mimeType), filename);
            MultipartEntityBuilder builder = MultipartEntityBuilder.create();
            builder.addPart(partName, contentBody);
            post.setEntity(builder.build());
            HttpResponse response = client.execute(post);
            String result = EntityUtils.toString(response.getEntity());
            int statusCode = response.getStatusLine().getStatusCode();
            Assert.assertEquals(String.format("Invalid response code, %s", statusCode), expectedResponseCode, statusCode);
View Full Code Here

      is = getClass().getResourceAsStream("/UploadTestFile.txt");

      MultipartEntityBuilder builder = MultipartEntityBuilder.create();
      ContentBody cbFile = new InputStreamBody(is,
          ContentType.create("text/plain"), "UploadTestFile.txt");
      builder.addPart("fileUpload", cbFile);
      builder.addPart("extTID", new StringBody("2", ContentType.DEFAULT_TEXT));
      builder.addPart("extAction", new StringBody("fileUploadController",
          ContentType.DEFAULT_TEXT));
      builder.addPart("extMethod", new StringBody("uploadTest",
          ContentType.DEFAULT_TEXT));
View Full Code Here

      MultipartEntityBuilder builder = MultipartEntityBuilder.create();
      ContentBody cbFile = new InputStreamBody(is,
          ContentType.create("text/plain"), "UploadTestFile.txt");
      builder.addPart("fileUpload", cbFile);
      builder.addPart("extTID", new StringBody("2", ContentType.DEFAULT_TEXT));
      builder.addPart("extAction", new StringBody("fileUploadController",
          ContentType.DEFAULT_TEXT));
      builder.addPart("extMethod", new StringBody("uploadTest",
          ContentType.DEFAULT_TEXT));
      builder.addPart("extType", new StringBody("rpc", ContentType.DEFAULT_TEXT));
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.