On Mon, 2014-04-28 at 23:33 +0000, Nitu Choudhary wrote:
> I am using InternalHttpClient and would like to print the local port on which 
> the request was made. If the request was successful, I can use the 
> HttpClientContext to retrieve the local port number. However, if an 
> IOException is thrown, I am unable to get the local port number as it fails 
> with ConnectionShutdownException.
> 
> Can you please help me find out how I can get local port number for all 
> requests?
> 
> Regards,
> nitu

---
CloseableHttpClient hc = HttpClients.custom()
    .addInterceptorLast(new HttpResponseInterceptor() {
        @Override
        public void process(
                final HttpResponse response,
                final HttpContext context) throws HttpException,
IOException {
            HttpClientContext localContext =
HttpClientContext.adapt(context);
            HttpInetConnection conn =
localContext.getConnection(HttpInetConnection.class);
            System.out.println(conn.getLocalPort());

        }
    })
    .build();
HttpGet get = new HttpGet("http://google.com/";);
CloseableHttpResponse response = hc.execute(get);
try {

} finally {
    response.close();
}
---

Oleg


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to