类java.net.CookieStore源码实例Demo

下面列出了怎么用java.net.CookieStore的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: j2objc   文件: AbstractCookiesTest.java
public void testCookieStoreNullUris() {
    CookieStore cookieStore = new CookieManager(createCookieStore(), null).getCookieStore();
    HttpCookie cookieA = createCookie("a", "android", ".android.com", "/source");
    HttpCookie cookieB = createCookie("b", "banana", "code.google.com", "/p/android");

    cookieStore.add(null, cookieA);
    assertEquals(Arrays.asList(cookieA), cookieStore.getCookies());
    cookieStore.add(null, cookieB);
    assertEquals(Arrays.asList(cookieA, cookieB), cookieStore.getCookies());

    try {
        cookieStore.get(null);
        fail();
    } catch (NullPointerException expected) {
    }

    assertEquals(Collections.<URI>emptyList(), cookieStore.getURIs());
    assertTrue(cookieStore.remove(null, cookieA));
    assertEquals(Arrays.asList(cookieB), cookieStore.getCookies());

    assertTrue(cookieStore.removeAll());
    assertEquals(Collections.<URI>emptyList(), cookieStore.getURIs());
    assertEquals(Collections.<HttpCookie>emptyList(), cookieStore.getCookies());
}
 
源代码2 项目: utexas-utilities   文件: AuthCookie.java
private void resetCookie() {
    settings.edit().remove(prefKey).apply();
    authCookie = "";
    try {
        /*
        This step is *required* for PNA, and nicety for other services. PNA won't let you
        log in if you're still holding on to a valid authcookie, so we clear them out.
         */
        URI loginURI = URI.create(url.getHost());
        CookieStore cookies = ((CookieManager) CookieHandler.getDefault()).getCookieStore();
        for (HttpCookie cookie : cookies.get(loginURI)) {
            cookies.remove(loginURI, cookie);
        }
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    }
    cookieHasBeenSet = false;
}
 
源代码3 项目: utexas-utilities   文件: AuthCookie.java
protected void setAuthCookieVal(String authCookie, String domain) {
    this.authCookie = authCookie;
    settings.edit().putString(prefKey, authCookie).apply();

    /*
    this is technically unnecessary if OkHttp handled the authentication, because it will
    have already set the cookies in the CookieHandler. It doesn't seem to cause any issues
    just to re-add the cookies, though
     */
    HttpCookie httpCookie = new HttpCookie(authCookieKey, authCookie);
    httpCookie.setDomain(domain);
    try {
        CookieStore cookies = ((CookieManager) CookieHandler.getDefault()).getCookieStore();
        cookies.add(URI.create(domain), httpCookie);
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    }
    cookieHasBeenSet = true;
    android.webkit.CookieManager.getInstance().setCookie(domain, httpCookie.getName() + "=" + httpCookie.getValue());
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
        android.webkit.CookieManager.getInstance().flush();
    } else {
        CookieSyncManager.getInstance().sync();
    }
}
 
源代码4 项目: Java-Coding-Problems   文件: Main.java
public static void main(String[] args) throws IOException, InterruptedException {

        /*
        HttpClient client = HttpClient.newBuilder()
                .cookieHandler(new CookieManager(null, CookiePolicy.ACCEPT_NONE))
                .build();

        System.out.println(client.cookieHandler().orElseThrow());
         */
        
        CookieManager cm = new CookieManager();
        cm.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
        
        HttpClient client = HttpClient.newBuilder()
                .cookieHandler(cm)
                .build();

        HttpRequest request = HttpRequest.newBuilder()
                .header("Authorization", "Bearer Q3ku4mp_hCQGvAFeYKa0ktFCDKS3VpSA1nwf")                
                .uri(URI.create("https://gorest.co.in/public-api/users/1"))
                .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

        System.out.println("Status code: " + response.statusCode());
        System.out.println("\n Body: " + response.body());       
        System.out.println("\nset-cookie header: " + response.headers().firstValue("set-cookie"));
        
        CookieStore cookieStore = cm.getCookieStore();
        
        System.out.println("\nCookies: " + cookieStore.getCookies());
    }
 
源代码5 项目: dragonwell8_jdk   文件: NullUriCookieTest.java
static void checkCookieNullUri() throws Exception {
    //get a cookie store implementation and add a cookie to the store with null URI
    CookieStore cookieStore = (new CookieManager()).getCookieStore();
    //Check if removeAll() retrurns false on an empty CookieStore
    if (cookieStore.removeAll()) {
        fail = true;
    }
    checkFail("removeAll on empty store should return false");
    HttpCookie cookie = new HttpCookie("MY_COOKIE", "MY_COOKIE_VALUE");
    cookie.setDomain("foo.com");
    cookieStore.add(null, cookie);

    //Retrieve added cookie
    URI uri = new URI("http://foo.com");
    List<HttpCookie> addedCookieList = cookieStore.get(uri);

    //Verify CookieStore behaves well
    if (addedCookieList.size() != 1) {
       fail = true;
    }
    checkFail("Abnormal size of cookie jar");

    for (HttpCookie chip : addedCookieList) {
        if (!chip.equals(cookie)) {
             fail = true;
        }
    }
    checkFail("Cookie not retrieved from Cookie Jar");
    boolean ret = cookieStore.remove(null,cookie);
    if (!ret) {
        fail = true;
    }
    checkFail("Abnormal removal behaviour from Cookie Jar");
}
 
源代码6 项目: TencentKona-8   文件: NullUriCookieTest.java
static void checkCookieNullUri() throws Exception {
    //get a cookie store implementation and add a cookie to the store with null URI
    CookieStore cookieStore = (new CookieManager()).getCookieStore();
    //Check if removeAll() retrurns false on an empty CookieStore
    if (cookieStore.removeAll()) {
        fail = true;
    }
    checkFail("removeAll on empty store should return false");
    HttpCookie cookie = new HttpCookie("MY_COOKIE", "MY_COOKIE_VALUE");
    cookie.setDomain("foo.com");
    cookieStore.add(null, cookie);

    //Retrieve added cookie
    URI uri = new URI("http://foo.com");
    List<HttpCookie> addedCookieList = cookieStore.get(uri);

    //Verify CookieStore behaves well
    if (addedCookieList.size() != 1) {
       fail = true;
    }
    checkFail("Abnormal size of cookie jar");

    for (HttpCookie chip : addedCookieList) {
        if (!chip.equals(cookie)) {
             fail = true;
        }
    }
    checkFail("Cookie not retrieved from Cookie Jar");
    boolean ret = cookieStore.remove(null,cookie);
    if (!ret) {
        fail = true;
    }
    checkFail("Abnormal removal behaviour from Cookie Jar");
}
 
源代码7 项目: jdk8u60   文件: NullUriCookieTest.java
static void checkCookieNullUri() throws Exception {
    //get a cookie store implementation and add a cookie to the store with null URI
    CookieStore cookieStore = (new CookieManager()).getCookieStore();
    //Check if removeAll() retrurns false on an empty CookieStore
    if (cookieStore.removeAll()) {
        fail = true;
    }
    checkFail("removeAll on empty store should return false");
    HttpCookie cookie = new HttpCookie("MY_COOKIE", "MY_COOKIE_VALUE");
    cookie.setDomain("foo.com");
    cookieStore.add(null, cookie);

    //Retrieve added cookie
    URI uri = new URI("http://foo.com");
    List<HttpCookie> addedCookieList = cookieStore.get(uri);

    //Verify CookieStore behaves well
    if (addedCookieList.size() != 1) {
       fail = true;
    }
    checkFail("Abnormal size of cookie jar");

    for (HttpCookie chip : addedCookieList) {
        if (!chip.equals(cookie)) {
             fail = true;
        }
    }
    checkFail("Cookie not retrieved from Cookie Jar");
    boolean ret = cookieStore.remove(null,cookie);
    if (!ret) {
        fail = true;
    }
    checkFail("Abnormal removal behaviour from Cookie Jar");
}
 
源代码8 项目: openjdk-jdk8u   文件: NullUriCookieTest.java
static void checkCookieNullUri() throws Exception {
    //get a cookie store implementation and add a cookie to the store with null URI
    CookieStore cookieStore = (new CookieManager()).getCookieStore();
    //Check if removeAll() retrurns false on an empty CookieStore
    if (cookieStore.removeAll()) {
        fail = true;
    }
    checkFail("removeAll on empty store should return false");
    HttpCookie cookie = new HttpCookie("MY_COOKIE", "MY_COOKIE_VALUE");
    cookie.setDomain("foo.com");
    cookieStore.add(null, cookie);

    //Retrieve added cookie
    URI uri = new URI("http://foo.com");
    List<HttpCookie> addedCookieList = cookieStore.get(uri);

    //Verify CookieStore behaves well
    if (addedCookieList.size() != 1) {
       fail = true;
    }
    checkFail("Abnormal size of cookie jar");

    for (HttpCookie chip : addedCookieList) {
        if (!chip.equals(cookie)) {
             fail = true;
        }
    }
    checkFail("Cookie not retrieved from Cookie Jar");
    boolean ret = cookieStore.remove(null,cookie);
    if (!ret) {
        fail = true;
    }
    checkFail("Abnormal removal behaviour from Cookie Jar");
}
 
源代码9 项目: openjdk-jdk8u-backup   文件: NullUriCookieTest.java
static void checkCookieNullUri() throws Exception {
    //get a cookie store implementation and add a cookie to the store with null URI
    CookieStore cookieStore = (new CookieManager()).getCookieStore();
    //Check if removeAll() retrurns false on an empty CookieStore
    if (cookieStore.removeAll()) {
        fail = true;
    }
    checkFail("removeAll on empty store should return false");
    HttpCookie cookie = new HttpCookie("MY_COOKIE", "MY_COOKIE_VALUE");
    cookie.setDomain("foo.com");
    cookieStore.add(null, cookie);

    //Retrieve added cookie
    URI uri = new URI("http://foo.com");
    List<HttpCookie> addedCookieList = cookieStore.get(uri);

    //Verify CookieStore behaves well
    if (addedCookieList.size() != 1) {
       fail = true;
    }
    checkFail("Abnormal size of cookie jar");

    for (HttpCookie chip : addedCookieList) {
        if (!chip.equals(cookie)) {
             fail = true;
        }
    }
    checkFail("Cookie not retrieved from Cookie Jar");
    boolean ret = cookieStore.remove(null,cookie);
    if (!ret) {
        fail = true;
    }
    checkFail("Abnormal removal behaviour from Cookie Jar");
}
 
源代码10 项目: openjdk-jdk9   文件: NullUriCookieTest.java
static void checkCookieNullUri() throws Exception {
    //get a cookie store implementation and add a cookie to the store with null URI
    CookieStore cookieStore = (new CookieManager()).getCookieStore();
    //Check if removeAll() retrurns false on an empty CookieStore
    if (cookieStore.removeAll()) {
        fail = true;
    }
    checkFail("removeAll on empty store should return false");
    HttpCookie cookie = new HttpCookie("MY_COOKIE", "MY_COOKIE_VALUE");
    cookie.setDomain("foo.com");
    cookieStore.add(null, cookie);

    //Retrieve added cookie
    URI uri = new URI("http://foo.com");
    List<HttpCookie> addedCookieList = cookieStore.get(uri);

    //Verify CookieStore behaves well
    if (addedCookieList.size() != 1) {
       fail = true;
    }
    checkFail("Abnormal size of cookie jar");

    for (HttpCookie chip : addedCookieList) {
        if (!chip.equals(cookie)) {
             fail = true;
        }
    }
    checkFail("Cookie not retrieved from Cookie Jar");
    boolean ret = cookieStore.remove(null,cookie);
    if (!ret) {
        fail = true;
    }
    checkFail("Abnormal removal behaviour from Cookie Jar");
}
 
源代码11 项目: jdk8u-jdk   文件: NullUriCookieTest.java
static void checkCookieNullUri() throws Exception {
    //get a cookie store implementation and add a cookie to the store with null URI
    CookieStore cookieStore = (new CookieManager()).getCookieStore();
    //Check if removeAll() retrurns false on an empty CookieStore
    if (cookieStore.removeAll()) {
        fail = true;
    }
    checkFail("removeAll on empty store should return false");
    HttpCookie cookie = new HttpCookie("MY_COOKIE", "MY_COOKIE_VALUE");
    cookie.setDomain("foo.com");
    cookieStore.add(null, cookie);

    //Retrieve added cookie
    URI uri = new URI("http://foo.com");
    List<HttpCookie> addedCookieList = cookieStore.get(uri);

    //Verify CookieStore behaves well
    if (addedCookieList.size() != 1) {
       fail = true;
    }
    checkFail("Abnormal size of cookie jar");

    for (HttpCookie chip : addedCookieList) {
        if (!chip.equals(cookie)) {
             fail = true;
        }
    }
    checkFail("Cookie not retrieved from Cookie Jar");
    boolean ret = cookieStore.remove(null,cookie);
    if (!ret) {
        fail = true;
    }
    checkFail("Abnormal removal behaviour from Cookie Jar");
}
 
源代码12 项目: rawhttp   文件: RawHttpCliClient.java
private static CookieHandler cookieManagerFor(@Nullable File cookieJar) {
    CookieStore cookieStore;
    try {
        cookieStore = cookieJar == null ? null : new FileCookieJar(cookieJar);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return new CookieManager(cookieStore, CookiePolicy.ACCEPT_ALL);
}
 
源代码13 项目: rawhttp   文件: OnWriteFlushStrategy.java
@Override
public void onUpdate(CookieStore cookieStore) {
    super.onUpdate(cookieStore);
    int count = totalWrites.incrementAndGet();
    if (count % writeCount == 0) {
        try {
            flush.call();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
 
源代码14 项目: rawhttp   文件: PeriodicFlushStrategy.java
@Override
public void onUpdate(CookieStore cookieStore) {
    super.onUpdate(cookieStore);
    executorService.submit(() -> {
        requiresFlush = true;
    });
}
 
源代码15 项目: appinventor-extensions   文件: GingerbreadUtil.java
/**
 * Clears the cookies in the given cookie handler. Cookies can only be cleared if the
 * cookieHandler is a CookieManager with a non-null CookieStore.
 *
 * @param cookieHandler the cookie handler where cookies should be cleared
 * @return true if cookies were cleared; false otherwise
 */
public static boolean clearCookies(CookieHandler cookieHandler) {
  if (cookieHandler instanceof CookieManager) {
    CookieManager cookieManager = (CookieManager) cookieHandler;
    CookieStore cookieStore = cookieManager.getCookieStore();
    if (cookieStore != null) {
      cookieStore.removeAll();
      return true;
    }
  }
  return false;
}
 
源代码16 项目: hottub   文件: NullUriCookieTest.java
static void checkCookieNullUri() throws Exception {
    //get a cookie store implementation and add a cookie to the store with null URI
    CookieStore cookieStore = (new CookieManager()).getCookieStore();
    //Check if removeAll() retrurns false on an empty CookieStore
    if (cookieStore.removeAll()) {
        fail = true;
    }
    checkFail("removeAll on empty store should return false");
    HttpCookie cookie = new HttpCookie("MY_COOKIE", "MY_COOKIE_VALUE");
    cookie.setDomain("foo.com");
    cookieStore.add(null, cookie);

    //Retrieve added cookie
    URI uri = new URI("http://foo.com");
    List<HttpCookie> addedCookieList = cookieStore.get(uri);

    //Verify CookieStore behaves well
    if (addedCookieList.size() != 1) {
       fail = true;
    }
    checkFail("Abnormal size of cookie jar");

    for (HttpCookie chip : addedCookieList) {
        if (!chip.equals(cookie)) {
             fail = true;
        }
    }
    checkFail("Cookie not retrieved from Cookie Jar");
    boolean ret = cookieStore.remove(null,cookie);
    if (!ret) {
        fail = true;
    }
    checkFail("Abnormal removal behaviour from Cookie Jar");
}
 
源代码17 项目: openjdk-8-source   文件: NullUriCookieTest.java
static void checkCookieNullUri() throws Exception {
    //get a cookie store implementation and add a cookie to the store with null URI
    CookieStore cookieStore = (new CookieManager()).getCookieStore();
    //Check if removeAll() retrurns false on an empty CookieStore
    if (cookieStore.removeAll()) {
        fail = true;
    }
    checkFail("removeAll on empty store should return false");
    HttpCookie cookie = new HttpCookie("MY_COOKIE", "MY_COOKIE_VALUE");
    cookie.setDomain("foo.com");
    cookieStore.add(null, cookie);

    //Retrieve added cookie
    URI uri = new URI("http://foo.com");
    List<HttpCookie> addedCookieList = cookieStore.get(uri);

    //Verify CookieStore behaves well
    if (addedCookieList.size() != 1) {
       fail = true;
    }
    checkFail("Abnormal size of cookie jar");

    for (HttpCookie chip : addedCookieList) {
        if (!chip.equals(cookie)) {
             fail = true;
        }
    }
    checkFail("Cookie not retrieved from Cookie Jar");
    boolean ret = cookieStore.remove(null,cookie);
    if (!ret) {
        fail = true;
    }
    checkFail("Abnormal removal behaviour from Cookie Jar");
}
 
源代码18 项目: openjdk-8   文件: NullUriCookieTest.java
static void checkCookieNullUri() throws Exception {
    //get a cookie store implementation and add a cookie to the store with null URI
    CookieStore cookieStore = (new CookieManager()).getCookieStore();
    //Check if removeAll() retrurns false on an empty CookieStore
    if (cookieStore.removeAll()) {
        fail = true;
    }
    checkFail("removeAll on empty store should return false");
    HttpCookie cookie = new HttpCookie("MY_COOKIE", "MY_COOKIE_VALUE");
    cookie.setDomain("foo.com");
    cookieStore.add(null, cookie);

    //Retrieve added cookie
    URI uri = new URI("http://foo.com");
    List<HttpCookie> addedCookieList = cookieStore.get(uri);

    //Verify CookieStore behaves well
    if (addedCookieList.size() != 1) {
       fail = true;
    }
    checkFail("Abnormal size of cookie jar");

    for (HttpCookie chip : addedCookieList) {
        if (!chip.equals(cookie)) {
             fail = true;
        }
    }
    checkFail("Cookie not retrieved from Cookie Jar");
    boolean ret = cookieStore.remove(null,cookie);
    if (!ret) {
        fail = true;
    }
    checkFail("Abnormal removal behaviour from Cookie Jar");
}
 
源代码19 项目: jdk8u_jdk   文件: NullUriCookieTest.java
static void checkCookieNullUri() throws Exception {
    //get a cookie store implementation and add a cookie to the store with null URI
    CookieStore cookieStore = (new CookieManager()).getCookieStore();
    //Check if removeAll() retrurns false on an empty CookieStore
    if (cookieStore.removeAll()) {
        fail = true;
    }
    checkFail("removeAll on empty store should return false");
    HttpCookie cookie = new HttpCookie("MY_COOKIE", "MY_COOKIE_VALUE");
    cookie.setDomain("foo.com");
    cookieStore.add(null, cookie);

    //Retrieve added cookie
    URI uri = new URI("http://foo.com");
    List<HttpCookie> addedCookieList = cookieStore.get(uri);

    //Verify CookieStore behaves well
    if (addedCookieList.size() != 1) {
       fail = true;
    }
    checkFail("Abnormal size of cookie jar");

    for (HttpCookie chip : addedCookieList) {
        if (!chip.equals(cookie)) {
             fail = true;
        }
    }
    checkFail("Cookie not retrieved from Cookie Jar");
    boolean ret = cookieStore.remove(null,cookie);
    if (!ret) {
        fail = true;
    }
    checkFail("Abnormal removal behaviour from Cookie Jar");
}
 
源代码20 项目: jdk8u-jdk   文件: NullUriCookieTest.java
static void checkCookieNullUri() throws Exception {
    //get a cookie store implementation and add a cookie to the store with null URI
    CookieStore cookieStore = (new CookieManager()).getCookieStore();
    //Check if removeAll() retrurns false on an empty CookieStore
    if (cookieStore.removeAll()) {
        fail = true;
    }
    checkFail("removeAll on empty store should return false");
    HttpCookie cookie = new HttpCookie("MY_COOKIE", "MY_COOKIE_VALUE");
    cookie.setDomain("foo.com");
    cookieStore.add(null, cookie);

    //Retrieve added cookie
    URI uri = new URI("http://foo.com");
    List<HttpCookie> addedCookieList = cookieStore.get(uri);

    //Verify CookieStore behaves well
    if (addedCookieList.size() != 1) {
       fail = true;
    }
    checkFail("Abnormal size of cookie jar");

    for (HttpCookie chip : addedCookieList) {
        if (!chip.equals(cookie)) {
             fail = true;
        }
    }
    checkFail("Cookie not retrieved from Cookie Jar");
    boolean ret = cookieStore.remove(null,cookie);
    if (!ret) {
        fail = true;
    }
    checkFail("Abnormal removal behaviour from Cookie Jar");
}
 
源代码21 项目: jdk8u-dev-jdk   文件: NullUriCookieTest.java
static void checkCookieNullUri() throws Exception {
    //get a cookie store implementation and add a cookie to the store with null URI
    CookieStore cookieStore = (new CookieManager()).getCookieStore();
    //Check if removeAll() retrurns false on an empty CookieStore
    if (cookieStore.removeAll()) {
        fail = true;
    }
    checkFail("removeAll on empty store should return false");
    HttpCookie cookie = new HttpCookie("MY_COOKIE", "MY_COOKIE_VALUE");
    cookie.setDomain("foo.com");
    cookieStore.add(null, cookie);

    //Retrieve added cookie
    URI uri = new URI("http://foo.com");
    List<HttpCookie> addedCookieList = cookieStore.get(uri);

    //Verify CookieStore behaves well
    if (addedCookieList.size() != 1) {
       fail = true;
    }
    checkFail("Abnormal size of cookie jar");

    for (HttpCookie chip : addedCookieList) {
        if (!chip.equals(cookie)) {
             fail = true;
        }
    }
    checkFail("Cookie not retrieved from Cookie Jar");
    boolean ret = cookieStore.remove(null,cookie);
    if (!ret) {
        fail = true;
    }
    checkFail("Abnormal removal behaviour from Cookie Jar");
}
 
源代码22 项目: wasp   文件: Wasp.java
public Builder enableCookies(CookieStore cookieStore, CookiePolicy cookiePolicy) {
  if (cookiePolicy == null) {
    throw new NullPointerException("CookiePolicy may not be null");
  }
  this.cookieHandler = new CookieManager(cookieStore, cookiePolicy);
  return this;
}
 
源代码23 项目: j2objc   文件: AbstractCookiesTest.java
public void testCookieStoreRemoveAll() throws URISyntaxException {
    CookieStore cookieStore = new CookieManager(createCookieStore(), null).getCookieStore();
    cookieStore.add(new URI("http://code.google.com/"), new HttpCookie("a", "android"));
    assertTrue(cookieStore.removeAll());
    assertEquals(Collections.<URI>emptyList(), cookieStore.getURIs());
    assertEquals(Collections.<HttpCookie>emptyList(), cookieStore.getCookies());
    assertFalse("Expected removeAll() to return false when the call doesn't mutate the store",
            cookieStore.removeAll());  // RI6 fails this
}
 
源代码24 项目: j2objc   文件: AbstractCookiesTest.java
public void testCookieStoreRemoveRequiresUri() throws URISyntaxException {
    CookieStore cookieStore = new CookieManager(createCookieStore(), null).getCookieStore();
    HttpCookie cookieA = new HttpCookie("a", "android");
    cookieStore.add(new URI("http://android.com/source/"), cookieA);
    assertFalse("Expected remove() to take the cookie URI into account.", // RI6 fails this
            cookieStore.remove(new URI("http://code.google.com/"), cookieA));
    assertEquals(Arrays.asList(cookieA), cookieStore.getCookies());
}
 
源代码25 项目: j2objc   文件: AbstractCookiesTest.java
public void testCookieStoreGet() throws Exception {
    CookieStore cookieStore = new CookieManager(createCookieStore(), null).getCookieStore();
    HttpCookie cookiePort1 = createCookie("a1", "android", "a.com", "/path1");
    HttpCookie cookiePort2 = createCookie("a2", "android", "a.com", "/path2");
    HttpCookie secureCookie = createCookie("a3", "android", "a.com", "/path3");
    secureCookie.setSecure(true);
    HttpCookie notSecureCookie = createCookie("a4", "android", "a.com", "/path4");

    HttpCookie bCookie = createCookie("b1", "android", "b.com", "/path5");

    cookieStore.add(new URI("http://a.com:443/path1"), cookiePort1);
    cookieStore.add(new URI("http://a.com:8080/path2"), cookiePort2);
    cookieStore.add(new URI("https://a.com:443/path3"), secureCookie);
    cookieStore.add(new URI("https://a.com:443/path4"), notSecureCookie);
    cookieStore.add(new URI("https://b.com:8080/path5"), bCookie);

    List<HttpCookie> expectedStoreCookies = new ArrayList<>();
    expectedStoreCookies.add(cookiePort1);
    expectedStoreCookies.add(cookiePort2);
    expectedStoreCookies.add(secureCookie);
    expectedStoreCookies.add(notSecureCookie);

    // The default CookieStore implementation on Android is currently responsible for matching
    // the host/domain but not handling other cookie rules: it ignores the scheme (e.g. "secure"
    // checks), port and path.
    // The tests below fail on the RI. It looks like in the RI it is CookieStoreImpl that is
    // enforcing "secure" checks.
    assertEquals(expectedStoreCookies, cookieStore.get(new URI("http://a.com:443/anypath")));
    assertEquals(expectedStoreCookies, cookieStore.get(new URI("http://a.com:8080/anypath")));
    assertEquals(expectedStoreCookies, cookieStore.get(new URI("https://a.com/anypath")));
    assertEquals(expectedStoreCookies, cookieStore.get(new URI("http://a.com/anypath")));
}
 
源代码26 项目: j2objc   文件: AbstractCookiesTest.java
/**
 * Regression test for http://b/25682357 /
 * https://code.google.com/p/android/issues/detail?id=193475
 * CookieStoreImpl.get(URI) not handling ports properly in the absence of an explicit cookie
 * Domain.
 */
public void testCookieStoreGetWithPort() throws Exception {
    CookieStore cookieStore = new CookieManager(createCookieStore(), null).getCookieStore();
    HttpCookie cookie = new HttpCookie("theme", "light");
    // Deliberately not setting the cookie domain or path.
    cookieStore.add(new URI("http://a.com:12345"), cookie);

    // CookieStoreImpl must ignore the port during retrieval when domain is not set.
    assertEquals(1, cookieStore.get(new URI("http://a.com:12345/path1")).size());
    assertEquals(1, cookieStore.get(new URI("http://a.com/path1")).size());
}
 
源代码27 项目: j2objc   文件: AbstractCookiesTest.java
public void testCookieStoreGetWithSecure() throws Exception {
    CookieStore cookieStore = new CookieManager(createCookieStore(), null).getCookieStore();
    HttpCookie cookie = createCookie("theme", "light", "a.com", "/path");
    cookie.setSecure(true);
    cookieStore.add(new URI("https://a.com/path"), cookie);

    // CookieStoreImpl on Android ignores the "Secure" attribute. The RI implements the secure
    // check in CookieStoreImpl. For safety / app compatibility, if this is changed Android
    // should probably implement it in both places.
    assertEquals(1, cookieStore.get(new URI("http://a.com/path")).size());
    assertEquals(1, cookieStore.get(new URI("https://a.com/path")).size());
}
 
源代码28 项目: j2objc   文件: AbstractCookiesTest.java
public void testCookieStoreEviction() throws Exception {
    CookieStore cookieStore = new CookieManager(createCookieStore(), null).getCookieStore();
    HttpCookie themeCookie = createCookie("theme", "light", "a.com", "/");
    cookieStore.add(new URI("http://a.com/"), themeCookie);

    HttpCookie sidCookie = createCookie("sid", "mysid", "a.com", "/");
    cookieStore.add(new URI("http://a.com/"), sidCookie);

    HttpCookie replacementThemeCookie = createCookie("theme", "dark", "a.com", "/");
    cookieStore.add(new URI("http://a.com/"), replacementThemeCookie);

    // toString() is used below to avoid confusion with assertEquals():
    // HttpCookie.equals() is implemented so that it only checks name, path and domain
    // attributes but we also want to check the value.
    assertEquals(
            "[sid=\"mysid\";$Path=\"/\";$Domain=\"a.com\", "
                    + "theme=\"dark\";$Path=\"/\";$Domain=\"a.com\"]",
            cookieStore.get(new URI("http://a.com/")).toString());

    HttpCookie replacementSidCookie = createCookie("sid", "mynewsid", "A.cOm", "/");
    cookieStore.add(new URI("http://a.com/"), replacementSidCookie);

    assertEquals(
            "[theme=\"dark\";$Path=\"/\";$Domain=\"a.com\", "
                    + "sid=\"mynewsid\";$Path=\"/\";$Domain=\"a.com\"]",
            cookieStore.get(new URI("http://a.com/")).toString());
}
 
源代码29 项目: utexas-utilities   文件: UTilitiesApplication.java
public void logoutAll() {
    for (AuthCookie authCookie : authCookies.values()) {
        authCookie.logout();
    }
    CookieStore cookies = ((CookieManager) CookieHandler.getDefault()).getCookieStore();
    cookies.removeAll();
}
 
源代码30 项目: CrossMobile   文件: CookieManagerProxy.java
@Override
    public CookieStore getCookieStore() {
//        if (cookieManager == null)  // No special cookie manager - use system default
        return super.getCookieStore();
        // we don't want anyone to work with this cookie store directly
    }
 
 类所在包
 同包方法