Java Code Examples for java.net.HttpCookie#getDomain()

The following examples show how to use java.net.HttpCookie#getDomain() . 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: CookieDBJar.java    From Nimingban with Apache License 2.0 6 votes vote down vote up
private Cookie httpCookie2Cookie(URL url, HttpCookie httpCookie) {
    String domain = httpCookie.getDomain();
    String path = httpCookie.getPath();
    if (TextUtils.isEmpty(domain)) {
        domain = url.getHost();
    }
    if (TextUtils.isEmpty(path)) {
        path = url.getPath();
    }

    Cookie.Builder builder = new Cookie.Builder()
            .name(httpCookie.getName())
            .value(httpCookie.getValue())
            .expiresAt(System.currentTimeMillis() + (httpCookie.getMaxAge() * 1000))
            .domain(domain)
            .path(path);
    if (httpCookie.getSecure()) {
        builder.secure();
    }
    return builder.build();
}
 
Example 2
Source File: DBCookieStore.java    From Kalle with Apache License 2.0 6 votes vote down vote up
@Override
public void remove(HttpCookie httpCookie) {
    mLock.lock();
    try {
        Where.Builder whereBuilder = Where.newBuilder().add(NAME, Where.Options.EQUAL, httpCookie.getName());

        String domain = httpCookie.getDomain();
        if (!TextUtils.isEmpty(domain)) whereBuilder.and(DOMAIN, Where.Options.EQUAL, domain);

        String path = httpCookie.getPath();
        if (!TextUtils.isEmpty(path)) {
            if (path.length() > 1 && path.endsWith("/")) {
                path = path.substring(0, path.length() - 1);
            }
            whereBuilder.and(PATH, Where.Options.EQUAL, path);
        }
        mCookieDao.delete(whereBuilder.build().toString());
    } finally {
        mLock.unlock();
    }
}
 
Example 3
Source File: ProfileEditFragment.java    From 4pdaClient-plus with Apache License 2.0 6 votes vote down vote up
protected void onPostExecute(final Boolean success) {
    setLoading(false);

    if (isCancelled()) return;

    if (success) {
        showThemeBody(m_ThemeBody);
    } else {
        getSupportActionBar().setTitle(ex.getMessage());
        m_WebView.loadDataWithBaseURL("https://4pda.ru/forum/", m_ThemeBody, "text/html", "UTF-8", null);
        AppLog.e(getMainActivity(), ex);
    }

    CookieSyncManager syncManager = CookieSyncManager.createInstance(m_WebView.getContext());
    CookieManager cookieManager = CookieManager.getInstance();

        for (HttpCookie cookie : Client.getInstance().getCookies()) {

            if (cookie.getDomain() != null) {
                cookieManager.setCookie(cookie.getDomain(), cookie.getName() + "=" + cookie.getValue());
            }
            //cookieManager.setCookie(cookie.getTitle(),cookie.getValue());
        }
    syncManager.sync();
}
 
Example 4
Source File: TestAuthenticationFilter.java    From big-c with Apache License 2.0 5 votes vote down vote up
private static void parseCookieMap(String cookieHeader, HashMap<String,
        String> cookieMap) {
  List<HttpCookie> cookies = HttpCookie.parse(cookieHeader);
  for (HttpCookie cookie : cookies) {
    if (AuthenticatedURL.AUTH_COOKIE.equals(cookie.getName())) {
      cookieMap.put(cookie.getName(), cookie.getValue());
      if (cookie.getPath() != null) {
        cookieMap.put("Path", cookie.getPath());
      }
      if (cookie.getDomain() != null) {
        cookieMap.put("Domain", cookie.getDomain());
      }
    }
  }
}
 
Example 5
Source File: TestAuthenticationFilter.java    From registry with Apache License 2.0 5 votes vote down vote up
private static void parseCookieMap(String cookieHeader, HashMap<String,
        String> cookieMap) {
    List<HttpCookie> cookies = HttpCookie.parse(cookieHeader);
    for (HttpCookie cookie : cookies) {
        if (AuthenticatedURL.AUTH_COOKIE.equals(cookie.getName())) {
            cookieMap.put(cookie.getName(), cookie.getValue());
            if (cookie.getPath() != null) {
                cookieMap.put("Path", cookie.getPath());
            }
            if (cookie.getDomain() != null) {
                cookieMap.put("Domain", cookie.getDomain());
            }
        }
    }
}
 
Example 6
Source File: InMemoryCookieStore.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add one cookie into cookie store.
 */
public void add(URI uri, HttpCookie cookie) {
    // pre-condition : argument can't be null
    if (cookie == null) {
        throw new NullPointerException("cookie is null");
    }


    lock.lock();
    try {
        // remove the ole cookie if there has had one
        cookieJar.remove(cookie);

        // add new cookie if it has a non-zero max-age
        if (cookie.getMaxAge() != 0) {
            cookieJar.add(cookie);
            // and add it to domain index
            if (cookie.getDomain() != null) {
                addIndex(domainIndex, cookie.getDomain(), cookie);
            }
            if (uri != null) {
                // add it to uri index, too
                addIndex(uriIndex, getEffectiveURI(uri), cookie);
            }
        }
    } finally {
        lock.unlock();
    }
}
 
Example 7
Source File: InMemoryCookieStore.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add one cookie into cookie store.
 */
public void add(URI uri, HttpCookie cookie) {
    // pre-condition : argument can't be null
    if (cookie == null) {
        throw new NullPointerException("cookie is null");
    }


    lock.lock();
    try {
        // remove the ole cookie if there has had one
        cookieJar.remove(cookie);

        // add new cookie if it has a non-zero max-age
        if (cookie.getMaxAge() != 0) {
            cookieJar.add(cookie);
            // and add it to domain index
            if (cookie.getDomain() != null) {
                addIndex(domainIndex, cookie.getDomain(), cookie);
            }
            if (uri != null) {
                // add it to uri index, too
                addIndex(uriIndex, getEffectiveURI(uri), cookie);
            }
        }
    } finally {
        lock.unlock();
    }
}
 
Example 8
Source File: InMemoryCookieStore.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add one cookie into cookie store.
 */
public void add(URI uri, HttpCookie cookie) {
    // pre-condition : argument can't be null
    if (cookie == null) {
        throw new NullPointerException("cookie is null");
    }


    lock.lock();
    try {
        // remove the ole cookie if there has had one
        cookieJar.remove(cookie);

        // add new cookie if it has a non-zero max-age
        if (cookie.getMaxAge() != 0) {
            cookieJar.add(cookie);
            // and add it to domain index
            if (cookie.getDomain() != null) {
                addIndex(domainIndex, cookie.getDomain(), cookie);
            }
            if (uri != null) {
                // add it to uri index, too
                addIndex(uriIndex, getEffectiveURI(uri), cookie);
            }
        }
    } finally {
        lock.unlock();
    }
}
 
Example 9
Source File: InMemoryCookieStore.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Add one cookie into cookie store.
 */
public void add(URI uri, HttpCookie cookie) {
    // pre-condition : argument can't be null
    if (cookie == null) {
        throw new NullPointerException("cookie is null");
    }


    lock.lock();
    try {
        // remove the ole cookie if there has had one
        cookieJar.remove(cookie);

        // add new cookie if it has a non-zero max-age
        if (cookie.getMaxAge() != 0) {
            cookieJar.add(cookie);
            // and add it to domain index
            if (cookie.getDomain() != null) {
                addIndex(domainIndex, cookie.getDomain(), cookie);
            }
            if (uri != null) {
                // add it to uri index, too
                addIndex(uriIndex, getEffectiveURI(uri), cookie);
            }
        }
    } finally {
        lock.unlock();
    }
}
 
Example 10
Source File: InMemoryCookieStore.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add one cookie into cookie store.
 */
public void add(URI uri, HttpCookie cookie) {
    // pre-condition : argument can't be null
    if (cookie == null) {
        throw new NullPointerException("cookie is null");
    }


    lock.lock();
    try {
        // remove the ole cookie if there has had one
        cookieJar.remove(cookie);

        // add new cookie if it has a non-zero max-age
        if (cookie.getMaxAge() != 0) {
            cookieJar.add(cookie);
            // and add it to domain index
            if (cookie.getDomain() != null) {
                addIndex(domainIndex, cookie.getDomain(), cookie);
            }
            if (uri != null) {
                // add it to uri index, too
                addIndex(uriIndex, getEffectiveURI(uri), cookie);
            }
        }
    } finally {
        lock.unlock();
    }
}
 
Example 11
Source File: InMemoryCookieStore.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add one cookie into cookie store.
 */
public void add(URI uri, HttpCookie cookie) {
    // pre-condition : argument can't be null
    if (cookie == null) {
        throw new NullPointerException("cookie is null");
    }


    lock.lock();
    try {
        // remove the ole cookie if there has had one
        cookieJar.remove(cookie);

        // add new cookie if it has a non-zero max-age
        if (cookie.getMaxAge() != 0) {
            cookieJar.add(cookie);
            // and add it to domain index
            if (cookie.getDomain() != null) {
                addIndex(domainIndex, cookie.getDomain(), cookie);
            }
            if (uri != null) {
                // add it to uri index, too
                addIndex(uriIndex, getEffectiveURI(uri), cookie);
            }
        }
    } finally {
        lock.unlock();
    }
}
 
Example 12
Source File: InMemoryCookieStore.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add one cookie into cookie store.
 */
public void add(URI uri, HttpCookie cookie) {
    // pre-condition : argument can't be null
    if (cookie == null) {
        throw new NullPointerException("cookie is null");
    }


    lock.lock();
    try {
        // remove the ole cookie if there has had one
        cookieJar.remove(cookie);

        // add new cookie if it has a non-zero max-age
        if (cookie.getMaxAge() != 0) {
            cookieJar.add(cookie);
            // and add it to domain index
            if (cookie.getDomain() != null) {
                addIndex(domainIndex, cookie.getDomain(), cookie);
            }
            if (uri != null) {
                // add it to uri index, too
                addIndex(uriIndex, getEffectiveURI(uri), cookie);
            }
        }
    } finally {
        lock.unlock();
    }
}
 
Example 13
Source File: InMemoryCookieStore.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Add one cookie into cookie store.
 */
public void add(URI uri, HttpCookie cookie) {
    // pre-condition : argument can't be null
    if (cookie == null) {
        throw new NullPointerException("cookie is null");
    }


    lock.lock();
    try {
        // remove the ole cookie if there has had one
        cookieJar.remove(cookie);

        // add new cookie if it has a non-zero max-age
        if (cookie.getMaxAge() != 0) {
            cookieJar.add(cookie);
            // and add it to domain index
            if (cookie.getDomain() != null) {
                addIndex(domainIndex, cookie.getDomain(), cookie);
            }
            if (uri != null) {
                // add it to uri index, too
                addIndex(uriIndex, getEffectiveURI(uri), cookie);
            }
        }
    } finally {
        lock.unlock();
    }
}
 
Example 14
Source File: InMemoryCookieStore.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add one cookie into cookie store.
 */
public void add(URI uri, HttpCookie cookie) {
    // pre-condition : argument can't be null
    if (cookie == null) {
        throw new NullPointerException("cookie is null");
    }


    lock.lock();
    try {
        // remove the ole cookie if there has had one
        cookieJar.remove(cookie);

        // add new cookie if it has a non-zero max-age
        if (cookie.getMaxAge() != 0) {
            cookieJar.add(cookie);
            // and add it to domain index
            if (cookie.getDomain() != null) {
                addIndex(domainIndex, cookie.getDomain(), cookie);
            }
            if (uri != null) {
                // add it to uri index, too
                addIndex(uriIndex, getEffectiveURI(uri), cookie);
            }
        }
    } finally {
        lock.unlock();
    }
}
 
Example 15
Source File: InMemoryCookieStore.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add one cookie into cookie store.
 */
public void add(URI uri, HttpCookie cookie) {
    // pre-condition : argument can't be null
    if (cookie == null) {
        throw new NullPointerException("cookie is null");
    }


    lock.lock();
    try {
        // remove the ole cookie if there has had one
        cookieJar.remove(cookie);

        // add new cookie if it has a non-zero max-age
        if (cookie.getMaxAge() != 0) {
            cookieJar.add(cookie);
            // and add it to domain index
            if (cookie.getDomain() != null) {
                addIndex(domainIndex, cookie.getDomain(), cookie);
            }
            if (uri != null) {
                // add it to uri index, too
                addIndex(uriIndex, getEffectiveURI(uri), cookie);
            }
        }
    } finally {
        lock.unlock();
    }
}
 
Example 16
Source File: InMemoryCookieStore.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add one cookie into cookie store.
 */
public void add(URI uri, HttpCookie cookie) {
    // pre-condition : argument can't be null
    if (cookie == null) {
        throw new NullPointerException("cookie is null");
    }


    lock.lock();
    try {
        // remove the ole cookie if there has had one
        cookieJar.remove(cookie);

        // add new cookie if it has a non-zero max-age
        if (cookie.getMaxAge() != 0) {
            cookieJar.add(cookie);
            // and add it to domain index
            if (cookie.getDomain() != null) {
                addIndex(domainIndex, cookie.getDomain(), cookie);
            }
            if (uri != null) {
                // add it to uri index, too
                addIndex(uriIndex, getEffectiveURI(uri), cookie);
            }
        }
    } finally {
        lock.unlock();
    }
}
 
Example 17
Source File: InMemoryCookieStore.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Add one cookie into cookie store.
 */
public void add(URI uri, HttpCookie cookie) {
    // pre-condition : argument can't be null
    if (cookie == null) {
        throw new NullPointerException("cookie is null");
    }


    lock.lock();
    try {
        // remove the ole cookie if there has had one
        cookieJar.remove(cookie);

        // add new cookie if it has a non-zero max-age
        if (cookie.getMaxAge() != 0) {
            cookieJar.add(cookie);
            // and add it to domain index
            if (cookie.getDomain() != null) {
                addIndex(domainIndex, cookie.getDomain(), cookie);
            }
            if (uri != null) {
                // add it to uri index, too
                addIndex(uriIndex, getEffectiveURI(uri), cookie);
            }
        }
    } finally {
        lock.unlock();
    }
}
 
Example 18
Source File: PersistentCookieStore.java    From AndroidStudyDemo with GNU General Public License v2.0 4 votes vote down vote up
protected String getCookieToken(URI uri, HttpCookie cookie) {
    return cookie.getName() + cookie.getDomain();
}
 
Example 19
Source File: PersistentCookieStore.java    From NewsMe with Apache License 2.0 4 votes vote down vote up
protected String getCookieToken(URI uri, HttpCookie cookie)
{
    return cookie.getName() + cookie.getDomain();
}
 
Example 20
Source File: PersistentCookieStore.java    From FimiX8-RE with MIT License 4 votes vote down vote up
public String getCookieToken(URI uri, HttpCookie cookie) {
    return cookie.getName() + cookie.getDomain();
}