Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

session mismanagement in Netscape using HttpURLConnection  RSS feed

 
Muddassar Shaikh
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,



for (int i=1; (headerName = connection.getHeaderFieldKey(i)) != null; i++)
{
if (headerName.equalsIgnoreCase(SET_COOKIE))
{
Map cookie = new HashMap();
StringTokenizer st = new StringTokenizer(connection.getHeaderField(i), COOKIE_VALUE_DELIMITER);
if (st.hasMoreTokens())
{
String token = st.nextToken();
String name = token.substring(0, token.indexOf(NAME_VALUE_SEPARATOR));
String value = token.substring(token.indexOf(NAME_VALUE_SEPARATOR) + 1, token.length());
cookie.put(name, value);
cookieMap.put(name,cookie);
}
}
}

After retrieving the cookie I set it in the HTTP response.
Map cookie = (Map)cookieMap.get(cookieName);
httpResponse.addCookie(new Cookie(cookieName,(String)cookie.get(cookieName)));

and when i post the request in subsequent flow I set the cookies in the "Cookie" field of the header.
httpURLConnection.setRequestProperty("Cookie",getKookies(httpRequest.getKookies()));

where get cookies in a private method which returns a semicolon seperated list of cookies.

This works fine in IE and the session is maintained.
But the session is not maintained in Netscape or Mozilla.

Any pointers to the solution or to the flaws in the logic used would be helpful.

Thank you.
Moody
 
Anupam Sinha
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
May be cookie are not getting saved in Mozilla and netscape. Try the httpLiveHeaders for Mozilla Firefox and see if the value is getting set properly and also check if cookie saving is set to off.
 
Muddassar Shaikh
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The cookies are getting saved in both Mozilla and Netscape. I think the problem begins when i read the cookies and set them in the connection while "POST"ing to the application.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to "Sockets and Internet Protocols".
 
Muddassar Shaikh
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried retaining the cookie in my session and then sending it back to the calling servlet. The problem still persists.
when I set the "Cookie" in HTTP header, I jst set the name=value pair of the cookie and nothing else. Is it dependant on the browser? or the server?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!