You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Cabbar Duzayak <dc...@yahoo.com> on 2004/05/12 09:32:49 UTC

HttpClient initialization, when/where?

Hi,

I will be writing a gateway which will invoke URLs in
behalf of several threads and they will return the
content. Each thread needs to invoke different URLs
with different context (cookies, etc).

It looks like right way of doing this is to
instantiate the HttpClient once with
MultiThreadedHttpConnectionManager and each thread
will use httpClient.executeMethod on this HttpClient
instance. Or the other alternative is to instantiate
one object for each thread, and keep calling
executeMethods on them. 

However, since you can set the state of the
HttpClient, I was wondering if I can use the
HttpClient for iterative http invocations with
different contexts? I mean, is there an in-memory
state other than the HttpState that is preserved
between these invocations? Would it be enough to
create an HttpState and GetMethod for each call, and
set it before calling executeMethod? 

Shortly, what is the optimum mechanism for this
functionality?

TIA...



	
		
__________________________________
Do you Yahoo!?
Yahoo! Movies - Buy advance tickets for 'Shrek 2'
http://movies.yahoo.com/showtimes/movie?mid=1808405861 

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


Cookie Bug?

Posted by Cabbar Duzayak <dc...@yahoo.com>.
Hi,

I am trying to run the following code for
www.google.com:

Cookie cookie = initialState.getCookies()[0];
CookieSpec cs = CookiePolicy.getDefaultSpec();
Header h = cs.formatCookieHeader(cookie);
Cookie[] cookie2 = cs.parse(cookie.getDomain(), 80,
cookie.getPath(), cookie.getSecure(), h);

And, it is throwing an exception as:

"org.apache.commons.httpclient.cookie.MalformedCookieException:
Cookie name may not start with $"

It looks like h.getValue returns name with $ sign
(which was indeed created by the cookiespec), but the
same cookiespec can not read this back, because it has
a $ sign???

BTW, h.getValue() is:

$Version=0;
PREF=ID=069e080d47cd4332:TM=1084362072:LM=1084362072:S=0u9G4CTYGPvhxJzn;
$Domain=.google.com; $Path=/

Looks like, cookieSpec.parse is expecting the same
string without $ signs, in fact, when I remove dollar
signs manually, the code works fine.

Did I hit the jackpot and found a bug;)

Thanks...



	
		
__________________________________
Do you Yahoo!?
Yahoo! Movies - Buy advance tickets for 'Shrek 2'
http://movies.yahoo.com/showtimes/movie?mid=1808405861 

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


Re: HttpClient initialization, when/where?

Posted by Cabbar Duzayak <dc...@yahoo.com>.
Well,

This information is more than I need;)

Appreciate your help.

--- Roland Weber <RO...@de.ibm.com> wrote:
> Hi Duzayak (?),
> 
> the MultiThreadedHCM is called so because it allows
> for multiple threads to use the same HttpClient. It
> has
> to be used if the application is multithreaded.
> 
> The connection pool limits the number of
> simultaneous
> connections, to a particular host and in general. It
> keeps
> resource usage in check. Also, if there are many
> requests
> to the same host, open connections may be reused,
> which avoids the overhead of establishing a new
> connection for each request.
> If you want to know how it works, feel free to look
> at
> the source code. It's open :-)
> 
> cheers,
>   Roland
> 
> 
> 
> 
> 
> Cabbar Duzayak <dc...@yahoo.com>
> 12.05.2004 12:26
> Please respond to "Commons HttpClient Project"
>  
>         To:     Commons HttpClient Project 
> <co...@jakarta.apache.org>
>         cc: 
>         Subject:        Re: HttpClient
> initialization, when/where?
> 
> 
> Can you please elaborate a bit how this connection
> pool and multithreaded HCM work? Cause, given that
> httpclient will be executed within my thread, why do
> we need a multithreaded HCM? Also, connection pool
> is
> used for sharing connections between threads? How
> exactly does it work, what does it improve?
> 
> Thanks a lot for the information!
> 
> 
> 
> 



	
		
__________________________________
Do you Yahoo!?
Yahoo! Movies - Buy advance tickets for 'Shrek 2'
http://movies.yahoo.com/showtimes/movie?mid=1808405861 

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


Re: HttpClient initialization, when/where?

Posted by Roland Weber <RO...@de.ibm.com>.
Hi Duzayak (?),

the MultiThreadedHCM is called so because it allows
for multiple threads to use the same HttpClient. It has
to be used if the application is multithreaded.

The connection pool limits the number of simultaneous
connections, to a particular host and in general. It keeps
resource usage in check. Also, if there are many requests
to the same host, open connections may be reused,
which avoids the overhead of establishing a new
connection for each request.
If you want to know how it works, feel free to look at
the source code. It's open :-)

cheers,
  Roland





Cabbar Duzayak <dc...@yahoo.com>
12.05.2004 12:26
Please respond to "Commons HttpClient Project"
 
        To:     Commons HttpClient Project 
<co...@jakarta.apache.org>
        cc: 
        Subject:        Re: HttpClient initialization, when/where?


Can you please elaborate a bit how this connection
pool and multithreaded HCM work? Cause, given that
httpclient will be executed within my thread, why do
we need a multithreaded HCM? Also, connection pool is
used for sharing connections between threads? How
exactly does it work, what does it improve?

Thanks a lot for the information!




Re: HttpClient initialization, when/where?

Posted by Cabbar Duzayak <dc...@yahoo.com>.
Can you please elaborate a bit how this connection
pool and multithreaded HCM work? Cause, given that
httpclient will be executed within my thread, why do
we need a multithreaded HCM? Also, connection pool is
used for sharing connections between threads? How
exactly does it work, what does it improve?

Thanks a lot for the information!

--- Roland Weber <RO...@de.ibm.com> wrote:
> Hello,
> 
> you need one HttpState for each thread, since the
> cookies
> are stored there. Creating a new state for each
> request will
> not work, unless the threads manage the cookies
> themselves.
> 
> The HttpClient is associated with a connection pool.
> If
> you require independently configured connection
> pools
> for each thread, you have to create multiple
> HttpClient
> objects. Otherwise, one HttpClient with
> MultiThreadedHCM
> is ok.
> 
> hope that helps,
>   Roland
> 
> 
> 
> 
> 
> 
> Cabbar Duzayak <dc...@yahoo.com>
> 12.05.2004 09:32
> Please respond to "Commons HttpClient Project"
>  
>         To:    
> commons-httpclient-dev@jakarta.apache.org
>         cc: 
>         Subject:        HttpClient initialization,
> when/where?
> 
> 
> Hi,
> 
> I will be writing a gateway which will invoke URLs
> in
> behalf of several threads and they will return the
> content. Each thread needs to invoke different URLs
> with different context (cookies, etc).
> 
> It looks like right way of doing this is to
> instantiate the HttpClient once with
> MultiThreadedHttpConnectionManager and each thread
> will use httpClient.executeMethod on this HttpClient
> instance. Or the other alternative is to instantiate
> one object for each thread, and keep calling
> executeMethods on them. 
> 
> However, since you can set the state of the
> HttpClient, I was wondering if I can use the
> HttpClient for iterative http invocations with
> different contexts? I mean, is there an in-memory
> state other than the HttpState that is preserved
> between these invocations? Would it be enough to
> create an HttpState and GetMethod for each call, and
> set it before calling executeMethod? 
> 
> Shortly, what is the optimum mechanism for this
> functionality?
> 
> TIA...
> 
> 
> 
>  
>  
> __________________________________
> Do you Yahoo!?
> Yahoo! Movies - Buy advance tickets for 'Shrek 2'
>
http://movies.yahoo.com/showtimes/movie?mid=1808405861
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail: 
>
commons-httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: 
> commons-httpclient-dev-help@jakarta.apache.org
> 
> 
> 



	
		
__________________________________
Do you Yahoo!?
Yahoo! Movies - Buy advance tickets for 'Shrek 2'
http://movies.yahoo.com/showtimes/movie?mid=1808405861 

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


Re: HttpClient initialization, when/where?

Posted by Roland Weber <RO...@de.ibm.com>.
Hello,

you need one HttpState for each thread, since the cookies
are stored there. Creating a new state for each request will
not work, unless the threads manage the cookies themselves.

The HttpClient is associated with a connection pool. If
you require independently configured connection pools
for each thread, you have to create multiple HttpClient
objects. Otherwise, one HttpClient with MultiThreadedHCM
is ok.

hope that helps,
  Roland






Cabbar Duzayak <dc...@yahoo.com>
12.05.2004 09:32
Please respond to "Commons HttpClient Project"
 
        To:     commons-httpclient-dev@jakarta.apache.org
        cc: 
        Subject:        HttpClient initialization, when/where?


Hi,

I will be writing a gateway which will invoke URLs in
behalf of several threads and they will return the
content. Each thread needs to invoke different URLs
with different context (cookies, etc).

It looks like right way of doing this is to
instantiate the HttpClient once with
MultiThreadedHttpConnectionManager and each thread
will use httpClient.executeMethod on this HttpClient
instance. Or the other alternative is to instantiate
one object for each thread, and keep calling
executeMethods on them. 

However, since you can set the state of the
HttpClient, I was wondering if I can use the
HttpClient for iterative http invocations with
different contexts? I mean, is there an in-memory
state other than the HttpState that is preserved
between these invocations? Would it be enough to
create an HttpState and GetMethod for each call, and
set it before calling executeMethod? 

Shortly, what is the optimum mechanism for this
functionality?

TIA...



 
 
__________________________________
Do you Yahoo!?
Yahoo! Movies - Buy advance tickets for 'Shrek 2'
http://movies.yahoo.com/showtimes/movie?mid=1808405861 

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