hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Telvis Calhoun Jr." <telvi...@gmail.com>
Subject Re: [HttpClient 4] local socket port
Date Fri, 20 Jul 2012 18:41:52 GMT
Your problem seems similar to mine. Oleg recommended extending the
DefaultClientConnectionOperator class to add the socket attribute to
the context. Something like:

class MyClientConnectionOperator extends DefaultClientConnectionOperator {

    public MyClientConnectionOperator(SchemeRegistry schemes) {
        super(schemes);
    }

    @Override
    protected void prepareSocket(
            final Socket sock,
            final HttpContext context,
            final HttpParams params) throws IOException {
        super.prepareSocket(sock, context, params);
        context.setAttribute("sock-port", sock.getLocalPort());
    }

};

// thread
http://old.nabble.com/get-InetAddress-for-the-HTTP_TARGET_HOST-tt34157287.html


On Fri, Jul 20, 2012 at 11:06 AM, Wolfram Alpha
<wolfram.alpha2012@googlemail.com> wrote:
> Hi
>
> I'm using the Apache HttpClient 4.1.2 and I want to get the local port of
> the underlying socket. I have not found a reasonable way to get the
> port-number without changing a lot of the httpclient code, which I don't
> want to do.
>
> Is there realy no easy way to get the port-number?
>
> Any suggestions are appreciated!
>
> Thanks

---------------------------------------------------------------------
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