Search in sources :

Example 1 with Part

use of org.asynchttpclient.request.body.multipart.Part in project async-http-client by AsyncHttpClient.

the class SimpleAsyncHttpClient method put.

public Future<Response> put(Part... parts) throws IOException {
    RequestBuilder r = rebuildRequest(requestBuilder.build());
    r.setMethod("POST");
    for (Part part : parts) {
        r.addBodyPart(part);
    }
    return execute(r, null, null);
}
Also used : RequestBuilder(org.asynchttpclient.RequestBuilder) Part(org.asynchttpclient.request.body.multipart.Part) HttpResponseBodyPart(org.asynchttpclient.HttpResponseBodyPart)

Example 2 with Part

use of org.asynchttpclient.request.body.multipart.Part in project async-http-client by AsyncHttpClient.

the class SimpleAsyncHttpClient method put.

public Future<Response> put(BodyConsumer consumer, Part... parts) throws IOException {
    RequestBuilder r = rebuildRequest(requestBuilder.build());
    r.setMethod("POST");
    for (Part part : parts) {
        r.addBodyPart(part);
    }
    return execute(r, consumer, null);
}
Also used : RequestBuilder(org.asynchttpclient.RequestBuilder) Part(org.asynchttpclient.request.body.multipart.Part) HttpResponseBodyPart(org.asynchttpclient.HttpResponseBodyPart)

Example 3 with Part

use of org.asynchttpclient.request.body.multipart.Part 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();
    }
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) FileLikePart(org.asynchttpclient.request.body.multipart.FileLikePart) Part(org.asynchttpclient.request.body.multipart.Part) StringPart(org.asynchttpclient.request.body.multipart.StringPart) MultipartBody(org.asynchttpclient.request.body.multipart.MultipartBody) ArrayList(java.util.ArrayList) StringPart(org.asynchttpclient.request.body.multipart.StringPart) ByteBuf(io.netty.buffer.ByteBuf) Test(org.testng.annotations.Test)

Example 4 with Part

use of org.asynchttpclient.request.body.multipart.Part in project async-http-client by AsyncHttpClient.

the class SimpleAsyncHttpClient method post.

public Future<Response> post(Part... parts) throws IOException {
    RequestBuilder r = rebuildRequest(requestBuilder.build());
    r.setMethod("POST");
    for (Part part : parts) {
        r.addBodyPart(part);
    }
    return execute(r, null, null);
}
Also used : RequestBuilder(org.asynchttpclient.RequestBuilder) Part(org.asynchttpclient.request.body.multipart.Part) HttpResponseBodyPart(org.asynchttpclient.HttpResponseBodyPart)

Example 5 with Part

use of org.asynchttpclient.request.body.multipart.Part in project async-http-client by AsyncHttpClient.

the class SimpleAsyncHttpClient method post.

public Future<Response> post(BodyConsumer consumer, Part... parts) throws IOException {
    RequestBuilder r = rebuildRequest(requestBuilder.build());
    r.setMethod("POST");
    for (Part part : parts) {
        r.addBodyPart(part);
    }
    return execute(r, consumer, null);
}
Also used : RequestBuilder(org.asynchttpclient.RequestBuilder) Part(org.asynchttpclient.request.body.multipart.Part) HttpResponseBodyPart(org.asynchttpclient.HttpResponseBodyPart)

Aggregations

Part (org.asynchttpclient.request.body.multipart.Part)6 HttpResponseBodyPart (org.asynchttpclient.HttpResponseBodyPart)4 RequestBuilder (org.asynchttpclient.RequestBuilder)4 ByteBuf (io.netty.buffer.ByteBuf)1 DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)1 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)1 Cookie (io.netty.handler.codec.http.cookie.Cookie)1 Charset (java.nio.charset.Charset)1 ArrayList (java.util.ArrayList)1 FileLikePart (org.asynchttpclient.request.body.multipart.FileLikePart)1 MultipartBody (org.asynchttpclient.request.body.multipart.MultipartBody)1 StringPart (org.asynchttpclient.request.body.multipart.StringPart)1 Uri (org.asynchttpclient.uri.Uri)1 Test (org.testng.annotations.Test)1