Hi,
I would like some help, clarification on using HttpAsyncClient with multipart
entitity .
I got it working with HttpCleint but I need it to work with HttpAsyncClient.
Blocked on this but any help on this would be great.
Sample of how I am using it with both Clients.
MultipartEntity mpe = new MultipartEntity()
;
mpe.addPart("key1", new StringBody("value1"))
;
mpe.addPart("key2", new StringBody("value2"))
;
mpe.addPart("data1", new ByteArrayBody(hugeData1, ""))
;
mpe.addPart("data2", new ByteArrayBody(hugeData2, ""))
;Using Blocking I/O: This one works.
SchemeRegistry schemeRegistry = new SchemeRegistry()
;schemeRegistry.register(new Scheme("http", 80, new PlainSocketFactory()))
;ClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry)
;HttpClient httpClient = new DefaultHttpClient(cm)
;HttpPost post = new HttpPost(myurl)
;post.setEntity(mpe)
;HttpResponse r = client.execute(post)
;int status = r.getStatusLine().getStatusCode()
;Using NIO: This fails with the following exception. (Multipart form entity
does not implement #getContent())
HttpParams params = new BasicHttpParams()
;AsyncSchemeRegistry schemeRegistry = new AsyncSchemeRegistry()
;schemeRegistry.register(new AsyncScheme("http", 80, null))
;ClientAsyncConnectionManager cm = new PoolingClientAsyncConnectionManager(new
DefaultConnectingIOReactor(), schemeRegistry)
;DefaultHttpAsyncClient asyncClient = new DefaultHttpAsyncClient(cm)
;asyncClient.setParams(params)
;asyncClient.start();
HttpPost post = new HttpPost(myurl)
;
post.setEntity(mpe)
;Future<HttpResponse> f= asyncClient.execute(post, null)
;// do something
HttpResponse r = f.get(5, TimeUnit.SECONDS)
;int status = r.getStatusLine().getStatusCode();
Thanks,
Rishi.