hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adrian Sutton <adr...@intencha.com>
Subject Re: question about HttpState
Date Mon, 25 Aug 2003 21:12:35 GMT
On 26/08/2003 2:27 AM, "Yue Luo" <yue.luo@sun.com> wrote:

> Hi,
>  I want to do the following:
> 1. The main thread/conneciton logins to a web site.  It is a post
> request like a online banking login, not HTTP authentication.  The
> server will return a cookie containing session id.
> 2. Then the main thread creates two simultaneous threads to create two
> connections to send two queries to the web site. Of course the cookie
> needs to be sent with the get request.
> My questions are:
> 1. Can the two subsequent threads/connections use the HttpState from the
> main thread/connection directly?  Or, should I clone two HttpState for
> the two sub-threads?  Does the clone() method of HttpState work properly?

Yes, you should use 1 instance of HttpClient and make sure you are using the
MultiThreadedHttpConnectionManager.  So something like:

HttpClient client = new HttpClient(new
PostMethod login = new PostMethod(...);

Create as many threads as you like to do something like:
GetMethod get = new GetMethod(...);

You should probably take a look at the multithreading guide:

> 2. Do HttpState.addCookies() and HttpState.getCookies() create COPIES
> of the cookies or work on the cookie objects directly?
> 3. This question is somewhat related to the above one.
> client.executeMethod(method1);
> Cookies[] cookie1=state.getState().getCooies();
> client.executeMethod(method2);
> Cookies[] cookie2=state.getState().getCooies();
> If the server changes some cookies in the second method, will the cookie
> objects in cookie1[] be changed?

On this I couldn't be entirely certain and don't have time to analyse the
code right now, though you could certainly do it yourself or even easier,
just test it and find out. :)

> Yue


Adrian Sutton.
Intencha "tomorrow's technology today"
Ph: 38478913 0422236329
Suite 8/29 Oatland Crescent
Holland Park West 4121
Australia QLD

View raw message