< prev index next >

src/java.base/share/classes/java/net/CookieManager.java

Print this page




  45  *                  use
  46  * CookieHandler <------- HttpURLConnection
  47  *       ^
  48  *       | impl
  49  *       |         use
  50  * CookieManager -------> CookiePolicy
  51  *             |   use
  52  *             |--------> HttpCookie
  53  *             |              ^
  54  *             |              | use
  55  *             |   use        |
  56  *             |--------> CookieStore
  57  *                            ^
  58  *                            | impl
  59  *                            |
  60  *                  Internal in-memory implementation
  61  * }</pre>
  62  * <ul>
  63  *   <li>
  64  *     CookieHandler is at the core of cookie management. User can call
  65  *     CookieHandler.setDefault to set a concrete CookieHanlder implementation
  66  *     to be used.
  67  *   </li>
  68  *   <li>
  69  *     CookiePolicy.shouldAccept will be called by CookieManager.put to see whether
  70  *     or not one cookie should be accepted and put into cookie store. User can use
  71  *     any of three pre-defined CookiePolicy, namely ACCEPT_ALL, ACCEPT_NONE and
  72  *     ACCEPT_ORIGINAL_SERVER, or user can define his own CookiePolicy implementation
  73  *     and tell CookieManager to use it.
  74  *   </li>
  75  *   <li>
  76  *     CookieStore is the place where any accepted HTTP cookie is stored in.
  77  *     If not specified when created, a CookieManager instance will use an internal
  78  *     in-memory implementation. Or user can implements one and tell CookieManager
  79  *     to use it.
  80  *   </li>
  81  *   <li>
  82  *     Currently, only CookieStore.add(URI, HttpCookie) and CookieStore.get(URI)
  83  *     are used by CookieManager. Others are for completeness and might be needed
  84  *     by a more sophisticated CookieStore implementation, e.g. a NetscapeCookieStore.
  85  *   </li>


 337                             if (shouldAcceptInternal(uri, cookie)) {
 338                                 cookieJar.add(uri, cookie);
 339                             }
 340                         }
 341                     }
 342                 } catch (IllegalArgumentException e) {
 343                     // invalid set-cookie header string
 344                     // no-op
 345                 }
 346             }
 347         }
 348     }
 349 
 350 
 351     /* ---------------- Private operations -------------- */
 352 
 353     // to determine whether or not accept this cookie
 354     private boolean shouldAcceptInternal(URI uri, HttpCookie cookie) {
 355         try {
 356             return policyCallback.shouldAccept(uri, cookie);
 357         } catch (Exception ignored) { // pretect against malicious callback
 358             return false;
 359         }
 360     }
 361 
 362 
 363     private static boolean isInPortList(String lst, int port) {
 364         int i = lst.indexOf(',');
 365         int val = -1;
 366         while (i > 0) {
 367             try {
 368                 val = Integer.parseInt(lst, 0, i, 10);
 369                 if (val == port) {
 370                     return true;
 371                 }
 372             } catch (NumberFormatException numberFormatException) {
 373             }
 374             lst = lst.substring(i+1);
 375             i = lst.indexOf(',');
 376         }
 377         if (!lst.isEmpty()) {




  45  *                  use
  46  * CookieHandler <------- HttpURLConnection
  47  *       ^
  48  *       | impl
  49  *       |         use
  50  * CookieManager -------> CookiePolicy
  51  *             |   use
  52  *             |--------> HttpCookie
  53  *             |              ^
  54  *             |              | use
  55  *             |   use        |
  56  *             |--------> CookieStore
  57  *                            ^
  58  *                            | impl
  59  *                            |
  60  *                  Internal in-memory implementation
  61  * }</pre>
  62  * <ul>
  63  *   <li>
  64  *     CookieHandler is at the core of cookie management. User can call
  65  *     CookieHandler.setDefault to set a concrete CookieHandler implementation
  66  *     to be used.
  67  *   </li>
  68  *   <li>
  69  *     CookiePolicy.shouldAccept will be called by CookieManager.put to see whether
  70  *     or not one cookie should be accepted and put into cookie store. User can use
  71  *     any of three pre-defined CookiePolicy, namely ACCEPT_ALL, ACCEPT_NONE and
  72  *     ACCEPT_ORIGINAL_SERVER, or user can define his own CookiePolicy implementation
  73  *     and tell CookieManager to use it.
  74  *   </li>
  75  *   <li>
  76  *     CookieStore is the place where any accepted HTTP cookie is stored in.
  77  *     If not specified when created, a CookieManager instance will use an internal
  78  *     in-memory implementation. Or user can implements one and tell CookieManager
  79  *     to use it.
  80  *   </li>
  81  *   <li>
  82  *     Currently, only CookieStore.add(URI, HttpCookie) and CookieStore.get(URI)
  83  *     are used by CookieManager. Others are for completeness and might be needed
  84  *     by a more sophisticated CookieStore implementation, e.g. a NetscapeCookieStore.
  85  *   </li>


 337                             if (shouldAcceptInternal(uri, cookie)) {
 338                                 cookieJar.add(uri, cookie);
 339                             }
 340                         }
 341                     }
 342                 } catch (IllegalArgumentException e) {
 343                     // invalid set-cookie header string
 344                     // no-op
 345                 }
 346             }
 347         }
 348     }
 349 
 350 
 351     /* ---------------- Private operations -------------- */
 352 
 353     // to determine whether or not accept this cookie
 354     private boolean shouldAcceptInternal(URI uri, HttpCookie cookie) {
 355         try {
 356             return policyCallback.shouldAccept(uri, cookie);
 357         } catch (Exception ignored) { // protect against malicious callback
 358             return false;
 359         }
 360     }
 361 
 362 
 363     private static boolean isInPortList(String lst, int port) {
 364         int i = lst.indexOf(',');
 365         int val = -1;
 366         while (i > 0) {
 367             try {
 368                 val = Integer.parseInt(lst, 0, i, 10);
 369                 if (val == port) {
 370                     return true;
 371                 }
 372             } catch (NumberFormatException numberFormatException) {
 373             }
 374             lst = lst.substring(i+1);
 375             i = lst.indexOf(',');
 376         }
 377         if (!lst.isEmpty()) {


< prev index next >