Re: How to retrieve server ip of the connected connections

2016-06-10 Thread Oleg Kalnichevski
On Thu, 2016-06-09 at 19:40 +, Vicky Singh wrote:
> 
> 
>  I am using PoolingHttpClientConnectionManager to create connections. I would 
> like to get what IP address my connections resolve to. Is there a API that I 
> can use.
> I need it for reporting and also to drop connections if I think connected IP 
> is not the best IP address. I found this 
> https://issues.apache.org/jira/browse/HTTPCLIENT-656  
> 
> Summary of my code,
> PoolingHttpClientConnectionManager connMgr = new 
> PoolingHttpClientConnectionManager(socketFactoryRegistry);// 
> build custom http client . ...Set hosts = 
> connMgr.getRoutes();for (HttpRoute r: hosts) {InetAddress 
> ip = r.getTargetHost().getAddress();break;}
> The above code gets an IP only if HttpHost was created using IP in 
> constructor . From documentation of  HttpHost.getAddress() Returns the inet 
> address if explicitly set by a constructor, null otherwise.
> 

There are different ways to approach the problem
(1) Have full control over hostname resolution by using a custom
DnsResolver
(2) Get hold of active connections from a custom subsclass of
HttpRequestExecutor 

Oleg
  



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



How to retrieve server ip of the connected connections

2016-06-09 Thread Vicky Singh



 I am using PoolingHttpClientConnectionManager to create connections. I would 
like to get what IP address my connections resolve to. Is there a API that I 
can use.
I need it for reporting and also to drop connections if I think connected IP is 
not the best IP address. I found this 
https://issues.apache.org/jira/browse/HTTPCLIENT-656  

Summary of my code,
PoolingHttpClientConnectionManager connMgr = new 
PoolingHttpClientConnectionManager(socketFactoryRegistry);        // build 
custom http client . ...        Set hosts = connMgr.getRoutes();     
   for (HttpRoute r: hosts) {            InetAddress ip = 
r.getTargetHost().getAddress();            break;        }
The above code gets an IP only if HttpHost was created using IP in constructor 
. From documentation of  HttpHost.getAddress() Returns the inet address if 
explicitly set by a constructor, null otherwise.