Discussion:
More about migration from async4.1.3 to http5
Joan Balagueró
2018-10-19 14:02:17 UTC
Permalink
Hello,



Just three more questions:



1. Is this the way to set a byte array to the RequestBuilder’s entity
(using a org.apache.http.nio.entity.NByteArrayEntity)?



org.apache.hc.client5.http.classic.methods.RequestBuilder.RequestBuilder rb
= RequestBuilder.post(uri);

org.apache.http.nio.entity.NByteArrayEntity nbae = new
NByteArrayEntity(requestBody);

nbae.setContentType(contentType);

rb.setEntity(nbae);

return rb.build();





2. With the Async client, in order to send an async request to be
consumed for an AsyncConsumer:



HttpRequest httpRequest = this.createPostRequest(uri,
responseTimeout);

HttpAsyncResponseConsumer<Void> harc = new ServerHttpResponse(…);

this.objHttp.getAsyncHttpClient().execute(new
BasicAsyncRequestProducer(this.createHttpHost(uri), httpRequest), harc,
null);



What request producer must I use now? I can’t find anyone that accomplish
with (
<eclipse-javadoc:%E2%98%82=vpfw/web%5C/WEB-INF%5C/lib%5C/httpcore5-5.0-beta3
.jar%3Corg> org.
<eclipse-javadoc:%E2%98%82=vpfw/web%5C/WEB-INF%5C/lib%5C/httpcore5-5.0-beta3
.jar%3Corg.apache> apache.
<eclipse-javadoc:%E2%98%82=vpfw/web%5C/WEB-INF%5C/lib%5C/httpcore5-5.0-beta3
.jar%3Corg.apache.hc> hc.
<eclipse-javadoc:%E2%98%82=vpfw/web%5C/WEB-INF%5C/lib%5C/httpcore5-5.0-beta3
.jar%3Corg.apache.hc.core5> core5.
<eclipse-javadoc:%E2%98%82=vpfw/web%5C/WEB-INF%5C/lib%5C/httpcore5-5.0-beta3
.jar%3Corg.apache.hc.core5.http> http.HttpHost,
<eclipse-javadoc:%E2%98%82=vpfw/web%5C/WEB-INF%5C/lib%5C/httpcore5-5.0-beta3
.jar%3Corg> org.
<eclipse-javadoc:%E2%98%82=vpfw/web%5C/WEB-INF%5C/lib%5C/httpcore5-5.0-beta3
.jar%3Corg.apache> apache.
<eclipse-javadoc:%E2%98%82=vpfw/web%5C/WEB-INF%5C/lib%5C/httpcore5-5.0-beta3
.jar%3Corg.apache.hc> hc.
<eclipse-javadoc:%E2%98%82=vpfw/web%5C/WEB-INF%5C/lib%5C/httpcore5-5.0-beta3
.jar%3Corg.apache.hc.core5> core5.
<eclipse-javadoc:%E2%98%82=vpfw/web%5C/WEB-INF%5C/lib%5C/httpcore5-5.0-beta3
.jar%3Corg.apache.hc.core5.http> http.Request)





3. Regarding to the HttpAsyncResponseConsumer, what is the equivalent
interface in Http5 with the methods ‘responseReceived’, ‘consumeContent’ and
‘responseCompleted’?





I have been looking at the examples, but I couldn’t find anything similar.



Thanks,



Joan.
Oleg Kalnichevski
2018-10-19 15:41:22 UTC
Permalink
Post by Joan Balagueró
Hello,
1. Is this the way to set a byte array to the RequestBuilder’s
entity
(using a org.apache.http.nio.entity.NByteArrayEntity)?
org.apache.hc.client5.http.classic.methods.RequestBuilder.RequestBuil
der rb
= RequestBuilder.post(uri);
org.apache.http.nio.entity.NByteArrayEntity nbae = new
NByteArrayEntity(requestBody);
nbae.setContentType(contentType);
rb.setEntity(nbae);
return rb.build();
Do not use classic request builder. Use AsyncRequestBuilder instead.
Post by Joan Balagueró
2. With the Async client, in order to send an async request to be
HttpRequest httpRequest = this.createPostRequest(uri,
responseTimeout);
HttpAsyncResponseConsumer<Void> harc = new ServerHttpResponse(…);
this.objHttp.getAsyncHttpClient().execute(new
BasicAsyncRequestProducer(this.createHttpHost(uri), httpRequest), harc,
null);
What request producer must I use now?
Use AsyncRequestBuilder.
Post by Joan Balagueró
3. Regarding to the HttpAsyncResponseConsumer, what is the equivalent
interface in Http5 with the methods ‘responseReceived’,
‘consumeContent’ and
‘responseCompleted’?
#consumeResponse, #consume, #streamEnd

You might find AbstractBinResponseConsumer and
AbstractCharResponseConsumer useful as base classes for custom response
consumers.
Post by Joan Balagueró
I have been looking at the examples, but I couldn’t find anything
similar.
This is a whole bunch of examples of all sorts.

https://github.com/apache/httpcomponents-client/tree/master/httpclient5/src/examples/org/apache/hc/client5/http/examples

Oleg



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
Loading...