You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Naresh Agarwal <na...@yahoo.com> on 2005/05/23 15:31:47 UTC

session maintenance with two different HttpClient objects

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.
 
Basically, I've a special requirement to use *two different* instances of HttpClient to communicate with same web service (which needs session maintenance).
 
Am I missing something? Does session maintenace works only if all the operations are called using same HttpClient object?
 
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 

Re: session maintenance with two different HttpClient objects

Posted by Oleg Kalnichevski <ol...@apache.org>.
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

Oleg


> 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


R: session maintenance with two different HttpClient objects

Posted by Andrea Sodomaco <an...@sodomaco.it>.
Hi, 
Try 
	obj2.setState(obj1.getState());

can it help you?

Andrea Sodomaco


-----Messaggio originale-----
Da: Naresh Agarwal [mailto:naresh_iitd@yahoo.com] 
Inviato: lunedì 23 maggio 2005 15.32
A: httpclient-user@jakarta.apache.org
Oggetto: session maintenance with two different HttpClient objects

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.
 
Basically, I've a special requirement to use *two different* instances
of HttpClient to communicate with same web service (which needs session
maintenance).
 
Am I missing something? Does session maintenace works only if all the
operations are called using same HttpClient object?
 
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