permaculture playing cards*
The moose likes Sockets and Internet Protocols and the fly likes CookieManager doesn't send cookies?    Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "CookieManager doesn Watch "CookieManager doesn New topic
Author

CookieManager doesn't send cookies?

John De Vries
Greenhorn

Joined: Feb 03, 2008
Posts: 4
Problem:
CookieManager stores cookies in the CookieStore after visiting urls, but it does not seem to retrieve cookies from the cookiestore when creating http requests.
It this a bug ?

To test cookies, I made a simple php page that displays and sets cookies: http://www.vitaminb5acne.com/testcookies.php

The Java HTTP client code that I use to test CookieManager:


Executing this code, shows that the webpage returns cookies, but that cookies aren't retrieved from the CookieStore of CookieManager when making a second HTTP request.....

Does anybody know what is going wrong?
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
I wrestled with this awhile, dummying up some code - I do not see where you are setting any cookies.


"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."
John De Vries
Greenhorn

Joined: Feb 03, 2008
Posts: 4
Originally posted by Nicholas Jordan:
I wrestled with this awhile, dummying up some code - I do not see where you are setting any cookies.

Cookies are set via the webpage.

I looked into the source code of CookieManager etc, and found multiple bugs. Making CookieManager almost useless when using it has httpclient.

One of the bugs is that cookies than contain the "expires" attribute (which most cookies do), aren't stored on Operating System that does not have a English locale by default. This is caused by the parser of HttpCookie, which is parsing using the default locale instead of an English locale.
So on a LOT OF systems, CookieManager won't even store simple cookies.

Another important bug is that the path and domain info is not stored in the HttpCookie when using CookieManager. Those cookies will be ignored when CookieManager is trying to fetch cookies based on the URI.
So all cookies that are managed automatically via CookieManager, are simply ignored.

These major bugs make Cookiemanager almost useless.
I have submitted these bugs to the Sun Bug database.
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
Well this is sure not greenhorn level of work. I do have one question:Cookies are set via the webpage?

I thought server-side set cookies on client-side, by webpage do you infer the entire browser-server interaction ? I have no experience with php, sounds like you develop under that model.
John De Vries
Greenhorn

Joined: Feb 03, 2008
Posts: 4
I meant what you say.

So the webserver tells the client to set the cookies using "Set-Cookie" in the HTTP response. The Java HTTP state management mechanism of the Java client then automatically calls CookieManager to put the HttpCookies in the CookieStore. At least, that is what it should do when the bugs are fixed.

Then, when the client makes a second request to the webpage, the cookies are automatically retrieved by CookieManager from the CookieStore and put in the HTTP request header. And again, at least, when the bugs are fixed.

What surprises me is that this buggy code is in the Api, while the scenario above won't work on most computer systems.

But, fixing these bugs only takes about 5 lines of code
[ February 04, 2008: Message edited by: John De Vries ]
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
Originally posted by John De Vries:
What surprises me is that this buggy code is in the Api, while the scenario above won't work on most computer systems.

But, fixing these bugs only takes about 5 lines of code

Tread lightly, these people will narrow things down to the beginner's specific interest every time.

I meant what you say. That's what I thought.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41109
    
  45
Not having used Java 6 so far I wasn't aware of CookieManager, but now I've just searched the Sun Bug Database for it: http://bugs.sun.com/bugdatabase/search.do?process=1&category=java&keyword=cookiemanager

You're right that there are several basic bugs, some of which are targeted for fixing in Java 7. Ugh. The bloating of the class libraries at the expense of quality has really gotten out of hand. Not to mention that there are bugs a lot older than this in it, but that's a different subject.

In any case, this looks indeed like the class is unusable. Thanks to the good folks at Apache for HttpClient.


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: CookieManager doesn't send cookies?
 
Similar Threads
HttpURLConnection or URLConnection to login in to sites
Unable to access tomcat protected resource using Cookie manager for JSessionID
Passing cookies back and forth
Java Application using webpages for profile changes
Applet cookie access and retrieval