In httpclient 4.3, if you respect all the deprecations, you must build and configure your HttpClient
using an HttpClientBuilder
(documentation here). The methods are explicit, they seem easy to use, and HttpClient
's interface is clear. But maybe a tad too much.
In my own case, I have to inherit Spring's HttpComponentsHttpInvokerRequestExecutor
(documentation here). As a consequence, I can easily get the HttpClient
, but all I know about this object is that it implements the interface.
Since the client is already built, and I do not know anything about its implementation, I cannot access methods such as AbstractHttpClient
's setHttpRequestRetryHandler
or addRequestInterceptor
(though yes, I know, they are deprecated).
So, what would be the cleanest way of updating the settings of this HttpClient
(the retry handler and request interceptor are those I am most concerned with at the moment)? Should I...
- ... savagely cast my client to
AbstractHttpClient
, hoping I will always receive this implementation? - ... create a new
HttpClient
in my HttpInvokerRequestExecutor's constructor, and get something like the example reproduced below? I might add that Spring's constructor (in 3.2.4 at least) uses methods deprecated in httpclient 4.3 too. Would there be any side effect I missed using this strategy? - ... do something I have not proposed yet?
Custom constructor example:
public CustomHttpInvokerRequestExecutor() {
super(); // will create an HttpClient
// Now overwrite the client the super constructor created
setHttpClient(HttpClientBuilder.custom(). ... .build());
}