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 Mrigank Shekhar <mr...@yahoo.com> on 2007/06/20 11:55:26 UTC

HTTP Client losing cookies when servers run behind a load balancer

Hi all,

It would be really great if someone can help me out with the following issue.

I have a small application with two pages, one page adds cookies and the second page just prints out the list of cookies.
When I run the application on a single server and use HTTP Client to simulate the requests, the behavior is as expected. the cookies get added and the list is displayed properly. 

The problem comes when I run the same application on a cluster hidden behind a load balancer.
The application when run from an actual browser runs fine and gives desired results.

But when I simulate the requests using HTTP Client, here is what I am getting:
The method client.getState().getCookies(); gives the correct set of cookies.
But when I put the following code in my jsp
<% 
        Cookie[] cookies = request.getCookies();
        System.out.println("-----------------------------------------");
        for(int i=0; i<cookies.length; i++){
            System.out.println("Name:" + cookies[i].getName());
            System.out.println("Value:" + cookies[i].getValue());
        }
        System.out.println("-----------------------------------------");
%>
the list of cookies getting returned is not correct. The number of cookies returned is correct. But the name of each cookie is JSESSIONID and the value is the JSESSIONID value. 
The same code runs fine when run through the actual browser and even with HTTP Client with single servers.

For single server deployments, the application url is http://localhost:7001/test.jsp
For cluster deployments, the load balancer runs at http://localhost:7001, the application is deployed on two servers http://localhost:8001 and http://localhost:9001. I access the application using the url http://localhost:7001.

It will be of great help if someone can help me out with the issue. 
I shall willingly provide any other information required to solve the issue.

Thanks a lot,
Mrigank.
 


       
____________________________________________________________________________________
Need a vacation? Get great deals
to amazing places on Yahoo! Travel.
http://travel.yahoo.com/