protected synchronized void clearCookieForHost(String sessionHost) throws Exception {
    Cookie sessionCookie = null;
    for (Cookie cookie : cookieStore.getCookies()) {
      String cookieDomain = cookie.getDomain();
      if (cookieDomain != null) {
        if (sessionHost.equals(cookieDomain)
            || sessionHost.indexOf(cookieDomain) != -1
            || cookieDomain.indexOf(sessionHost) != -1) {
          sessionCookie = cookie;
          break;
        }
      }
    }

    if (sessionCookie != null) {
      BasicClientCookie httpCookie =
          new BasicClientCookie(sessionCookie.getName(), sessionCookie.getValue());
      httpCookie.setExpiryDate(new Date(0));
      httpCookie.setVersion(1);
      httpCookie.setPath(sessionCookie.getPath());
      httpCookie.setDomain(sessionCookie.getDomain());
      cookieStore.addCookie(httpCookie);
    }

    cookieStore.clearExpired(new Date()); // this should clear the cookie
  }
 @Implementation
 public void removeExpiredCookie() {
   store.clearExpired(new Date());
 }
Example #3
0
 /** Создает контекст интрернет-запросов */
 private void createContext() {
   cookie.clearExpired(new Date());
   httpContext = HttpClientContext.create();
   httpContext.setCookieStore(cookie);
 }