Java Code Examples for java.net.HttpCookie#hasExpired()
The following examples show how to use
java.net.HttpCookie#hasExpired() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CookieNegativeMaxAge.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public static void main(String... args) { HttpCookie cookie = new HttpCookie("testCookie", "value"); cookie.setMaxAge(Integer.MIN_VALUE); if (cookie.hasExpired()) { throw new RuntimeException("Cookie has unexpectedly expired"); } List<HttpCookie> cookies = HttpCookie.parse("Set-Cookie: " + "expiredCookie=value; expires=Thu, 01 Jan 1970 00:00:00 GMT"); if (cookies.size() == 1) { if (cookies.get(0).getMaxAge() != 0) { throw new RuntimeException("Cookie maxAge expected to be 0"); } } else { throw new RuntimeException("Header was incorrectly parsed"); } }
Example 2
Source File: PersistentCookieStore.java From AndroidStudyDemo with GNU General Public License v2.0 | 6 votes |
@Override public void add(URI uri, HttpCookie cookie) { String name = getCookieToken(uri, cookie); // Save cookie into local store, or remove if expired if (!cookie.hasExpired()) { if (!mCookieMap.containsKey(uri.getHost())) mCookieMap.put(uri.getHost(), new ConcurrentHashMap<String, HttpCookie>()); mCookieMap.get(uri.getHost()).put(name, cookie); } else { if (mCookieMap.containsKey(uri.toString())) mCookieMap.get(uri.getHost()).remove(name); } // Save cookie into persistent store SharedPreferences.Editor prefsWriter = mCookiePrefs.edit(); prefsWriter.putString(uri.getHost(), TextUtils.join(",", mCookieMap.get(uri.getHost()).keySet())); prefsWriter.putString(COOKIE_NAME_PREFIX + name, encodeCookie(new SerializableHttpCookie(cookie))); prefsWriter.commit(); }
Example 3
Source File: PersistentCookieStore.java From mattermost-android-classic with Apache License 2.0 | 6 votes |
@Override public void add(URI uri, HttpCookie cookie) { String name = getCookieToken(uri, cookie); String host = uri.getHost(); if (!cookie.hasExpired()) { if (!cookies.containsKey(host)) cookies.put(host, new ConcurrentHashMap<String, HttpCookie>()); cookies.get(host).put(name, cookie); } else { if (cookies.containsKey(uri.toString())) cookies.get(host).remove(name); } ConcurrentHashMap<String, HttpCookie> c = cookies.get(host); if (c == null) return; SharedPreferences.Editor prefsWriter = cookiePrefs.edit(); prefsWriter.putString(host, TextUtils.join(",", cookies.get(host).keySet())); prefsWriter.putString(COOKIE_NAME_PREFIX + name, encodeCookie(new SerializableHttpCookie(cookie))); prefsWriter.commit(); }
Example 4
Source File: PersistentCookieStore.java From NewsMe with Apache License 2.0 | 6 votes |
@Override public void add(URI uri, HttpCookie cookie) { String name = getCookieToken(uri, cookie); // Save cookie into local store, or remove if expired if (!cookie.hasExpired()) { if (!cookies.containsKey(uri.getHost())) cookies.put(uri.getHost(), new ConcurrentHashMap<String, HttpCookie>()); cookies.get(uri.getHost()).put(name, cookie); } else { if (cookies.containsKey(uri.toString())) cookies.get(uri.getHost()).remove(name); } // Save cookie into persistent store SharedPreferences.Editor prefsWriter = cookiePrefs.edit(); prefsWriter.putString(uri.getHost(), TextUtils.join(",", cookies.get(uri.getHost()).keySet())); prefsWriter.putString(COOKIE_NAME_PREFIX + name, encodeCookie(new SerializableHttpCookie(cookie))); prefsWriter.commit(); }
Example 5
Source File: InMemoryCookieStore.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
private <T> void getInternal2(List<HttpCookie> cookies, Map<T, List<HttpCookie>> cookieIndex, Comparable<T> comparator, boolean secureLink) { for (T index : cookieIndex.keySet()) { if (comparator.compareTo(index) == 0) { List<HttpCookie> indexedCookies = cookieIndex.get(index); // check the list of cookies associated with this domain if (indexedCookies != null) { Iterator<HttpCookie> it = indexedCookies.iterator(); while (it.hasNext()) { HttpCookie ck = it.next(); if (cookieJar.indexOf(ck) != -1) { // the cookie still in main cookie store if (!ck.hasExpired()) { // don't add twice if ((secureLink || !ck.getSecure()) && !cookies.contains(ck)) cookies.add(ck); } else { it.remove(); cookieJar.remove(ck); } } else { // the cookie has beed removed from main store, // so also remove it from domain indexed store it.remove(); } } } // end of indexedCookies != null } // end of comparator.compareTo(index) == 0 } // end of cookieIndex iteration }
Example 6
Source File: InMemoryCookieStore.java From JDKSourceCode1.8 with MIT License | 5 votes |
private <T> void getInternal2(List<HttpCookie> cookies, Map<T, List<HttpCookie>> cookieIndex, Comparable<T> comparator, boolean secureLink) { for (T index : cookieIndex.keySet()) { if (comparator.compareTo(index) == 0) { List<HttpCookie> indexedCookies = cookieIndex.get(index); // check the list of cookies associated with this domain if (indexedCookies != null) { Iterator<HttpCookie> it = indexedCookies.iterator(); while (it.hasNext()) { HttpCookie ck = it.next(); if (cookieJar.indexOf(ck) != -1) { // the cookie still in main cookie store if (!ck.hasExpired()) { // don't add twice if ((secureLink || !ck.getSecure()) && !cookies.contains(ck)) cookies.add(ck); } else { it.remove(); cookieJar.remove(ck); } } else { // the cookie has beed removed from main store, // so also remove it from domain indexed store it.remove(); } } } // end of indexedCookies != null } // end of comparator.compareTo(index) == 0 } // end of cookieIndex iteration }
Example 7
Source File: InMemoryCookieStore.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private <T> void getInternal2(List<HttpCookie> cookies, Map<T, List<HttpCookie>> cookieIndex, Comparable<T> comparator, boolean secureLink) { for (T index : cookieIndex.keySet()) { if (comparator.compareTo(index) == 0) { List<HttpCookie> indexedCookies = cookieIndex.get(index); // check the list of cookies associated with this domain if (indexedCookies != null) { Iterator<HttpCookie> it = indexedCookies.iterator(); while (it.hasNext()) { HttpCookie ck = it.next(); if (cookieJar.indexOf(ck) != -1) { // the cookie still in main cookie store if (!ck.hasExpired()) { // don't add twice if ((secureLink || !ck.getSecure()) && !cookies.contains(ck)) cookies.add(ck); } else { it.remove(); cookieJar.remove(ck); } } else { // the cookie has beed removed from main store, // so also remove it from domain indexed store it.remove(); } } } // end of indexedCookies != null } // end of comparator.compareTo(index) == 0 } // end of cookieIndex iteration }
Example 8
Source File: PersistentCookieStore.java From DaVinci with Apache License 2.0 | 5 votes |
private List<HttpCookie> getValidCookies(URI uri) { List<HttpCookie> targetCookies = new ArrayList<HttpCookie>(); // If the stored URI does not have a path then it must match any URI in // the same domain for (URI storedUri : allCookies.keySet()) { // Check ith the domains match according to RFC 6265 if (checkDomainsMatch(storedUri.getHost(), uri.getHost())) { // Check if the paths match according to RFC 6265 if (checkPathsMatch(storedUri.getPath(), uri.getPath())) { targetCookies.addAll(allCookies.get(storedUri)); } } } // Check it there are expired cookies and remove them if (!targetCookies.isEmpty()) { List<HttpCookie> cookiesToRemoveFromPersistence = new ArrayList<HttpCookie>(); for (Iterator<HttpCookie> it = targetCookies.iterator(); it .hasNext(); ) { HttpCookie currentCookie = it.next(); if (currentCookie.hasExpired()) { cookiesToRemoveFromPersistence.add(currentCookie); it.remove(); } } if (!cookiesToRemoveFromPersistence.isEmpty()) { removeFromPersistence(uri, cookiesToRemoveFromPersistence); } } return targetCookies; }
Example 9
Source File: InMemoryCookieStore.java From Bytecoder with Apache License 2.0 | 5 votes |
private <T> void getInternal2(List<HttpCookie> cookies, Map<T, List<HttpCookie>> cookieIndex, Comparable<T> comparator, boolean secureLink) { for (T index : cookieIndex.keySet()) { if (comparator.compareTo(index) == 0) { List<HttpCookie> indexedCookies = cookieIndex.get(index); // check the list of cookies associated with this domain if (indexedCookies != null) { Iterator<HttpCookie> it = indexedCookies.iterator(); while (it.hasNext()) { HttpCookie ck = it.next(); if (cookieJar.indexOf(ck) != -1) { // the cookie still in main cookie store if (!ck.hasExpired()) { // don't add twice if ((secureLink || !ck.getSecure()) && !cookies.contains(ck)) cookies.add(ck); } else { it.remove(); cookieJar.remove(ck); } } else { // the cookie has been removed from main store, // so also remove it from domain indexed store it.remove(); } } } // end of indexedCookies != null } // end of comparator.compareTo(index) == 0 } // end of cookieIndex iteration }
Example 10
Source File: InMemoryCookieStore.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private <T> void getInternal2(List<HttpCookie> cookies, Map<T, List<HttpCookie>> cookieIndex, Comparable<T> comparator, boolean secureLink) { for (T index : cookieIndex.keySet()) { if (comparator.compareTo(index) == 0) { List<HttpCookie> indexedCookies = cookieIndex.get(index); // check the list of cookies associated with this domain if (indexedCookies != null) { Iterator<HttpCookie> it = indexedCookies.iterator(); while (it.hasNext()) { HttpCookie ck = it.next(); if (cookieJar.indexOf(ck) != -1) { // the cookie still in main cookie store if (!ck.hasExpired()) { // don't add twice if ((secureLink || !ck.getSecure()) && !cookies.contains(ck)) cookies.add(ck); } else { it.remove(); cookieJar.remove(ck); } } else { // the cookie has beed removed from main store, // so also remove it from domain indexed store it.remove(); } } } // end of indexedCookies != null } // end of comparator.compareTo(index) == 0 } // end of cookieIndex iteration }
Example 11
Source File: PersistentCookieStore.java From FimiX8-RE with MIT License | 5 votes |
public void add(URI uri, HttpCookie cookie) { String name = getCookieToken(uri, cookie); if (!cookie.hasExpired()) { if (!this.cookies.containsKey(uri.getHost())) { this.cookies.put(uri.getHost(), new ConcurrentHashMap()); } ((ConcurrentHashMap) this.cookies.get(uri.getHost())).put(name, cookie); } else if (this.cookies.containsKey(uri.toString())) { ((ConcurrentHashMap) this.cookies.get(uri.getHost())).remove(name); } Editor prefsWriter = this.cookiePrefs.edit(); prefsWriter.putString(uri.getHost(), TextUtils.join(",", ((ConcurrentHashMap) this.cookies.get(uri.getHost())).keySet())); prefsWriter.putString(COOKIE_NAME_PREFIX + name, encodeCookie(new SerializableHttpCookie(cookie))); prefsWriter.commit(); }
Example 12
Source File: InMemoryCookieStore.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private <T> void getInternal2(List<HttpCookie> cookies, Map<T, List<HttpCookie>> cookieIndex, Comparable<T> comparator, boolean secureLink) { for (T index : cookieIndex.keySet()) { if (comparator.compareTo(index) == 0) { List<HttpCookie> indexedCookies = cookieIndex.get(index); // check the list of cookies associated with this domain if (indexedCookies != null) { Iterator<HttpCookie> it = indexedCookies.iterator(); while (it.hasNext()) { HttpCookie ck = it.next(); if (cookieJar.indexOf(ck) != -1) { // the cookie still in main cookie store if (!ck.hasExpired()) { // don't add twice if ((secureLink || !ck.getSecure()) && !cookies.contains(ck)) cookies.add(ck); } else { it.remove(); cookieJar.remove(ck); } } else { // the cookie has beed removed from main store, // so also remove it from domain indexed store it.remove(); } } } // end of indexedCookies != null } // end of comparator.compareTo(index) == 0 } // end of cookieIndex iteration }
Example 13
Source File: InMemoryCookieStore.java From Java8CN with Apache License 2.0 | 5 votes |
private <T> void getInternal2(List<HttpCookie> cookies, Map<T, List<HttpCookie>> cookieIndex, Comparable<T> comparator, boolean secureLink) { for (T index : cookieIndex.keySet()) { if (comparator.compareTo(index) == 0) { List<HttpCookie> indexedCookies = cookieIndex.get(index); // check the list of cookies associated with this domain if (indexedCookies != null) { Iterator<HttpCookie> it = indexedCookies.iterator(); while (it.hasNext()) { HttpCookie ck = it.next(); if (cookieJar.indexOf(ck) != -1) { // the cookie still in main cookie store if (!ck.hasExpired()) { // don't add twice if ((secureLink || !ck.getSecure()) && !cookies.contains(ck)) cookies.add(ck); } else { it.remove(); cookieJar.remove(ck); } } else { // the cookie has beed removed from main store, // so also remove it from domain indexed store it.remove(); } } } // end of indexedCookies != null } // end of comparator.compareTo(index) == 0 } // end of cookieIndex iteration }
Example 14
Source File: mutableInputs.java From JavaSCR with MIT License | 5 votes |
public void useMutableInput(HttpCookie cookie) { Objects.requireNonNull(cookie, "cookie cannot be null"); //$NON-NLS-1$ // Check whether cookie has expired if (cookie.hasExpired()) { throw new IllegalArgumentException(); } // Cookie may have expired since time of check doLogic(cookie); }
Example 15
Source File: InMemoryCookieStore.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
private <T> void getInternal2(List<HttpCookie> cookies, Map<T, List<HttpCookie>> cookieIndex, Comparable<T> comparator, boolean secureLink) { for (T index : cookieIndex.keySet()) { if (comparator.compareTo(index) == 0) { List<HttpCookie> indexedCookies = cookieIndex.get(index); // check the list of cookies associated with this domain if (indexedCookies != null) { Iterator<HttpCookie> it = indexedCookies.iterator(); while (it.hasNext()) { HttpCookie ck = it.next(); if (cookieJar.indexOf(ck) != -1) { // the cookie still in main cookie store if (!ck.hasExpired()) { // don't add twice if ((secureLink || !ck.getSecure()) && !cookies.contains(ck)) cookies.add(ck); } else { it.remove(); cookieJar.remove(ck); } } else { // the cookie has beed removed from main store, // so also remove it from domain indexed store it.remove(); } } } // end of indexedCookies != null } // end of comparator.compareTo(index) == 0 } // end of cookieIndex iteration }
Example 16
Source File: InMemoryCookieStore.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private <T> void getInternal2(List<HttpCookie> cookies, Map<T, List<HttpCookie>> cookieIndex, Comparable<T> comparator, boolean secureLink) { for (T index : cookieIndex.keySet()) { if (comparator.compareTo(index) == 0) { List<HttpCookie> indexedCookies = cookieIndex.get(index); // check the list of cookies associated with this domain if (indexedCookies != null) { Iterator<HttpCookie> it = indexedCookies.iterator(); while (it.hasNext()) { HttpCookie ck = it.next(); if (cookieJar.indexOf(ck) != -1) { // the cookie still in main cookie store if (!ck.hasExpired()) { // don't add twice if ((secureLink || !ck.getSecure()) && !cookies.contains(ck)) cookies.add(ck); } else { it.remove(); cookieJar.remove(ck); } } else { // the cookie has beed removed from main store, // so also remove it from domain indexed store it.remove(); } } } // end of indexedCookies != null } // end of comparator.compareTo(index) == 0 } // end of cookieIndex iteration }
Example 17
Source File: InMemoryCookieStore.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
private <T> void getInternal2(List<HttpCookie> cookies, Map<T, List<HttpCookie>> cookieIndex, Comparable<T> comparator, boolean secureLink) { for (T index : cookieIndex.keySet()) { if (comparator.compareTo(index) == 0) { List<HttpCookie> indexedCookies = cookieIndex.get(index); // check the list of cookies associated with this domain if (indexedCookies != null) { Iterator<HttpCookie> it = indexedCookies.iterator(); while (it.hasNext()) { HttpCookie ck = it.next(); if (cookieJar.indexOf(ck) != -1) { // the cookie still in main cookie store if (!ck.hasExpired()) { // don't add twice if ((secureLink || !ck.getSecure()) && !cookies.contains(ck)) cookies.add(ck); } else { it.remove(); cookieJar.remove(ck); } } else { // the cookie has beed removed from main store, // so also remove it from domain indexed store it.remove(); } } } // end of indexedCookies != null } // end of comparator.compareTo(index) == 0 } // end of cookieIndex iteration }
Example 18
Source File: InMemoryCookieStore.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
private <T> void getInternal2(List<HttpCookie> cookies, Map<T, List<HttpCookie>> cookieIndex, Comparable<T> comparator, boolean secureLink) { for (T index : cookieIndex.keySet()) { if (comparator.compareTo(index) == 0) { List<HttpCookie> indexedCookies = cookieIndex.get(index); // check the list of cookies associated with this domain if (indexedCookies != null) { Iterator<HttpCookie> it = indexedCookies.iterator(); while (it.hasNext()) { HttpCookie ck = it.next(); if (cookieJar.indexOf(ck) != -1) { // the cookie still in main cookie store if (!ck.hasExpired()) { // don't add twice if ((secureLink || !ck.getSecure()) && !cookies.contains(ck)) cookies.add(ck); } else { it.remove(); cookieJar.remove(ck); } } else { // the cookie has beed removed from main store, // so also remove it from domain indexed store it.remove(); } } } // end of indexedCookies != null } // end of comparator.compareTo(index) == 0 } // end of cookieIndex iteration }
Example 19
Source File: InMemoryCookieStore.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private <T> void getInternal2(List<HttpCookie> cookies, Map<T, List<HttpCookie>> cookieIndex, Comparable<T> comparator, boolean secureLink) { for (T index : cookieIndex.keySet()) { if (comparator.compareTo(index) == 0) { List<HttpCookie> indexedCookies = cookieIndex.get(index); // check the list of cookies associated with this domain if (indexedCookies != null) { Iterator<HttpCookie> it = indexedCookies.iterator(); while (it.hasNext()) { HttpCookie ck = it.next(); if (cookieJar.indexOf(ck) != -1) { // the cookie still in main cookie store if (!ck.hasExpired()) { // don't add twice if ((secureLink || !ck.getSecure()) && !cookies.contains(ck)) cookies.add(ck); } else { it.remove(); cookieJar.remove(ck); } } else { // the cookie has beed removed from main store, // so also remove it from domain indexed store it.remove(); } } } // end of indexedCookies != null } // end of comparator.compareTo(index) == 0 } // end of cookieIndex iteration }
Example 20
Source File: Api.java From ratebeer with GNU General Public License v3.0 | 5 votes |
private boolean haveLoginCookie() { if (cookieManager.getCookieStore().getCookies().isEmpty()) return false; boolean hasUserCookie = false, hasSessionCookie = false; for (HttpCookie cookie : cookieManager.getCookieStore().getCookies()) { if (cookie.getName().equals(COOKIE_USERID) && !TextUtils.isEmpty(cookie.getValue()) && !cookie.hasExpired()) hasUserCookie = true; if (cookie.getName().equals(COOKIE_SESSIONID) && !TextUtils.isEmpty(cookie.getValue()) && !cookie.hasExpired()) hasSessionCookie = true; } return hasUserCookie && hasSessionCookie; }