use of org.apache.http.entity.mime.content.FileBody in project incubator-heron by apache.
the class HttpUploader method uploadPackageAndGetURI.
private URI uploadPackageAndGetURI(final CloseableHttpClient httpclient) throws IOException, URISyntaxException {
File file = new File(this.topologyPackageLocation);
String uploaderUri = HttpUploaderContext.getHeronUploaderHttpUri(this.config);
post = new HttpPost(uploaderUri);
FileBody fileBody = new FileBody(file, ContentType.DEFAULT_BINARY);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
builder.addPart(FILE, fileBody);
HttpEntity entity = builder.build();
post.setEntity(entity);
HttpResponse response = execute(httpclient);
String responseString = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8.name());
LOG.fine("Topology package download URI: " + responseString);
return new URI(responseString);
}
use of org.apache.http.entity.mime.content.FileBody in project ninja by ninjaframework.
the class NinjaTestBrowser method uploadFile.
public String uploadFile(String url, String paramName, File fileToUpload) {
String response = null;
try {
httpClient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
HttpPost post = new HttpPost(url);
MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
// For File parameters
entity.addPart(paramName, new FileBody((File) fileToUpload));
post.setEntity(entity);
// Here we go!
response = EntityUtils.toString(httpClient.execute(post).getEntity(), "UTF-8");
post.releaseConnection();
} catch (Exception e) {
throw new RuntimeException(e);
}
return response;
}
use of org.apache.http.entity.mime.content.FileBody in project streamsx.topology by IBMStreams.
the class StreamingAnalyticsServiceV1 method submitBuild.
@Override
protected JsonObject submitBuild(CloseableHttpClient httpclient, File archive, String buildName, String originator) throws /*unused*/
IOException {
String newBuildURL = getBuildsUrl(httpclient) + "?build_name=" + URLEncoder.encode(buildName, StandardCharsets.UTF_8.name());
HttpPost httppost = new HttpPost(newBuildURL);
httppost.addHeader("Authorization", getAuthorization());
FileBody archiveBody = new FileBody(archive, ContentType.create("application/zip"));
HttpEntity reqEntity = MultipartEntityBuilder.create().addPart(archive.getName(), archiveBody).build();
httppost.setEntity(reqEntity);
JsonObject jso = StreamsRestUtils.getGsonResponse(httpclient, httppost);
JsonObject build = object(jso, "build");
return build;
}
use of org.apache.http.entity.mime.content.FileBody in project undertow by undertow-io.
the class MultiPartTestCase method testMultiPartIndividualFileToLarge.
@Test
public void testMultiPartIndividualFileToLarge() throws IOException {
TestHttpClient client = new TestHttpClient();
try {
String uri = DefaultServer.getDefaultServerURL() + "/servletContext/3";
HttpPost post = new HttpPost(uri);
MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
entity.addPart("formValue", new StringBody("myValue", "text/plain", StandardCharsets.UTF_8));
entity.addPart("file", new FileBody(new File(MultiPartTestCase.class.getResource("uploadfile.txt").getFile())));
post.setEntity(entity);
HttpResponse result = client.execute(post);
final String response = HttpClientUtils.readResponse(result);
Assert.assertEquals("EXCEPTION: class java.lang.IllegalStateException", response);
} finally {
client.getConnectionManager().shutdown();
}
}
use of org.apache.http.entity.mime.content.FileBody in project undertow by undertow-io.
the class MultipartFormDataParserTestCase method testFileUpload.
@Test
public void testFileUpload() throws Exception {
DefaultServer.setRootHandler(new BlockingHandler(createHandler()));
TestHttpClient client = new TestHttpClient();
try {
HttpPost post = new HttpPost(DefaultServer.getDefaultServerURL() + "/path");
// post.setHeader(Headers.CONTENT_TYPE, MultiPartHandler.MULTIPART_FORM_DATA);
MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
entity.addPart("formValue", new StringBody("myValue", "text/plain", StandardCharsets.UTF_8));
entity.addPart("file", new FileBody(new File(MultipartFormDataParserTestCase.class.getResource("uploadfile.txt").getFile())));
post.setEntity(entity);
HttpResponse result = client.execute(post);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
HttpClientUtils.readResponse(result);
} finally {
client.getConnectionManager().shutdown();
}
}
Aggregations