Hi,
We want to use the HttpAsyncClient and NIO so that we can handle more requests
with fewer threads.
I am tasked with migrating from HttpComponents 3.1 to 4.5. The new API is very
different from the earlier one and I need some help with the same.
ByteArrayPartSource horA = new ByteArrayPartSource("data",
data.toString().getBytes("UTF-8"));
FilePart p1 = new FilePart("data", horA);
StringPart encodingPart = new StringPart("encoded", "" + _encode);
StringPart contentPart = new StringPart("content-type", "text/xml");
Part[] partes = { p1, encodingPart, contentPart };
post.setRequestEntity(new MultipartRequestEntity(partes, post.getParams()));
I rewrote the whole thing above as:
HttpEntity postEntity = MultipartEntityBuilder.create()
.addTextBody("content-type", contentType)
.addTextBody("encoded", ""+true)
.addBinaryBody("data", data.toString().getBytes("UTF-8"))
.build();
post.setEntity(postEntity);
This results in UnsupportedOperationException:Multipart form entity does not
implement #getContent()
I read similar posts on this list but didn't understand what I should do. I
don't want to write copy content into memory/buffer. What is the right way to
write this using 4.5 and HttpAsyncClient? Any pointers will be really
appreciated.
Thanks!