• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

session mismanagement in Netscape using HttpURLConnection

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to "Sockets and Internet Protocols".
 
Muddassar Shaikh
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
There’s no place like 127.0.0.1. But I'll always remember this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic