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.
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 ]
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.
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop