use of org.asynchttpclient.request.body.multipart.MultipartBody in project async-http-client by AsyncHttpClient.
the class MultipartPartTest method transferToShouldWriteStringPart.
@Test
public void transferToShouldWriteStringPart() throws IOException, URISyntaxException {
String text = FileUtils.readFileToString(TestUtils.resourceAsFile("test_sample_message.eml"));
List<Part> parts = new ArrayList<>();
parts.add(new StringPart("test_sample_message.eml", text));
HttpHeaders headers = new DefaultHttpHeaders();
headers.set("Cookie", "open-xchange-public-session-d41d8cd98f00b204e9800998ecf8427e=bfb98150b24f42bd844fc9ef2a9eaad5; open-xchange-secret-TSlq4Cm4nCBnDpBL1Px2A=9a49b76083e34c5ba2ef5c47362313fd; JSESSIONID=6883138728830405130.OX2");
headers.set("Content-Length", "9241");
headers.set("Content-Type", "multipart/form-data; boundary=5gigAKQyqDCVdlZ1fCkeLlEDDauTNoOOEhRnFg");
headers.set("Host", "appsuite.qa.open-xchange.com");
headers.set("Accept", "*/*");
String boundary = "uwyqQolZaSmme019O2kFKvAeHoC14Npp";
List<MultipartPart<? extends Part>> multipartParts = MultipartUtils.generateMultipartParts(parts, boundary.getBytes());
MultipartBody multipartBody = new MultipartBody(multipartParts, "multipart/form-data; boundary=" + boundary, boundary.getBytes());
ByteBuf byteBuf = ByteBufAllocator.DEFAULT.buffer(8 * 1024);
try {
multipartBody.transferTo(byteBuf);
byteBuf.toString(StandardCharsets.UTF_8);
} finally {
multipartBody.close();
byteBuf.release();
}
}
Aggregations