use of org.apache.http.entity.mime.content.InputStreamBody in project sling by apache.
the class ConsoleTestClient method testResourceResolver.
@Test
public void testResourceResolver() throws Exception {
RequestBuilder rb = new RequestBuilder("http://localhost:9000");
final MultipartEntity entity = new MultipartEntity();
// Add Sling POST options
entity.addPart("lang", new StringBody("esp"));
entity.addPart("code", new InputStreamBody(getClass().getResourceAsStream("/test.js"), "test.js"));
executor.execute(rb.buildPostRequest("/system/console/scriptconsole.json").withEntity(entity).withCredentials("admin", "admin")).assertStatus(200);
}
use of org.apache.http.entity.mime.content.InputStreamBody in project sling by apache.
the class SlingSpecificsSightlyIT method uploadFile.
private void uploadFile(String fileName, String serverFileName, String url) throws IOException {
HttpClient httpClient = HttpClientBuilder.create().build();
HttpPost post = new HttpPost(launchpadURL + url);
post.setHeader("Authorization", "Basic YWRtaW46YWRtaW4=");
MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
InputStreamBody inputStreamBody = new InputStreamBody(this.getClass().getClassLoader().getResourceAsStream(fileName), ContentType.TEXT_PLAIN, fileName);
entityBuilder.addPart(serverFileName, inputStreamBody);
post.setEntity(entityBuilder.build());
httpClient.execute(post);
}
use of org.apache.http.entity.mime.content.InputStreamBody in project scheduling by ow2-proactive.
the class RestSchedulerPushPullFileTest method testIt.
public void testIt(String spaceName, String spacePath, String destPath, boolean encode) throws Exception {
File testPushFile = RestFuncTHelper.getDefaultJobXmlfile();
// you can test pushing pulling a big file :
// testPushFile = new File("path_to_a_big_file");
File destFile = new File(new File(spacePath, destPath), testPushFile.getName());
if (destFile.exists()) {
destFile.delete();
}
// PUSHING THE FILE
String pushfileUrl = getResourceUrl("dataspace/" + spaceName + "/" + (encode ? URLEncoder.encode(destPath, "UTF-8") : destPath.replace("\\", "/")));
// either we encode or we test human readable path (with no special character inside)
HttpPost reqPush = new HttpPost(pushfileUrl);
setSessionHeader(reqPush);
// we push a xml job as a simple test
MultipartEntity multipartEntity = new MultipartEntity();
multipartEntity.addPart("fileName", new StringBody(testPushFile.getName()));
multipartEntity.addPart("fileContent", new InputStreamBody(FileUtils.openInputStream(testPushFile), MediaType.APPLICATION_OCTET_STREAM, null));
reqPush.setEntity(multipartEntity);
HttpResponse response = executeUriRequest(reqPush);
System.out.println(response.getStatusLine());
assertHttpStatusOK(response);
Assert.assertTrue(destFile + " exists for " + spaceName, destFile.exists());
Assert.assertTrue("Original file and result are equals for " + spaceName, FileUtils.contentEquals(testPushFile, destFile));
// LISTING THE TARGET DIRECTORY
String pullListUrl = getResourceUrl("dataspace/" + spaceName + "/" + (encode ? URLEncoder.encode(destPath, "UTF-8") : destPath.replace("\\", "/")));
HttpGet reqPullList = new HttpGet(pullListUrl);
setSessionHeader(reqPullList);
HttpResponse response2 = executeUriRequest(reqPullList);
System.out.println(response2.getStatusLine());
assertHttpStatusOK(response2);
InputStream is = response2.getEntity().getContent();
List<String> lines = IOUtils.readLines(is);
HashSet<String> content = new HashSet<>(lines);
System.out.println(lines);
Assert.assertTrue("Pushed file correctly listed", content.contains(testPushFile.getName()));
// PULLING THE FILE
String pullfileUrl = getResourceUrl("dataspace/" + spaceName + "/" + (encode ? URLEncoder.encode(destPath + "/" + testPushFile.getName(), "UTF-8") : destPath.replace("\\", "/") + "/" + testPushFile.getName()));
HttpGet reqPull = new HttpGet(pullfileUrl);
setSessionHeader(reqPull);
HttpResponse response3 = executeUriRequest(reqPull);
System.out.println(response3.getStatusLine());
assertHttpStatusOK(response3);
InputStream is2 = response3.getEntity().getContent();
File answerFile = tmpFolder.newFile();
FileUtils.copyInputStreamToFile(is2, answerFile);
Assert.assertTrue("Original file and result are equals for " + spaceName, FileUtils.contentEquals(answerFile, testPushFile));
// DELETING THE HIERARCHY
String rootPath = destPath.substring(0, destPath.contains("/") ? destPath.indexOf("/") : destPath.length());
String deleteUrl = getResourceUrl("dataspace/" + spaceName + "/" + (encode ? URLEncoder.encode(rootPath, "UTF-8") : rootPath.replace("\\", "/")));
HttpDelete reqDelete = new HttpDelete(deleteUrl);
setSessionHeader(reqDelete);
HttpResponse response4 = executeUriRequest(reqDelete);
System.out.println(response4.getStatusLine());
assertHttpStatusOK(response4);
Assert.assertTrue(destFile + " still exist", !destFile.exists());
}
Aggregations