hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <oleg.kalnichev...@bearingpoint.com>
Subject Re: Problem with Preferences Architecture
Date Wed, 29 Sep 2004 12:29:40 GMT

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


Mime
View raw message