Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7059532

CookieManager - some cookies are not stored in CookieJar

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 7
    • core-libs
    • generic, x86
    • generic, windows_xp

      FULL PRODUCT VERSION :
      java version "1.7.0"
      Java(TM) SE Runtime Environment (build 1.7.0-b146)
      Java HotSpot(TM) Client VM (build 21.0-b16, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      When in the same HTTP response the cookie is deleted and set (for example with different value), the CookieManager does not store it.
      A typical web browser does store the cookie correctly, and there are web pages that both delete and set cookies in the same response, therefore the CookieManager should be able to handle them correctly.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. create a server resource (web page) that will both delete and set the same cookie in one request. For example the following HTTP response sets TWO cookies, one of them is both deleted and set:
      -----------------------------------------------
      HTTP/1.1 200 OK
      Date: Sun, 26 Jun 2011 09:15:46 GMT
      Server: Apache/2.2.17 (Win32) mod_ssl/2.2.17 OpenSSL/0.9.8o PHP/5.3.4 mod_perl/2.0.4 Perl/v5.10.1
      X-Powered-By: PHP/5.3.5
      Set-Cookie: cookie_test=deleted; expires=Sat, 26-Jun-2010 09:15:45 GMT
      Set-Cookie: cookie_test=cookie_value; expires=Sun, 26-Jun-2011 10:15:46 GMT
      Set-Cookie: other_cookie=other_value; expires=Sun, 26-Jun-2011 10:15:46 GMT
      Content-Length: 7
      Content-Type: text/html


      hello!
      -----------------------------------------------

      2. Get the cookies following the example code from http://download.oracle.com/javase/tutorial/deployment/doingMoreWithRIA/accessingCookies.html.
      (see "Source code for an executable test case")

      3. check in the output that only one cookie was retrieved correctly:
      CookieHandler retrieved cookie: other_cookie=other_value

      the "test_cookie" is missing, although any web browser captures it correctly.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      A typical web browser does store the cookie correctly, and there are web pages that both delete and set cookies in the same response, therefore the CookieManager should be able to handle them correctly.

      In terms of the attached example, the CookieJar should contain both "cookie_test" and "other_cookie" cookies.

      ACTUAL -
      In terms of the attached example, the CookieJar contains only "other_cookie" cookie, and "cookie_test" is missing.



      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.net.CookieHandler;
      import java.net.CookieManager;
      import java.net.CookiePolicy;
      import java.net.CookieStore;
      import java.net.HttpCookie;
      import java.net.URL;
      import java.net.URLConnection;
      import java.util.List;

      /* test code comes from: http://download.oracle.com/javase/tutorial/deployment/doingMoreWithRIA/accessingCookies.html */

      public class CookieTest {
      public static void main(String[] args) throws Exception {
      CookieManager manager = new CookieManager();
      manager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
      CookieHandler.setDefault(manager);

      // get content from URLConnection; cookies are set by web site

      URLConnection connection = new URL("http://127.0.0.1/cookie_test/").openConnection();
      connection.getContent();

      // get cookies from underlying CookieStore
      CookieStore cookieJar = manager.getCookieStore();
      List<HttpCookie> cookies = cookieJar.getCookies();
      for (HttpCookie cookie : cookies) {
      System.out.println("CookieHandler retrieved cookie: " + cookie);
      }
      }
      }


      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      the possible workaround is to write custom CookieManager implementation that changes sorting of response headers, so that the 'deleted' header comes first.

            michaelm Michael McMahon
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: