hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Naresh Agarwal <naresh_i...@yahoo.com>
Subject Re: session maintenance with two different HttpClient objects
Date Tue, 24 May 2005 09:37:33 GMT
Hi Oleg,
thanks for reply!
I agree that reusing HTTPClient will help improve performance. However in my scenario I'm
calling the two operations (which need session maintenance) in two different entities, which
can not share anything through memory.  So instead of relying on automatic session maintenance,
we are explicitly extracting the cookie from response of "login" operation and setting it
in request of "getDetails" operation.
However, if we use two different objects of HttpClient for calling login and getDetails, 2nd
call is failing. 
1. Why the second call is failing inspite of the fact that we are setting the same cookie.
Is it because that cookie is associated with underlying physical connection and each HttpClient
object has its own connection?
2. It we use same HttpClient object (with manual extracting and setting cookies), it works
fine. Is it because both operations are using same underlying connection?
3. What is right way to maintain session with two different HttpClient objects as required
in our scenario?
thanks & regards,
Naresh Agarwal 
But it is failing in the case of two objects.
1) obj1.executeMethod(

Oleg Kalnichevski <olegk@apache.org> wrote:
On Mon, May 23, 2005 at 06:31:47AM -0700, Naresh Agarwal wrote:
> Hi 
> I'm using HttpClient library for writing a specialized http client.
> Let's say I have two instances of HttpClient object obj1 and obj2, which communicate
with same application running in web server. This application provide two operations - "login"
and "getDetails", which need session maintenance using cookies. 
> I am using obj1 and obj2 as follows - 
> 1. Call "login" operation using obj1 and extract the cookie from the response.
> 2. Call "getDetails" operation using obj2 after setting cookie extracted in step 1.
> But my "getDetails" fails saying that login is required. However, if I use obj1 in step
2, it works fine.

Possibly there are more than one cookie involved.

> Basically, I've a special requirement to use *two different* instances of HttpClient
to communicate with same web service (which needs session maintenance).

HttpClient maintains the session state using an instance of a class
called HttpState. One can easily override the default HTTP state object
by specifying a different one as a parameter to HttpClient#executeMethod
call. In your particular case I do not think you have to maintain two
distinct instances of HttpClient. It may be sufficient to simply maintain
two HttpState instances and use the same HttpClient instance to execute
requests. The benefit of minimizing the number of HttpClient distances
involved is the potential performance improvement through the reuse of
persistent connections.

> Am I missing something? Does session maintenace works only if all the operations are
called using same HttpClient object?

This is not the case.

Hope this helps


> Any help will be greatly appreciated.
> thanks & regards,
> Naresh Agarwal
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 

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

Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message