You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Vikram Goyal <te...@craftbits.com> on 2004/09/29 11:14:50 UTC

Problem with Preferences Architecture

Hello,

I am not sure if this is a bug or I am not running this right.

I am trying to get the preferences architecture to modify the http.useragent
property at the client level, and then retrieve the value at the method and
host level. The value gets percolated down to the Method level but the Host
level value does not change and gives the global value. See code below.

As per the 3.0 B2 documentation, the Method and Host params should try and
retrieve the value of the http.useragent from their local cache, and if it
they do not find it, should go up the heirarchy, till they reach the global
params. Since in the code below, the value is set at the Client level, one
lower than the Global level, it should be retrieved from the Client level
for both Method and Host params.

Regards,
Vikram

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.HostConfiguration;

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();
 }
}



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


Re: Problem with Preferences Architecture

Posted by Oleg Kalnichevski <ol...@apache.org>.
> Actually the new Preferences Architecture is quite neat and great if it all
> works. It is only the HostConfiguration that does not work and I would love
> to figure out why.
> 

Vikram,

I believe the problem with HostConfiguration has been fixed in CVS HEAD.
We'd love to hear from you if now you find the new preferences
architecture working as expected.

Cheers,

Oleg


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


Re: Problem with Preferences Architecture

Posted by Oleg Kalnichevski <ol...@apache.org>.
> Actually the new Preferences Architecture is quite neat and great if it all
> works. It is only the HostConfiguration that does not work and I would love
> to figure out why.

Vikram,
Basically it appears that (1) we assume it should work one way, (2)
whereas you assume it should work quite the other way around, (3) and on
top of that the Hostconfiguration code appears broken. ;-)

As soon as we all agree to how exactly things are supposed to work, I'll
fix the code and everything should go back to normal.

So, please bear with us for a while, and keep on giving us feedback.
I'll do my best to have the first take on the fix done by the end of the
day.

Cheers,

Oleg


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


Re: Problem with Preferences Architecture

Posted by Vikram Goyal <te...@craftbits.com>.
>
>
> > 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.
>
> Vikram,
> That is why HttpClient 3.0 is still ALPHA. We are grateful to you for
> experimenting with the preferences architecture and giving us the
> feedback. I agree HostConfiguration stuff is ugly and am working on
> fixing it right now
>
> Oleg
>

Actually the new Preferences Architecture is quite neat and great if it all
works. It is only the HostConfiguration that does not work and I would love
to figure out why.



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


Re: Problem with Preferences Architecture

Posted by Oleg Kalnichevski <ol...@bearingpoint.com>.

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

Vikram,
That is why HttpClient 3.0 is still ALPHA. We are grateful to you for
experimenting with the preferences architecture and giving us the
feedback. I agree HostConfiguration stuff is ugly and am working on
fixing it right now

Oleg  

***************************************************************************************************
The information in this email is confidential and may be legally privileged.  Access to this email by anyone other than the intended addressee is unauthorized.  If you are not the intended recipient of this message, any review, disclosure, copying, distribution, retention, or any action taken or omitted to be taken in reliance on it is prohibited and may be unlawful.  If you are not the intended recipient, please reply to or forward a copy of this message to the sender and delete the message, any attachments, and any copies thereof from your system.
***************************************************************************************************

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


Re: Problem with Preferences Architecture

Posted by Ortwin Glück <or...@nose.ch>.

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


Re: Problem with Preferences Architecture

Posted by Vikram Goyal <te...@craftbits.com>.
>
> Vikram Goyal wrote:
>
> > No that is not right either. Because the HostConfiguration is created
using
> > the supplied HostConfiguration in line 389 as you say, the parameters
from
> > the supplied HostConfiguration are used to clone parameters for the new
> > HostConfiguration, so they should all be same. See
HostConfiguration.java
> > line 126.
>
> Yes, but the information is only held in a temporary object and is not
> fed back to the object you pass into the execute call.

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.

>
> > Even if I use the Client's HostConfiguration using
> > client.getHostConfiguration instead of using my own HostConfiguration
and
> > using it in the executeMethod call, the problem remains.
>
> Of course.
>
> Why do you want to query the params objects outside HttpClient anyway?

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.

Vikram

>
> > Vikram
> -- 
>   _________________________________________________________________
>   NOSE applied intelligence ag
>
>   ortwin glück                      [www]      http://www.nose.ch
>   software engineer
>   hardturmstrasse 171               [pgp id]           0x81CF3416
>   8005 zürich                       [office]      +41-1-277 57 35
>   switzerland                       [fax]         +41-1-277 57 12
>
> ---------------------------------------------------------------------
> 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


Re: Problem with Preferences Architecture

Posted by Ortwin Glück <or...@nose.ch>.

Vikram Goyal wrote:

> No that is not right either. Because the HostConfiguration is created using
> the supplied HostConfiguration in line 389 as you say, the parameters from
> the supplied HostConfiguration are used to clone parameters for the new
> HostConfiguration, so they should all be same. See HostConfiguration.java
> line 126.

Yes, but the information is only held in a temporary object and is not 
fed back to the object you pass into the execute call.

> Even if I use the Client's HostConfiguration using
> client.getHostConfiguration instead of using my own HostConfiguration and
> using it in the executeMethod call, the problem remains.

Of course.

Why do you want to query the params objects outside HttpClient anyway?

> Vikram
-- 
  _________________________________________________________________
  NOSE applied intelligence ag

  ortwin glück                      [www]      http://www.nose.ch
  software engineer
  hardturmstrasse 171               [pgp id]           0x81CF3416
  8005 zürich                       [office]      +41-1-277 57 35
  switzerland                       [fax]         +41-1-277 57 12

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


Re: Problem with Preferences Architecture

Posted by Vikram Goyal <te...@craftbits.com>.
No that is not right either. Because the HostConfiguration is created using
the supplied HostConfiguration in line 389 as you say, the parameters from
the supplied HostConfiguration are used to clone parameters for the new
HostConfiguration, so they should all be same. See HostConfiguration.java
line 126.

Even if I use the Client's HostConfiguration using
client.getHostConfiguration instead of using my own HostConfiguration and
using it in the executeMethod call, the problem remains.

Vikram

> The problem is, that HttpClient creates a new HostConfiguration object
> internally and sets default on that. So your original object is not
> modified. So within HttpClient the host configuration will use the right
> user agent string. But you can not see this from the outside.
>
> This is line 389 in HttpClient.java (HEAD):
>   HostConfiguration methodConfiguration = new
> HostConfiguration(hostConfiguration);
>



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


Re: Problem with Preferences Architecture

Posted by Oleg Kalnichevski <ol...@bearingpoint.com>.
Probably that's not the way it is supposed to be. I'll see what can be
done about it.

Oleg

On Wed, 2004-09-29 at 11:53, Ortwin Glück wrote:
> Vikram Goyal wrote:
>
> > Hello,
> >
> > I am not sure if this is a bug or I am not running this right.
> >
> > I am trying to get the preferences architecture to modify the http.useragent
> > property at the client level, and then retrieve the value at the method and
> > host level. The value gets percolated down to the Method level but the Host
> > level value does not change and gives the global value. See code below.
> >
> > As per the 3.0 B2 documentation, the Method and Host params should try and
> > retrieve the value of the http.useragent from their local cache, and if it
> > they do not find it, should go up the heirarchy, till they reach the global
> > params. Since in the code below, the value is set at the Client level, one
> > lower than the Global level, it should be retrieved from the Client level
> > for both Method and Host params.
>
> Vikram, please ignore my first post.
>
> The problem is, that HttpClient creates a new HostConfiguration object
> internally and sets default on that. So your original object is not
> modified. So within HttpClient the host configuration will use the right
> user agent string. But you can not see this from the outside.
>
> This is line 389 in HttpClient.java (HEAD):
>   HostConfiguration methodConfiguration = new
> HostConfiguration(hostConfiguration);
>
> Ortwin Glück

***************************************************************************************************
The information in this email is confidential and may be legally privileged.  Access to this email by anyone other than the intended addressee is unauthorized.  If you are not the intended recipient of this message, any review, disclosure, copying, distribution, retention, or any action taken or omitted to be taken in reliance on it is prohibited and may be unlawful.  If you are not the intended recipient, please reply to or forward a copy of this message to the sender and delete the message, any attachments, and any copies thereof from your system.
***************************************************************************************************

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


Re: Problem with Preferences Architecture

Posted by Ortwin Glück <or...@nose.ch>.

Vikram Goyal wrote:

> Hello,
> 
> I am not sure if this is a bug or I am not running this right.
> 
> I am trying to get the preferences architecture to modify the http.useragent
> property at the client level, and then retrieve the value at the method and
> host level. The value gets percolated down to the Method level but the Host
> level value does not change and gives the global value. See code below.
> 
> As per the 3.0 B2 documentation, the Method and Host params should try and
> retrieve the value of the http.useragent from their local cache, and if it
> they do not find it, should go up the heirarchy, till they reach the global
> params. Since in the code below, the value is set at the Client level, one
> lower than the Global level, it should be retrieved from the Client level
> for both Method and Host params.

Vikram, please ignore my first post.

The problem is, that HttpClient creates a new HostConfiguration object 
internally and sets default on that. So your original object is not 
modified. So within HttpClient the host configuration will use the right 
user agent string. But you can not see this from the outside.

This is line 389 in HttpClient.java (HEAD):
  HostConfiguration methodConfiguration = new 
HostConfiguration(hostConfiguration);

Ortwin Glück


-- 
  _________________________________________________________________
  NOSE applied intelligence ag

  ortwin glück                      [www]      http://www.nose.ch
  software engineer
  hardturmstrasse 171               [pgp id]           0x81CF3416
  8005 zürich                       [office]      +41-1-277 57 35
  switzerland                       [fax]         +41-1-277 57 12

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


Re: Problem with Preferences Architecture

Posted by Vikram Goyal <te...@craftbits.com>.
>
> The problem in your code is, that the host params are not set at all.
> You should add something along the lines of:
> host.setParams(new HostParams(client.getParams()));
>
> Ortwin Glück

That does not seem to be right. I haven't added any Method params either,
but that works. Anyways, even when I add a param, it still does not work.

Regards,
Vikram



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


Re: Problem with Preferences Architecture

Posted by Ortwin Glück <or...@nose.ch>.

Vikram Goyal wrote:

> Hello,
> 
> I am not sure if this is a bug or I am not running this right.
> 
> I am trying to get the preferences architecture to modify the http.useragent
> property at the client level, and then retrieve the value at the method and
> host level. The value gets percolated down to the Method level but the Host
> level value does not change and gives the global value. See code below.
> 
> As per the 3.0 B2 documentation, the Method and Host params should try and
> retrieve the value of the http.useragent from their local cache, and if it
> they do not find it, should go up the heirarchy, till they reach the global
> params. Since in the code below, the value is set at the Client level, one
> lower than the Global level, it should be retrieved from the Client level
> for both Method and Host params.
> 
> Regards,
> Vikram

The problem in your code is, that the host params are not set at all.
You should add something along the lines of:
host.setParams(new HostParams(client.getParams()));

Ortwin Glück
-- 
  _________________________________________________________________
  NOSE applied intelligence ag

  ortwin glück                      [www]      http://www.nose.ch
  software engineer
  hardturmstrasse 171               [pgp id]           0x81CF3416
  8005 zürich                       [office]      +41-1-277 57 35
  switzerland                       [fax]         +41-1-277 57 12

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


Re: Problem with Preferences Architecture

Posted by Vikram Goyal <te...@craftbits.com>.
Thanks Oleg for the explanations, but what you are saying seems to
contradict the current code structure.

> I assume you'd still want this method to be executed against
> http://www.anothercompnany.com/ not http://www.mycompnany.com/, right?

Actually no! I would expect it to be run against mycompany.com and not
anothercompany.com, as I am explicitly passing a host configuration. This is
the case with the current code anyways, as can be tested by running a simple
example (see the code example of running against Google and Yahoo later)

> So, if you want to know the exact host parameters applied during the
> method execution, you should call
>
> ===================================================================
>
> method.getHostConfguration().getParams().getParameter("http.useragent"));
> ===================================================================

As I said earlier, this is not right. I tried it, but as expected, it still
doesn't work. Please see the code below:

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.HostConfiguration;

public class HttpClientParameterV1 {

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

  HttpClient client = new HttpClient();
  client.getParams().setParameter("http.useragent", "My Browser");

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

  GetMethod method = new GetMethod("http://www.yahoo.com");

  int returnCode = client.executeMethod(host, method); // connects to Google
and not Yahoo

  System.err.println(method.getResponseBodyAsString());

  System.err.println("User-Agent: " +

method.getHostConfiguration().getParams().getParameter("http.useragent"));
// Still prints default useragent info

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

  method.releaseConnection();
 }
}

Vikram



----- Original Message ----- 
From: "Oleg Kalnichevski" <ol...@bearingpoint.com>
To: "Commons HttpClient Project" <co...@jakarta.apache.org>
Sent: Wednesday, September 29, 2004 10:29 PM
Subject: Re: Problem with Preferences Architecture


>
> Vikram,
>
> I hope what is to follow will clarify things a little
>
> (1)
> ===================================================================
> HostConfiguration host = new HostConfiguration();
> host.setHost("www.google.com");
> ===================================================================
>
> These are the defaults that apply only when some host parameters have
> not been explicitly defined by the method itself. Thus, they are not
> supposed to mutate as a result of method execution
>
> Consider the following:
> ===================================================================
> HttpClient client = new HttpClient();
>
> HostConfiguration hostconfig = new HostConfiguration();
> hostconfig.setHost("www.mycompnany.com");
>
> HttpMethod httpget = new GetMethod("http://www.anothercompnany.com/");
>
> client.executeMethod(hostconfig, httpget);
> ===================================================================
>
> I assume you'd still want this method to be executed against
> http://www.anothercompnany.com/ not http://www.mycompnany.com/, right?
>
> So, if you want to know the exact host parameters applied during the
> method execution, you should call
>
> ===================================================================
>
> method.getHostConfguration().getParams().getParameter("http.useragent"));
> ===================================================================
>
> Please let me know if that sounds reasonable/unreasonable
>
> (2)
> All this said, I have to admit that current host configuration related
> code is a horrible mess. I will provide a refactoring patch shortly
>
> Hope this helps
>
> Oleg
>
>
> On Wed, 2004-09-29 at 11:14, Vikram Goyal wrote:
> > Hello,
> >
> > I am not sure if this is a bug or I am not running this right.
> >
> > I am trying to get the preferences architecture to modify the
http.useragent
> > property at the client level, and then retrieve the value at the method
and
> > host level. The value gets percolated down to the Method level but the
Host
> > level value does not change and gives the global value. See code below.
> >
> > As per the 3.0 B2 documentation, the Method and Host params should try
and
> > retrieve the value of the http.useragent from their local cache, and if
it
> > they do not find it, should go up the heirarchy, till they reach the
global
> > params. Since in the code below, the value is set at the Client level,
one
> > lower than the Global level, it should be retrieved from the Client
level
> > for both Method and Host params.
> >
> > Regards,
> > Vikram
> >
> > import org.apache.commons.httpclient.HttpClient;
> > import org.apache.commons.httpclient.methods.GetMethod;
> > import org.apache.commons.httpclient.HostConfiguration;
> >
> > 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();
> >  }
> > }
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
commons-httpclient-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
commons-httpclient-dev-help@jakarta.apache.org
>
>
****************************************************************************
***********************
> The information in this email is confidential and may be legally
privileged.  Access to this email by anyone other than the intended
addressee is unauthorized.  If you are not the intended recipient of this
message, any review, disclosure, copying, distribution, retention, or any
action taken or omitted to be taken in reliance on it is prohibited and may
be unlawful.  If you are not the intended recipient, please reply to or
forward a copy of this message to the sender and delete the message, any
attachments, and any copies thereof from your system.
>
****************************************************************************
***********************
>
> ---------------------------------------------------------------------
> 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


Re: Problem with Preferences Architecture

Posted by Oleg Kalnichevski <ol...@bearingpoint.com>.
Vikram,

I hope what is to follow will clarify things a little

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

These are the defaults that apply only when some host parameters have
not been explicitly defined by the method itself. Thus, they are not
supposed to mutate as a result of method execution

Consider the following:
===================================================================
HttpClient client = new HttpClient();
 
HostConfiguration hostconfig = new HostConfiguration();
hostconfig.setHost("www.mycompnany.com");

HttpMethod httpget = new GetMethod("http://www.anothercompnany.com/");

client.executeMethod(hostconfig, httpget);
===================================================================

I assume you'd still want this method to be executed against
http://www.anothercompnany.com/ not http://www.mycompnany.com/, right?

So, if you want to know the exact host parameters applied during the
method execution, you should call

===================================================================

method.getHostConfguration().getParams().getParameter("http.useragent"));
===================================================================

Please let me know if that sounds reasonable/unreasonable

(2)
All this said, I have to admit that current host configuration related
code is a horrible mess. I will provide a refactoring patch shortly

Hope this helps

Oleg


On Wed, 2004-09-29 at 11:14, Vikram Goyal wrote:
> Hello,
> 
> I am not sure if this is a bug or I am not running this right.
> 
> I am trying to get the preferences architecture to modify the http.useragent
> property at the client level, and then retrieve the value at the method and
> host level. The value gets percolated down to the Method level but the Host
> level value does not change and gives the global value. See code below.
> 
> As per the 3.0 B2 documentation, the Method and Host params should try and
> retrieve the value of the http.useragent from their local cache, and if it
> they do not find it, should go up the heirarchy, till they reach the global
> params. Since in the code below, the value is set at the Client level, one
> lower than the Global level, it should be retrieved from the Client level
> for both Method and Host params.
> 
> Regards,
> Vikram
> 
> import org.apache.commons.httpclient.HttpClient;
> import org.apache.commons.httpclient.methods.GetMethod;
> import org.apache.commons.httpclient.HostConfiguration;
> 
> 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();
>  }
> }
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org

***************************************************************************************************
The information in this email is confidential and may be legally privileged.  Access to this email by anyone other than the intended addressee is unauthorized.  If you are not the intended recipient of this message, any review, disclosure, copying, distribution, retention, or any action taken or omitted to be taken in reliance on it is prohibited and may be unlawful.  If you are not the intended recipient, please reply to or forward a copy of this message to the sender and delete the message, any attachments, and any copies thereof from your system.
***************************************************************************************************

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