Reputation: 77
I migrated my WildFly server from 10 to 16. It now uses resteasy-client of version 3.6.3.Final which uses version 4.5.4 of http-client. The problem is I am unable to get connection manager being created internally when I create restEasyClient from builder as shown below:
this.resteasyClient = new ResteasyClientBuilder()
.connectionPoolSize(DEFAULT_POOL_SIZE)
.maxPooledPerRoute(DEFAULT_POOL_SIZE)
.build();
How can I get connection manager from ApacheHttpClient43Engine engine? My ultimate goal is to get PoolStats from manager which should be PoolingHttpClientConnectionManager in my case [PoolingHttpClientConnectionManager#getTotalStats].
The code I am using to get the connection manager is as follows:
ApacheHttpClient43Engine engine = (ApacheHttpClient43Engine) resteasyClient.httpEngine();
ClientConnectionManager cm = engine.getHttpClient().getConnectionManager();
This method getConnectionManager() is deprecated and does not get HttpClientConnectionManager.
How can I get PoolStats from my restEasyClient?
Thanks in advance
Upvotes: 1
Views: 1980
Reputation: 1252
You can create your own instance of PoolingHttpClientConnectionManager, configure it, keep a reference of it to work with and explicitly set it via setConnectionManager() of HttpClientBuilder to create a HttpClient as hinted on the deprecation.
Afterwards just instruct RESTEasy to use that HttpClient instance by creating your own ApacheHttpClient43Engine with the appropriate constructor and configure it via httpEngine() of ResteasyClientBuilder.
PoolingHttpClientConnectionManager connectionManager =
new PoolingHttpClientConnectionManager();
connectionManager.setMaxTotal(DEFAULT_POOL_SIZE);
connectionManager.setDefaultMaxPerRoute(DEFAULT_POOL_SIZE);
HttpClient httpClient = HttpClientBuilder
.create()
.setConnectionManager(connectionManager)
.build();
ApacheHttpClient43Engine engine = new ApacheHttpClient43Engine(httpClient);
ResteasyClient resteasyClient = new ResteasyClientBuilder()
.httpEngine(engine)
.build();
connectionManager.getTotalStats();
Upvotes: 1
Reputation: 671
You can't get the PoolingHttpClientConnectionManager
instance created by RESTEasy when building the HTTP Client that way, the reason is that engine.getHttpClient().getConnectionManager()
returns a different implementation of the deprecated ClientConnectionManager
interface.
What you could do, instead, is:
org.jboss.resteasy.client.jaxrs.ClientHttpEngineBuilder
interface, extending org.jboss.resteasy.client.jaxrs.ClientHttpEngineBuilder43
and overriding the createEngine(..)
method: you would simply delegate to super.createEngine(..), but you can store the HttpClientConnectionManager
instance that's passed as first parameter and which should be what you're looking for.ResteasyClientBuilder builder = new ResteasyClientBuilder();
ClientHttpEngine customClientHttpEngine = newCustomClientHttpEngineBuilder().resteasyClientBuilder(builder).build();
this.resteasyClient = builder
.httpEngine(customClientHttpEngine)
.connectionPoolSize(DEFAULT_POOL_SIZE)
.maxPooledPerRoute(DEFAULT_POOL_SIZE)
.build();
Hope this helps.
Upvotes: 1