hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Roland Weber <http-as...@dubioso.net>
Subject Re: HttpClient & custom host names resolving
Date Mon, 29 Jan 2007 15:34:22 GMT
Hello Erwan,

> instance variables of HttpConnection to "protected", in order to be
> able to override open() in an inheriting class. This creates code
> duplication (because open() has a lot of logic inside), but seems to
> provide the service.

How that? Didn't you say you want to switch based on any information
in the request? You don't have access to the HttpMethod from within
the connection. Besides, you need to change the connection manager
as well, because the connection class is derived there. That creates
ugly mutual dependencies between the modified HttpClient code and
your code.

> If there is another, more simple or proper way of doing that, i'd be
> happy to hear about it ;-)

Simple *and* proper? Not with 3.x I'm afraid ;-(

If you have to change the HttpClient code anyway, you can either
put your code directly in place, or you could implement hook methods
to be overridden by derived classes:

   open(...) throws... {
      WhatINeed win = createSocketHook(...);
      Socket s = new Socket(...win...);

Another alternative is that you write your own socket factory and
access the HttpMethod object (=request) from a ThreadLocal attribute
somewhere. Damn, I should have thought about that in the first place.
Let the application put the method in a ThreadLocal just before
HttpClient.execute is called. The socket factory will be called by
the same thread. You tell HttpClient to use your own socket factory
by registering instances of the Protocol class:

hope that helps,

To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org

View raw message