hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hentzen, Rudy" <rudy.hent...@etrade.com>
Subject RE: Problem with Preferences Architecture
Date Wed, 29 Sep 2004 13:03:21 GMT
Does that mean you don't recommend 3.0 for use...ummmm, damm I am boned, I was coding with
it.  Hopefully I can change to 2.0.2 quite easily!!

Rudy

-----Original Message-----
From: Ortwin Gl├╝ck [mailto:ortwin.glueck@nose.ch] 
Sent: 29 September 2004 14:00
To: Commons HttpClient Project
Subject: Re: Problem with Preferences Architecture



Vikram Goyal wrote:

> Sorry, I must be missing something, because I don't see it that way. The
> temporary object that you are talking about, methodConfiguration, is used to
> create the MethodDirector object that is used to execute the request. So it
> is passed to the execute call.

Okay. I explain in detail:

Your code:
--------------------------------
public class HttpClientTest {

  public static void main(String args[]) throws Exception {

   HttpClient client = new HttpClient();
   client.getParams().setParameter("http.useragent", "My Browser");  // set
the value here

   HostConfiguration host = new HostConfiguration();
   host.setHost("www.google.com");

   GetMethod method = new GetMethod("/");

   int returnCode = client.executeMethod(host, method);

   System.err.println("User-Agent: " +
     host.getParams().getParameter("http.useragent"));  // does not print My
Browser

   System.err.println("User-Agent: " +
     method.getParams().getParameter("http.useragent")); // prints My 
Browser

   method.releaseConnection();
  }
}
---------------------------------

http.useragent is set in the params object of client.

You create a new HostConfiguration host, that carries another new params 
object.

Upon the executeMethod call the following happens:
1. host is passed in
2. A copy of host ist created (methodConfiguration). This is a *deep* 
copy, i.e. carries it's own params object that is different from host's 
param object.
3. methodConfiguration and client params are passed to HttpMethodDirector
4. client params are set as the defaults for methodConfiguration param
5. methodConfiguration param are set as the defaults for method params

In step 4 your http.useragent value ends up beeing the default value for 
params object of the *copy* created in 2 of your HostConfiguration 
object. Your original host object has never been passsed to 
HttpMethodDirector and has not been altered.

That's simply why.

Now, the question of course is, *if* it is correct to create this deep 
copy in 2. I thinks we should always clone params objects that we 
receive from the outside. Otherwise this may get us into trouble if they 
are modified concurrently from another thread or so. It would be more OO 
design anyway (do not expose intrinsic state).


> I am testing the new Preferences Architecture before writing about it in a
> Book that I am working on. I have spent the whole of today looking at the
> source code but could not locate the problem, so it is bugging me now. It
> makes sense, the architecture I mean, but it is just not working right for
> the HostConfiguration.

Oh... now that you mention it, your name looks familiar. I guess the 
book will contain those three articles about Jakarta Commons as well. 
Watch out, 3.0 is ALPHA! API and contract may still change until the 
final version! Good luck with your book. May it become a bestseller.

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



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


Mime
View raw message