hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: Print local port when using httpclient
Date Wed, 30 Apr 2014 09:05:20 GMT
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: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Mime
View raw message