You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Joan Balagueró <jo...@grupoventus.com> on 2018/10/19 14:02:17 UTC

More about migration from async4.1.3 to http5

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.


Re: More about migration from async4.1.3 to http5

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Fri, 2018-10-19 at 16:02 +0200, Joan Balagueró wrote:
> 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.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. 

>  
> 
>  
> 
> 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? 

Use AsyncRequestBuilder.


> 
> 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.  

>  
> 
>  
> 
> 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-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org