hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kalnichevski, Oleg" <oleg.kalnichev...@bearingpoint.com>
Subject RE: Why is the HttpConnectionManager a field in HttpState?
Date Tue, 06 May 2003 08:14:32 GMT

In my opinion HttpConnectionManager has nothing to do with the HTTP state information. It
should not be coupled with HttpState class. I suggest we deprecate HttpState#getHttpConnectionManager
& HttpState#setHttpConnectionManager methods


-----Original Message-----
From: Laura Werner [mailto:laura@lwerner.org]
Sent: Tuesday, May 06, 2003 02:15
To: Commons HttpClient Project
Subject: Why is the HttpConnectionManager a field in HttpState?


I just discovered a sort of a gotcha with the patch I submitted on 
Friday.  Imagine code like this:

HttpConnectionManager manager = new MultiThreadedHttpConnectionManager();
HttpClient myClient = new HttpClient(manager);
HttpState myState = new HttpState();
myClient.executeMethod(hostConfig, method, myState);

This didn't behave the way I expected, because HttpClient.executeMethod 
ends up calling HttpState.getHttpConnectionManager() to find the 
connection manager to use.  I had naively expected it to use the manager 
that I passed in to the constructor, but that one is only used for 
constructing the HttpClient's default HttpState object.

I'm not entirely sure what to do about this.  One option would be to add 
another argument to my overload of executeMethod and allow the 
connection manager to be passed in as well.  If it's null, the one from 
the HttpState would be used.  This works but makes the API fairly 
complicated semantically.  Does anyone have a better idea?

The way I'm working around this in the short term is by calling 
myState.setHttpConnectionManager(manager) before each call to 
executeMethod.  But that's *really* ugly and maybe not thread-safe.  
(Are writes atomic in Java?)


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

View raw message