You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Laura Werner <la...@lwerner.org> on 2003/05/06 02:15:02 UTC
Why is the HttpConnectionManager a field in HttpState?
Hi,
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?)
Laura
Re: Why is the HttpConnectionManager a field in HttpState?
Posted by Ortwin Glück <or...@nose.ch>.
Definitely ugly.
Laura Werner wrote:
> Hi,
>
> 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.