Re: Fwd: HttpClient5 : simple example on how to configure timeout after build()

2018-05-16 Thread /

Thanks I understand.

I would appreciate if some concrete code or pointer to examples is given 
regarding:


1) Create a shared HTTPClient
2) how a given thread is passed=given the shared client and changes, 
say, connection timeout AND ALSO its userAgentString.


(the userAgentString is not something I want to change but I try to push 
this to its limit).


bw
a.

On 16/05/18 22:54, Oleg Kalnichevski wrote:

On Wed, 2018-05-16 at 15:56 +, Daly, Paul wrote:

I canot speak for HttpClient5, but If you are just looking to change
some timeouts on the request, in 4.5.5, I do this (as recommended
from this emai list some time ago!).

I guess its not too differenent for HC5 (?)


- Create a shared HTTPClient instance. this is used by all requests
in the JVM and is instantiated on first use.
- each request (thread) grabs the shared client (it is thread safe)
- each request (thread) creates its own request context
- set the request type specific timeout on the request context (note
internally in our app we apply different timeouts depending on
several factors (message type,client etc))
- execute the request on the shared client with the request context

Seems to work fine...



+1. Precisely how it was intended.

Oleg


Some snippets

// in a client factory class I create the client based on sensible
timeout defaults
// this populates a static httpclient which can be returned by a
static getClient method to all threads needing a httpClient
CloseableHttpClient newClient =
HttpClientBuilder.create().useSystemProperties()
.setDefaultRequestConfig(config).setMaxConnPerRoute(max
ConnectionsPerRoute)
.setMaxConnTotal(totalMaxConnection).evictExpiredConnec
tions()
.evictIdleConnections(idleLife,
TimeUnit.MINUTES).setConnectionTimeToLive(maxLife, TimeUnit.MINUTES)
.build();


statichttpClient = newClient;


// within the request
httpClient = HttpClientFactory.getClient();

// create the context for this thread
HttpClientContext httpContext = HttpClientContext.create();
httpContext.setRequestConfig(getRequestConfig());
HttpResponse serviceResponse = httpClient.execute(httpRequest,
httpContext);


// make the request config
private RequestConfig getRequestConfig() throws
PCEConfigParamNotFoundException {

// setup request timeouts
return RequestConfig.custom().setConnectionRequestTimeout(aaa).
setConnectTimeout(bbb). setSocketTimeout(ccc).build();
}







-Original Message-
From: / [mailto:isla...@yahoo.co.uk.INVALID]
Sent: Wednesday, May 16, 2018 4:01 PM
To: httpclient-users@hc.apache.org
Subject: Re: Fwd: HttpClient5 : simple example on how to configure
timeout after build()

Thanks,

if I understood correctly, the pattern should be:

1) Create a RequestConfig (rc) object and keep it.
2) If you need to modify httpclient, modify the kept RequestConfig
object
3) After doing said modifications **re-create httpclient** with kept
RequestConfig.
4) Keep the RequestConfig.
5) Keeping a client and modifying it as see fit is/will be
deprecated.

Questions:
can I extract a RequestConfig from current client, modify its
timeout
and then re-create a client with this cloned-and-modified
RequestConfig?
(so as not to keep a RequestConfig at all but remember all the
settings
I did to my client).



thanks

On 16/05/18 17:42, Shawn Heisey wrote:

On 5/16/2018 8:09 AM, / wrote:

I am looking for an example on how to configure HttpClient5 after
it
has been built and how to extract/print some of its
configuration.

Once I have an HttpClient object, how do I go about and change
some of
its settings, for example connection timeout or user-agent-string
or
even cookie jar?

I am looking for the most straight-forward and efficient way to
do
this. I don't care about "fluent" APIs neither about streams etc.

something like:

myclient.setParameter(connection_timeout, 1000);


For the most part, you can't change settings on an existing
HttpClient
object.  Since about 4.3, the objects and methods that allow
clients to
be changed after creation are all deprecated. That capability is
completely gone in 5.x.  Default settings are managed with builder
objects using fluent methods, then you create the client object
with the
indicated settings.  Here's how I create a client object with
explicit
defaults using non-deprecated code in the 4.5 version:

    RequestConfig rc =
RequestConfig.custom().setConnectTimeout(15000)
            .setSocketTimeout(12).build();
    httpClient = HttpClients.custom().setDefaultRequestConfig(rc)
.setMaxConnPerRoute(300).setMaxConnTotal(5000).disableAutomaticRetr
ies()
            .build();

The httpClient field is an instance of HttpClient.  I do not know
what
kind of adjustments might need to be made for 5.x, but that should
give
you an idea about how things are done since the way you're trying
to do
it is no longer available.

Many of the settings you might be interested in can also be changed
at
the request level.  I do not know HOW to do this, 

Re: Fwd: HttpClient5 : simple example on how to configure timeout after build()

2018-05-16 Thread Shawn Heisey
On 5/16/2018 8:42 AM, Shawn Heisey wrote:
>   RequestConfig rc = RequestConfig.custom().setConnectTimeout(15000)
>           .setSocketTimeout(12).build();
>   httpClient = HttpClients.custom().setDefaultRequestConfig(rc)
> .setMaxConnPerRoute(300).setMaxConnTotal(5000).disableAutomaticRetries()
>           .build();

I have attempted to upgrade httpclient in one of my projects from 4.5.x
to the latest 5.0 beta release, and this code no longer compiles.  On
RequestConfig.Builder, the setSocketTimeout method no longer exists.  On
HttpClientBuilder, the setMaxConnPerRoute and setMaxConnTotal methods no
longer exist.  These methods were not deprecated in 4.5.x.

Is it still possible to set a socket timeout default?  Is it still
possible to increase the maximum number of connections that a client can
make?  If so, how is it done?

Thanks,
Shawn


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



Re: Fwd: HttpClient5 : simple example on how to configure timeout after build()

2018-05-16 Thread Oleg Kalnichevski
On Wed, 2018-05-16 at 15:56 +, Daly, Paul wrote:
> I canot speak for HttpClient5, but If you are just looking to change
> some timeouts on the request, in 4.5.5, I do this (as recommended
> from this emai list some time ago!).
> 
> I guess its not too differenent for HC5 (?)
> 
> 
> - Create a shared HTTPClient instance. this is used by all requests
> in the JVM and is instantiated on first use.
> - each request (thread) grabs the shared client (it is thread safe)
> - each request (thread) creates its own request context
> - set the request type specific timeout on the request context (note
> internally in our app we apply different timeouts depending on
> several factors (message type,client etc))
> - execute the request on the shared client with the request context
> 
> Seems to work fine...
> 

+1. Precisely how it was intended.

Oleg

> Some snippets
> 
> // in a client factory class I create the client based on sensible
> timeout defaults
> // this populates a static httpclient which can be returned by a
> static getClient method to all threads needing a httpClient
> CloseableHttpClient newClient =
> HttpClientBuilder.create().useSystemProperties()
>   .setDefaultRequestConfig(config).setMaxConnPerRoute(max
> ConnectionsPerRoute)
>   .setMaxConnTotal(totalMaxConnection).evictExpiredConnec
> tions()
>   .evictIdleConnections(idleLife,
> TimeUnit.MINUTES).setConnectionTimeToLive(maxLife, TimeUnit.MINUTES)
>   .build();
> 
> 
> statichttpClient = newClient;
> 
> 
> // within the request
> httpClient = HttpClientFactory.getClient();
> 
> // create the context for this thread
> HttpClientContext httpContext = HttpClientContext.create();
> httpContext.setRequestConfig(getRequestConfig());
> HttpResponse serviceResponse = httpClient.execute(httpRequest,
> httpContext);
> 
> 
> // make the request config
> private RequestConfig getRequestConfig() throws
> PCEConfigParamNotFoundException {
> 
> // setup request timeouts
> return RequestConfig.custom().setConnectionRequestTimeout(aaa).
> setConnectTimeout(bbb). setSocketTimeout(ccc).build();
> }
> 
> 
> 
> 
> 
> 
> 
> -Original Message-
> From: / [mailto:isla...@yahoo.co.uk.INVALID] 
> Sent: Wednesday, May 16, 2018 4:01 PM
> To: httpclient-users@hc.apache.org
> Subject: Re: Fwd: HttpClient5 : simple example on how to configure
> timeout after build()
> 
> Thanks,
> 
> if I understood correctly, the pattern should be:
> 
> 1) Create a RequestConfig (rc) object and keep it.
> 2) If you need to modify httpclient, modify the kept RequestConfig
> object
> 3) After doing said modifications **re-create httpclient** with kept 
> RequestConfig.
> 4) Keep the RequestConfig.
> 5) Keeping a client and modifying it as see fit is/will be
> deprecated.
> 
> Questions:
> can I extract a RequestConfig from current client, modify its
> timeout 
> and then re-create a client with this cloned-and-modified
> RequestConfig? 
> (so as not to keep a RequestConfig at all but remember all the
> settings 
> I did to my client).
> 
> 
> 
> thanks
> 
> On 16/05/18 17:42, Shawn Heisey wrote:
> > On 5/16/2018 8:09 AM, / wrote:
> > > I am looking for an example on how to configure HttpClient5 after
> > > it 
> > > has been built and how to extract/print some of its
> > > configuration.
> > > 
> > > Once I have an HttpClient object, how do I go about and change
> > > some of 
> > > its settings, for example connection timeout or user-agent-string 
> > > or 
> > > even cookie jar?
> > > 
> > > I am looking for the most straight-forward and efficient way to
> > > do 
> > > this. I don't care about "fluent" APIs neither about streams etc.
> > > 
> > > something like:
> > > 
> > > myclient.setParameter(connection_timeout, 1000); 
> > 
> > For the most part, you can't change settings on an existing
> > HttpClient 
> > object.  Since about 4.3, the objects and methods that allow
> > clients to 
> > be changed after creation are all deprecated. That capability is 
> > completely gone in 5.x.  Default settings are managed with builder 
> > objects using fluent methods, then you create the client object
> > with the 
> > indicated settings.  Here's how I create a client object with
> > explicit 
> > defaults using non-deprecated code in the 4.5 version:
> > 
> >    RequestConfig rc =
> > RequestConfig.custom().setConnectTimeout(15000)
> >            .setSocketTimeout(12).build();
> >    httpClient = HttpClients.custom().setDefaultRequestConfig(rc)
> > .setMaxConnPerRoute(300).setMaxConnTotal(5000).disableAutomaticRetr
> > ies()
> >            .build();
> > 
> > The httpClient field is an instance of HttpClient.  I do not know
> > what 
> > kind of adjustments might need to be made for 5.x, but that should
> > give 
> > you an idea about how things are done since the way you're trying
> > to do 
> > it is no longer available.
> > 
> > Many of the settings you might be interested in can also be changed
> > at 
> > the request level.  I do 

Re: Fwd: HttpClient5 : simple example on how to configure timeout after build()

2018-05-16 Thread Oleg Kalnichevski
On Wed, 2018-05-16 at 18:01 +0300, / wrote:
> Thanks,
> 
> if I understood correctly, the pattern should be:
> 
> 1) Create a RequestConfig (rc) object and keep it.
> 2) If you need to modify httpclient, modify the kept RequestConfig
> object
> 3) After doing said modifications **re-create httpclient** with kept 
> RequestConfig.

Please do not do that. There is no need to re-create the client. If you
have a custom RequestConfig, stick it into the request object or the
HttpContext associated with it.

4) Keep the RequestConfig.
> 5) Keeping a client and modifying it as see fit is/will be
> deprecated.
> 
> Questions:
> can I extract a RequestConfig from current client, modify its
> timeout 
> and then re-create a client with this cloned-and-modified
> RequestConfig? 
> (so as not to keep a RequestConfig at all but remember all the
> settings 
> I did to my client).
> 

RequestConfig used to execute a particular request will be available in
the HttpContext. HttpClient instance merely holds default settings. 

Oleg

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



Re: Default IOReactorConfig instance has no socket timeout

2018-05-16 Thread Дмитрий Жихарев
Oleg,

realistically I would expect the default timeout to be around 5 seconds, as is 
the default value in the PoolingHttpClientConnectionManager ( 
https://github.com/apache/httpcomponents-client/blob/master/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java).
 IIRC, it was 2 seconds in the 4.4 release. To me, for an http call 3 minutes 
looks like an eternity. But that's just my opinion.

I've made a small example: 
https://github.com/jihor/async-http-client-notimeout-demo

In the demo project, HttpAsyncClient 4.1.3 is used.

The example runs 2 http post's (one without timeout, the other with a timeout) 
on each of the following clients:

 

- (sync) client with default configuration (HttpClients.createDefault()). This 
client will wait endlessly if no timeout is defined in the request;

- (sync) client with custom RequestConfig. This client will always exit after 
its timeout expires even if the request has no timeout defined;

- asyncClient with default configuration (HttpAsyncClients.createDefault()). 
This client will wait endlessly if no timeout is defined in the request;

- asyncClient with custom connection manager and custom ioReactor. This client 
will always exit after its timeout expires even if the request has no timeout 
defined.

 

To me, it seems like a pitfall that default configurations offer unlimited 
timeouts for the requests which don't request specific timeouts using request 
configs. 


Regards, Dmitry Zhikharev


On May 16, 2018, 17:02, at 17:02, Oleg Kalnichevski  wrote:
>On Wed, 2018-05-16 at 15:16 +0300, Дмитрий Жихарев wrote:
>> Hi all!
>>
>> I was wondering if the IOReactorConfig.DEFAULT intentionally has
>> soTimeout set to ZERO_MILLESECONDS. Before version 5 there was also
>> connectTimeout, which also was 0 for the default builder. I
>> understand that the library can't make up its own mind on what
>> timeout the user requires, but isn't it a good practice for the
>> default config to have some sensible defaults so it doesn't hang
>> forever if something goes wrong?
>>
>> Regards, Dmitry Zhikharev
>>
>
>Hi Dmitry
>
>HttpClient 5.0 already uses finite (3 min) timeout values for connect
>and connection request operations.
>
>
>https://github.com/apache/httpcomponents-client/blob/master/httpclient5
>/src/main/java/org/apache/hc/client5/http/config/RequestConfig.java#L44
>
>It is more difficult to say what the default value of socket timeout
>should be as different application might have different expectations
>and operational assumptions. 
>
>What kind of value would you propose?
>
>Oleg
>
>-
>To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org
>For additional commands, e-mail: httpclient-users-h...@hc.apache.org


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



HttpClient5 : simple example on how to configure timeout after build()

2018-05-16 Thread /

Hi there,

I am looking for an example on how to configure HttpClient5 after it has 
been built, i.e. once I have an HttpClient object, how do I go about and 
change some of its settings, for example connection timeout or 
user-agent-string or even cookie jar.


I am looking for the most straight-forward and efficient way to do this.

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



RE: Fwd: HttpClient5 : simple example on how to configure timeout after build()

2018-05-16 Thread Daly, Paul

I canot speak for HttpClient5, but If you are just looking to change some 
timeouts on the request, in 4.5.5, I do this (as recommended from this emai 
list some time ago!).

I guess its not too differenent for HC5 (?)


- Create a shared HTTPClient instance. this is used by all requests in the JVM 
and is instantiated on first use.
- each request (thread) grabs the shared client (it is thread safe)
- each request (thread) creates its own request context
- set the request type specific timeout on the request context (note internally 
in our app we apply different timeouts depending on several factors (message 
type,client etc))
- execute the request on the shared client with the request context

Seems to work fine...

Some snippets

// in a client factory class I create the client based on sensible timeout 
defaults
// this populates a static httpclient which can be returned by a static 
getClient method to all threads needing a httpClient
CloseableHttpClient newClient = HttpClientBuilder.create().useSystemProperties()

.setDefaultRequestConfig(config).setMaxConnPerRoute(maxConnectionsPerRoute)
.setMaxConnTotal(totalMaxConnection).evictExpiredConnections()
.evictIdleConnections(idleLife, 
TimeUnit.MINUTES).setConnectionTimeToLive(maxLife, TimeUnit.MINUTES)
.build();


statichttpClient = newClient;


// within the request
httpClient = HttpClientFactory.getClient();

// create the context for this thread
HttpClientContext httpContext = HttpClientContext.create();
httpContext.setRequestConfig(getRequestConfig());
HttpResponse serviceResponse = httpClient.execute(httpRequest, httpContext);


// make the request config
private RequestConfig getRequestConfig() throws PCEConfigParamNotFoundException 
{

// setup request timeouts
return RequestConfig.custom().setConnectionRequestTimeout(aaa). 
setConnectTimeout(bbb). setSocketTimeout(ccc).build();
}







-Original Message-
From: / [mailto:isla...@yahoo.co.uk.INVALID] 
Sent: Wednesday, May 16, 2018 4:01 PM
To: httpclient-users@hc.apache.org
Subject: Re: Fwd: HttpClient5 : simple example on how to configure timeout 
after build()

Thanks,

if I understood correctly, the pattern should be:

1) Create a RequestConfig (rc) object and keep it.
2) If you need to modify httpclient, modify the kept RequestConfig object
3) After doing said modifications **re-create httpclient** with kept 
RequestConfig.
4) Keep the RequestConfig.
5) Keeping a client and modifying it as see fit is/will be deprecated.

Questions:
can I extract a RequestConfig from current client, modify its timeout 
and then re-create a client with this cloned-and-modified RequestConfig? 
(so as not to keep a RequestConfig at all but remember all the settings 
I did to my client).



thanks

On 16/05/18 17:42, Shawn Heisey wrote:
> On 5/16/2018 8:09 AM, / wrote:
>> I am looking for an example on how to configure HttpClient5 after it 
>> has been built and how to extract/print some of its configuration.
>>
>> Once I have an HttpClient object, how do I go about and change some of 
>> its settings, for example connection timeout or user-agent-string or 
>> even cookie jar?
>>
>> I am looking for the most straight-forward and efficient way to do 
>> this. I don't care about "fluent" APIs neither about streams etc.
>>
>> something like:
>>
>> myclient.setParameter(connection_timeout, 1000); 
> 
> For the most part, you can't change settings on an existing HttpClient 
> object.  Since about 4.3, the objects and methods that allow clients to 
> be changed after creation are all deprecated. That capability is 
> completely gone in 5.x.  Default settings are managed with builder 
> objects using fluent methods, then you create the client object with the 
> indicated settings.  Here's how I create a client object with explicit 
> defaults using non-deprecated code in the 4.5 version:
> 
>    RequestConfig rc = RequestConfig.custom().setConnectTimeout(15000)
>            .setSocketTimeout(12).build();
>    httpClient = HttpClients.custom().setDefaultRequestConfig(rc)
> .setMaxConnPerRoute(300).setMaxConnTotal(5000).disableAutomaticRetries()
>            .build();
> 
> The httpClient field is an instance of HttpClient.  I do not know what 
> kind of adjustments might need to be made for 5.x, but that should give 
> you an idea about how things are done since the way you're trying to do 
> it is no longer available.
> 
> Many of the settings you might be interested in can also be changed at 
> the request level.  I do not know HOW to do this, only that it CAN be 
> done.  I think this is what Oleg was referring to in his reply.
> 
> Thanks,
> Shawn
> 
> 
> -
> To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org
> For additional commands, e-mail: httpclient-users-h...@hc.apache.org
> 

-
To 

Re: Fwd: HttpClient5 : simple example on how to configure timeout after build()

2018-05-16 Thread /

Thanks,

if I understood correctly, the pattern should be:

1) Create a RequestConfig (rc) object and keep it.
2) If you need to modify httpclient, modify the kept RequestConfig object
3) After doing said modifications **re-create httpclient** with kept 
RequestConfig.

4) Keep the RequestConfig.
5) Keeping a client and modifying it as see fit is/will be deprecated.

Questions:
can I extract a RequestConfig from current client, modify its timeout 
and then re-create a client with this cloned-and-modified RequestConfig? 
(so as not to keep a RequestConfig at all but remember all the settings 
I did to my client).




thanks

On 16/05/18 17:42, Shawn Heisey wrote:

On 5/16/2018 8:09 AM, / wrote:
I am looking for an example on how to configure HttpClient5 after it 
has been built and how to extract/print some of its configuration.


Once I have an HttpClient object, how do I go about and change some of 
its settings, for example connection timeout or user-agent-string or 
even cookie jar?


I am looking for the most straight-forward and efficient way to do 
this. I don't care about "fluent" APIs neither about streams etc.


something like:

myclient.setParameter(connection_timeout, 1000); 


For the most part, you can't change settings on an existing HttpClient 
object.  Since about 4.3, the objects and methods that allow clients to 
be changed after creation are all deprecated. That capability is 
completely gone in 5.x.  Default settings are managed with builder 
objects using fluent methods, then you create the client object with the 
indicated settings.  Here's how I create a client object with explicit 
defaults using non-deprecated code in the 4.5 version:


   RequestConfig rc = RequestConfig.custom().setConnectTimeout(15000)
           .setSocketTimeout(12).build();
   httpClient = HttpClients.custom().setDefaultRequestConfig(rc)
.setMaxConnPerRoute(300).setMaxConnTotal(5000).disableAutomaticRetries()
           .build();

The httpClient field is an instance of HttpClient.  I do not know what 
kind of adjustments might need to be made for 5.x, but that should give 
you an idea about how things are done since the way you're trying to do 
it is no longer available.


Many of the settings you might be interested in can also be changed at 
the request level.  I do not know HOW to do this, only that it CAN be 
done.  I think this is what Oleg was referring to in his reply.


Thanks,
Shawn


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



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



Re: Fwd: HttpClient5 : simple example on how to configure timeout after build()

2018-05-16 Thread Shawn Heisey

On 5/16/2018 8:09 AM, / wrote:
I am looking for an example on how to configure HttpClient5 after it 
has been built and how to extract/print some of its configuration.


Once I have an HttpClient object, how do I go about and change some of 
its settings, for example connection timeout or user-agent-string or 
even cookie jar?


I am looking for the most straight-forward and efficient way to do 
this. I don't care about "fluent" APIs neither about streams etc.


something like:

myclient.setParameter(connection_timeout, 1000); 


For the most part, you can't change settings on an existing HttpClient 
object.  Since about 4.3, the objects and methods that allow clients to 
be changed after creation are all deprecated. That capability is 
completely gone in 5.x.  Default settings are managed with builder 
objects using fluent methods, then you create the client object with the 
indicated settings.  Here's how I create a client object with explicit 
defaults using non-deprecated code in the 4.5 version:


  RequestConfig rc = RequestConfig.custom().setConnectTimeout(15000)
          .setSocketTimeout(12).build();
  httpClient = HttpClients.custom().setDefaultRequestConfig(rc)
.setMaxConnPerRoute(300).setMaxConnTotal(5000).disableAutomaticRetries()
          .build();

The httpClient field is an instance of HttpClient.  I do not know what 
kind of adjustments might need to be made for 5.x, but that should give 
you an idea about how things are done since the way you're trying to do 
it is no longer available.


Many of the settings you might be interested in can also be changed at 
the request level.  I do not know HOW to do this, only that it CAN be 
done.  I think this is what Oleg was referring to in his reply.


Thanks,
Shawn


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



Re: Shall I write my project in HC5 or HC4?

2018-05-16 Thread /

many thanks for your advice!

On 16/05/18 17:13, Oleg Kalnichevski wrote:

On Wed, 2018-05-16 at 17:04 +0300, / wrote:

Hi there,

My main requirement is that I do not have to change a lot of code
when
the HC5 becomes stable.

So, if I am writing software to live for the next 3 years should I
use
already existing HC4 or try HC5-beta. In fact I already started
playing
with HC5 but I can't find a lot of examples - even for as a simple
thing
as printing the response content or changing timeout settings?



While documentation for HC5 is still virtually non-existent there
should be quite a few examples already.

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

If you need HTTP/2 transport today HC5 should be a better choice,
otherwise stick to HC4 for now.


Oleg


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



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



Re: Fwd: HttpClient5 : simple example on how to configure timeout after build()

2018-05-16 Thread Oleg Kalnichevski
On Wed, 2018-05-16 at 17:09 +0300, / wrote:
> Hi there,
> 
> I am looking for an example on how to configure HttpClient5 after it
> has 
> been built and how to extract/print some of its configuration.
> 
> Once I have an HttpClient object, how do I go about and change some
> of 
> its settings, for example connection timeout or user-agent-string or 
> even cookie jar?
> 

HttpContext is your best friend

https://github.com/apache/httpcomponents-client/blob/master/httpclient5
/src/examples/org/apache/hc/client5/http/examples/ClientCustomContext.j
ava

Any bit of contextual details for request execution should be there (or
should go there)

Hope this helps.

Oleg

> I am looking for the most straight-forward and efficient way to do
> this. 
> I don't care about "fluent" APIs neither about streams etc.
> 
> something like:
> 
> myclient.setParameter(connection_timeout, 1000);
> 
> or
> 
> System.out.println(myclient.getParameter(user_agent_string));
> 
> is that possible at all? or shall I start prepare for the climb on
> the 
> long-winded road to the Castle - "oh! howdy Kafka!" ?
> 
> -
> To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org
> For additional commands, e-mail: httpclient-users-h...@hc.apache.org
> 

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



Re: Shall I write my project in HC5 or HC4?

2018-05-16 Thread Oleg Kalnichevski
On Wed, 2018-05-16 at 17:04 +0300, / wrote:
> Hi there,
> 
> My main requirement is that I do not have to change a lot of code
> when 
> the HC5 becomes stable.
> 
> So, if I am writing software to live for the next 3 years should I
> use 
> already existing HC4 or try HC5-beta. In fact I already started
> playing 
> with HC5 but I can't find a lot of examples - even for as a simple
> thing 
> as printing the response content or changing timeout settings?
> 

While documentation for HC5 is still virtually non-existent there
should be quite a few examples already.

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

If you need HTTP/2 transport today HC5 should be a better choice,
otherwise stick to HC4 for now.


Oleg


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



Fwd: HttpClient5 : simple example on how to configure timeout after build()

2018-05-16 Thread /

Hi there,

I am looking for an example on how to configure HttpClient5 after it has 
been built and how to extract/print some of its configuration.


Once I have an HttpClient object, how do I go about and change some of 
its settings, for example connection timeout or user-agent-string or 
even cookie jar?


I am looking for the most straight-forward and efficient way to do this. 
I don't care about "fluent" APIs neither about streams etc.


something like:

myclient.setParameter(connection_timeout, 1000);

or

System.out.println(myclient.getParameter(user_agent_string));

is that possible at all? or shall I start prepare for the climb on the 
long-winded road to the Castle - "oh! howdy Kafka!" ?


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



Shall I write my project in HC5 or HC4?

2018-05-16 Thread /

Hi there,

My main requirement is that I do not have to change a lot of code when 
the HC5 becomes stable.


So, if I am writing software to live for the next 3 years should I use 
already existing HC4 or try HC5-beta. In fact I already started playing 
with HC5 but I can't find a lot of examples - even for as a simple thing 
as printing the response content or changing timeout settings?


bw,
a.

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



Re: Default IOReactorConfig instance has no socket timeout

2018-05-16 Thread Oleg Kalnichevski
On Wed, 2018-05-16 at 15:16 +0300, Дмитрий Жихарев wrote:
> Hi all!
> 
> I was wondering if the IOReactorConfig.DEFAULT intentionally has
> soTimeout set to ZERO_MILLESECONDS. Before version 5 there was also
> connectTimeout, which also was 0 for the default builder. I
> understand that the library can't make up its own mind on what
> timeout the user requires, but isn't it a good practice for the
> default config to have some sensible defaults so it doesn't hang
> forever if something goes wrong?
> 
> Regards, Dmitry Zhikharev
> 

Hi Dmitry

HttpClient 5.0 already uses finite (3 min) timeout values for connect
and connection request operations.


https://github.com/apache/httpcomponents-client/blob/master/httpclient5
/src/main/java/org/apache/hc/client5/http/config/RequestConfig.java#L44

It is more difficult to say what the default value of socket timeout
should be as different application might have different expectations
and operational assumptions. 

What kind of value would you propose?

Oleg 

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



Default IOReactorConfig instance has no socket timeout

2018-05-16 Thread Дмитрий Жихарев
Hi all!

I was wondering if the IOReactorConfig.DEFAULT intentionally has soTimeout set 
to ZERO_MILLESECONDS. Before version 5 there was also connectTimeout, which 
also was 0 for the default builder. I understand that the library can't make up 
its own mind on what timeout the user requires, but isn't it a good practice 
for the default config to have some sensible defaults so it doesn't hang 
forever if something goes wrong?

Regards, Dmitry Zhikharev

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