Package org.apache.http.entity.mime

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


                                    }
                                    meb.addPart(p.getName(), fb);
                                }
                            }
                           
                            reqBuilder.setEntity(meb.build());
                        }
                       
                       
                    }
                    catch (UnsupportedEncodingException ex) {
View Full Code Here


        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

        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);
            return result;
View Full Code Here

          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();

      assertThat(resEntity).isNotNull();
      String responseString = EntityUtils.toString(resEntity);
View Full Code Here

      builder.addTextBody("successnum", successNum.toString());
    }
    if (picNum != null) {
      builder.addTextBody("picnum", picNum.toString());
    }
    request.setEntity(builder.build());
    try {
      HttpResponse response = Http.CLIENT.execute(request);
      String json = IOUtils.toString(response.getEntity().getContent());
      return Result.parse(json, PicUploadResult.class);
    } catch (ClientProtocolException e) {
View Full Code Here

    addParameter(params, "format", "json");

    for (NameValuePair nameValuePair : params) {
      builder.addTextBody(nameValuePair.getName(), nameValuePair.getValue());
    }
    request.setEntity(builder.build());
    try {
      HttpResponse response = Http.CLIENT.execute(request);
      String json = IOUtils.toString(response.getEntity().getContent());
      JSONObject jsonObject = new JSONObject(json);
      Error error = Error.parse(jsonObject);
View Full Code Here

      }
    }
   
    entityBuilder.addBinaryBody(fileName, IOUtils.toByteArray(fileStream), ContentType.create(contentType), fileName);
   
    return entityBuilder.build();
  }
}
View Full Code Here

        final MultipartEntityBuilder builder = MultipartEntityBuilder.create();
        builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
        builder.addPart("upfile", fileBody);
        builder.addPart("text1", stringBody1);
        builder.addPart("text2", stringBody2);
        final HttpEntity entity = builder.build();
        post.setEntity(entity);
        response = client.execute(post);
        final int statusCode = response.getStatusLine().getStatusCode();
        final String responseString = getContent();
        final String contentTypeInHeader = getContentTypeHeader();
View Full Code Here

        final String message = "This is a multipart post";
        final MultipartEntityBuilder builder = MultipartEntityBuilder.create();
        builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
        builder.addBinaryBody("upfile", file, ContentType.DEFAULT_BINARY, TEXTFILENAME);
        builder.addTextBody("text", message, ContentType.DEFAULT_BINARY);
        final HttpEntity entity = builder.build();
        post.setEntity(entity);
        response = client.execute(post);
        final int statusCode = response.getStatusLine().getStatusCode();
        final String responseString = getContent();
        final String contentTypeInHeader = getContentTypeHeader();
View Full Code Here

        final MultipartEntityBuilder builder = MultipartEntityBuilder.create();
        builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
        builder.addBinaryBody("upfile", file, ContentType.DEFAULT_BINARY, IMAGEFILENAME);
        builder.addBinaryBody("upstream", inputStream, ContentType.create("application/zip"), ZIPFILENAME);
        builder.addTextBody("text", message, ContentType.TEXT_PLAIN);
        final HttpEntity entity = builder.build();
        post.setEntity(entity);
        response = client.execute(post);
        final int statusCode = response.getStatusLine().getStatusCode();
        final String responseString = getContent();
        final String contentTypeInHeader = getContentTypeHeader();
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.