hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@lexmark.com
Subject Re: Cookies with multithreaded connection manager
Date Thu, 27 Jan 2005 17:26:51 GMT

Hi Oleg,

Yep, that helps in terms of submitting the right cookie...but then I have a
problem GETTING the session back for that particular thread!

I want everything to be happening at once, so obviously don't want to
synchronize on the whole call.  But as the cookie seems to be returned in
the HttpClient, when I have lots of threads running, I can't guarantee that
when I look in the client after I read the response that it holds the
session cookie for that particular thread - right?  (I'm calling
_httpClient.getState().getCookies() to get the session cookie).

Or am I missing something?  Is there any way to get the session for that
particular method?

cheers,

David




|---------+---------------------------->
|         |           Oleg Kalnichevski|
|         |           <olegk@apache.org|
|         |           >                |
|         |                            |
|         |           01/26/2005 06:06 |
|         |           PM               |
|         |           Please respond to|
|         |           "HttpClient User |
|         |           Discussion"      |
|         |                            |
|---------+---------------------------->
  >-----------------------------------------------------------------------------------------------------------------------|
  |                                                                                      
                                |
  |       To:       HttpClient User Discussion <httpclient-user@jakarta.apache.org>
                                      |
  |       cc:                                                                            
                                |
  |       Subject:  Re: Cookies with multithreaded connection manager - [was Re: Any  equivalent
to setReuseAddress()  to |
  |        true - ie reuse      sockets in TIME_WAIT    state]                           
                                |
  >-----------------------------------------------------------------------------------------------------------------------|




David,

Create a instance of HttpState per thread and pass it to
HttpClient#executeMethod as a parameter. This should do the trick

Oleg

On Wed, 2005-01-26 at 17:54 -0500, dhay@lexmark.com wrote:
> Hi,
>
> Thanks for the tip.  I have tried this, but ran into a problem with
cookies
> when using it.
>
> I created a single HttpClient instance, with a
> MultiThreadedHttpConnectionManager.  I pass this client to each thread
that
> I start.
>
> However, I also need to keep track of session information for each
thread,
> and am not sure how to do that in this model (I get another connection
from
> my caller, and hence another thread spawned, which must be part of the
same
> session).  I was just calling setState as follows if the thread was part
of
> a particular session like this:
>
>       if (_session != null)
>       {
>             // adding session cookie previously saved");
>             HttpState initialState = new HttpState();
>             initialState.addCookie(_session);
>             _httpClient.setState(initialState);
>       }
>
> This obviously doesn't work with multiple threads accessing the same
> HttpClient.
>
> What am I missing?  Is there another way to do cookies?
>
> thanks,
>
> David
>
>
>
> |---------+---------------------------->
> |         |           Oleg Kalnichevski|
> |         |           <olegk@apache.org|
> |         |           >                |
> |         |                            |
> |         |           01/24/2005 06:13 |
> |         |           PM               |
> |         |           Please respond to|
> |         |           "HttpClient User |
> |         |           Discussion"      |
> |         |                            |
> |---------+---------------------------->
>
>-----------------------------------------------------------------------------------------------------------------------|

>   |
|
>   |       To:       HttpClient User Discussion
<httpclient-user@jakarta.apache.org>
|
>   |       cc:
|
>   |       Subject:  Re: Any equivalent to setReuseAddress()  to true - ie
reuse       sockets in TIME_WAIT state          |
>
>-----------------------------------------------------------------------------------------------------------------------|

>
>
>
>
> David,
>
> What kind of connection manager are you using? If yes, consider using
> the so called multithreaded connection manager that maintains a pool of
> connections:
>
> http://jakarta.apache.org/commons/httpclient/3.0/threading.html
>
> Hope this helps,
>
> Oleg
>
> On Mon, 2005-01-24 at 15:04 -0500, dhay@lexmark.com wrote:
> > Hi,
> >
> > I am creating alot of connections to Tomcat 5 using HttpClient.  As a
> > result, I have a lot of sockets in the TIME_WAIT state, which lead to a
> > BindException - Connection In use.
> >
> > Is there any way to get the HttpClient to reuse these sockets akin to
> using
> > setReuseAddress(true) when using a plain socket?
> >
> > Any other suggestions?
> >
> > cheers,
> >
> > David
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
httpclient-user-help@jakarta.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
>


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






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


Mime
View raw message