Example usage for org.apache.http.client CookieStore clear

List of usage examples for org.apache.http.client CookieStore clear

Introduction

In this page you can find the example usage for org.apache.http.client CookieStore clear.

Prototype

void clear();

Source Link

Document

Clears all cookies.

Usage

From source file:com.hp.mercury.ci.jenkins.plugins.oo.core.OOAccessibilityLayer.java

private static CookieStore handleCsrfCookies(CookieStore cookieStore) {
    List<Cookie> cookies = new ArrayList<Cookie>();
    for (Cookie cookie : cookieStore.getCookies()) {
        if (!cookie.getName().contains("CSRF")) {
            cookies.add(cookie);//from ww  w.j  a va 2  s. c o  m
        }
    }

    cookieStore.clear();

    for (Cookie cookie : cookies) {
        cookieStore.addCookie(cookie);
    }
    return cookieStore;
}

From source file:de.ub0r.android.websms.connector.common.Utils.java

/**
 * Clear internal cookie cache./*from w w  w.j a  va2s . co  m*/
 */
public static void clearCookies() {
    if (httpClient != null) {
        final CookieStore cs = httpClient.getCookieStore();
        if (cs != null) {
            cs.clear();
        }
    }
}

From source file:com.adavr.http.Client.java

public void clearCookie() {
    CookieStore store = (CookieStore) localContext.getAttribute(ClientContext.COOKIE_STORE);
    store.clear();
}

From source file:de.damdi.fitness.activity.settings.sync.RestClient.java

/**
 * Set a cookie, all previous cookies will be cleared.
 * //from w w  w  . j a  va 2s  .c om
 * @param name
 *            the cookie name
 * @param value
 *            its value
 */
public void setCookie(String name, String value) {
    CookieStore store = mClient.getCookieStore();
    store.clear();
    BasicClientCookie cookie = new BasicClientCookie(name, value);
    cookie.setDomain(mHostName);
    store.addCookie(cookie);
}

From source file:test.integ.be.e_contract.cdi.crossconversation.CrossConversationScopedTest.java

@Test
public void testAndroidScopedNewSessionIsNewAndroidScope() throws Exception {
    String browserLocation = this.baseURL + "browser";
    String valueLocation = this.baseURL + "value";
    LOGGER.debug("location: {}", browserLocation);
    HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
    HttpClient httpClient = httpClientBuilder.build();

    HttpContext httpContext = new BasicHttpContext();
    String androidCode = doGet(httpClient, httpContext, browserLocation);
    LOGGER.debug("result: {}", androidCode);
    String value = doGet(httpClient, httpContext, valueLocation);

    CookieStore cookieStore = (CookieStore) httpContext.getAttribute(HttpClientContext.COOKIE_STORE);
    cookieStore.clear();

    String androidCode2 = doGet(httpClient, httpContext, browserLocation);
    LOGGER.debug("result 2: {}", androidCode2);
    String value2 = doGet(httpClient, httpContext, valueLocation);

    assertNotEquals(androidCode, androidCode2);
    assertNotEquals(value, value2);/*from  w  w  w . j av  a 2s.  co  m*/
}

From source file:test.integ.be.e_contract.cdi.crossconversation.CrossConversationScopedTest.java

@Test
public void testAndroidScopedBasicUsage() throws Exception {
    String browserLocation = this.baseURL + "browser";
    String valueLocation = this.baseURL + "value";
    LOGGER.debug("location: {}", browserLocation);
    HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
    HttpClient httpClient = httpClientBuilder.build();

    HttpContext httpContext = new BasicHttpContext();
    String androidCode = doGet(httpClient, httpContext, browserLocation);
    LOGGER.debug("result: {}", androidCode);
    String value = doGet(httpClient, httpContext, valueLocation);

    CookieStore cookieStore = (CookieStore) httpContext.getAttribute(HttpClientContext.COOKIE_STORE);
    cookieStore.clear();

    String androidLocation = this.baseURL + "android?androidCode=" + androidCode;
    valueLocation += "?androidCode=" + androidCode;

    HttpClient androidHttpClient = httpClientBuilder.build();
    HttpContext androidHttpContext = new BasicHttpContext();

    String androidCode2 = doGet(androidHttpClient, androidHttpContext, androidLocation);
    LOGGER.debug("result 2: {}", androidCode2);
    String value2 = doGet(androidHttpClient, androidHttpContext, valueLocation);

    assertEquals(androidCode, androidCode2);
    assertEquals(value, value2);//from  w w w .  j av  a2 s.c o m
}

From source file:ti.modules.titanium.network.NetworkModule.java

/**
 * Removes all the cookies in the HTTPClient cookie store.
 *///from   ww  w. j a  v a2 s . c  om
@Kroll.method
public void removeAllHTTPCookies() {
    CookieStore cookieStore = getHTTPCookieStoreInstance();
    cookieStore.clear();
}

From source file:ti.modules.titanium.network.NetworkModule.java

/**
 * Removes all the cookies with the domain matched with the given value.
 * @param domain the domain of the cookie to remove. It is case-insensitive.
 *//*from   w  w  w .j  ava  2s  . c  o m*/
@Kroll.method
public void removeHTTPCookiesForDomain(String domain) {
    CookieStore cookieStore = getHTTPCookieStoreInstance();
    List<Cookie> cookies = new ArrayList<Cookie>(cookieStore.getCookies());
    cookieStore.clear();
    for (Cookie cookie : cookies) {
        String cookieDomain = cookie.getDomain();
        if (!(domainMatch(cookieDomain, domain))) {
            cookieStore.addCookie(cookie);
        }
    }
}

From source file:ti.modules.titanium.network.NetworkModule.java

/** Removes the cookie with the domain, path and name exactly the same as the given values.
 * @param domain the domain of the cookie to remove. It is case-insensitive.
 * @param path the path of the cookie to remove. It is case-sensitive.
 * @param name the name of the cookie to remove. It is case-sensitive.
 *//*w  w  w. j a  v a2s. c  o  m*/
@Kroll.method
public void removeHTTPCookie(String domain, String path, String name) {
    if (domain == null || name == null) {
        if (Log.isDebugModeEnabled()) {
            Log.e(TAG, "Unable to remove the HTTP cookie. Need to provide a valid domain / name.");
        }
        return;
    }
    CookieStore cookieStore = getHTTPCookieStoreInstance();
    List<Cookie> cookies = new ArrayList<Cookie>(cookieStore.getCookies());
    cookieStore.clear();
    for (Cookie cookie : cookies) {
        String cookieName = cookie.getName();
        String cookieDomain = cookie.getDomain();
        String cookiePath = cookie.getPath();
        if (!(name.equals(cookieName) && stringEqual(domain, cookieDomain, false)
                && stringEqual(path, cookiePath, true))) {
            cookieStore.addCookie(cookie);
        }
    }
}

From source file:com.akop.bach.parser.Parser.java

@SuppressWarnings("unchecked")
protected boolean loadSession(BasicAccount account) {
    ObjectInputStream objStream = null;
    final List<Cookie> serializableCookies;

    CookieStore store = mHttpClient.getCookieStore();
    store.clear();

    if (account == null)
        return false;

    String filename = getSessionFile(account);
    if (filename == null)
        return false;

    File f = new File(mContext.getFilesDir(), filename);
    boolean fileExists = f.exists();

    if (!fileExists)
        return false;

    // Don't care about errors - authentication can always be re-done

    try {/*from   www  .  ja v a  2s.  c  o  m*/
        objStream = new ObjectInputStream(mContext.openFileInput(filename));
        serializableCookies = (ArrayList<Cookie>) objStream.readObject();
    } catch (StreamCorruptedException e) {
        return false;
    } catch (IOException e) {
        return false;
    } catch (ClassNotFoundException e) {
        return false;
    } catch (OutOfMemoryError e) {
        return false;
    } finally {
        if (objStream != null) {
            try {
                objStream.close();
            } catch (IOException e) {
                // Don't care
            }
        }
    }

    try {
        for (Cookie cookie : serializableCookies)
            store.addCookie(cookie);
    } catch (Exception ex) {
        deleteSession(account);
        return false;
    }

    return true;
}