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

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

Introduction

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

Prototype

List<Cookie> getCookies();

Source Link

Document

Returns all cookies contained in this store.

Usage

From source file:org.confab.Utilities.java

public static void printCookieStore(CookieStore cookieStore) {
    debug("printCookies");
    List<Cookie> cookies = cookieStore.getCookies();
    if (cookies.isEmpty()) {
        System.out.println("None");
    } else {/*  w  w w  .  ja v a  2s  . c o  m*/
        for (int i = 0; i < cookies.size(); i++) {
            System.out.println("- " + cookies.get(i).toString());
        }
    }
    debug("end printCookies");
}

From source file:co.paralleluniverse.comsat.webactors.servlet.WebActorServletTest.java

private static String getByName(final CookieStore cookieStore, String name) {
    for (org.apache.http.cookie.Cookie cookie : cookieStore.getCookies())
        if (name.equals(cookie.getName()))
            return cookie.getValue();
    return null;//from  ww w  . j a v a 2  s  .  c  o m
}

From source file:com.sampullara.findmyiphone.FindMyDevice.java

private static String extractIscCode(DefaultHttpClient hc) {
    CookieStore cookies = hc.getCookieStore();
    for (Cookie cookie : cookies.getCookies()) {
        if (cookie.getName().equals("isc-secure.me.com")) {
            return cookie.getValue();
        }/* w  w  w .j a  v  a  2s  . c  o m*/
    }
    return null;
}

From source file:com.game.sns.volley.MyVolley.java

public static Cookie getCookies(CookieStore cs, String cookieName) {
    Cookie ret = null;/*w w  w .  ja va2  s.c  o m*/

    List<Cookie> l = cs.getCookies();
    for (Cookie c : l) {
        if (c.getName().equals(cookieName)) {
            ret = c;
            break;
        }
    }

    return ret;
}

From source file:org.apache.ambari.view.hive.client.Utils.java

static boolean needToSendCredentials(CookieStore cookieStore, String cookieName, boolean isSSL) {
    if (cookieName == null || cookieStore == null) {
        return true;
    }/*from  w w  w. ja  va2s. c  om*/

    List<Cookie> cookies = cookieStore.getCookies();

    for (Cookie c : cookies) {
        // If this is a secured cookie and the current connection is non-secured,
        // then, skip this cookie. We need to skip this cookie because, the cookie
        // replay will not be transmitted to the server.
        if (c.isSecure() && !isSSL) {
            continue;
        }
        if (c.getName().equals(cookieName)) {
            return false;
        }
    }
    return true;
}

From source file:org.gluu.oxeleven.client.ClientUtils.java

public static void showClient(BaseClient client, CookieStore cookieStore) {
    showClient(client);/*from w w w .  j  a  v  a2  s . c o m*/

    System.out.println("-------------------------------------------------------");
    System.out.println("COOKIES:");
    System.out.println("-------------------------------------------------------");
    System.out.println(cookieStore.getCookies());
    System.out.println("");
}

From source file:nya.miku.wishmaster.http.cloudflare.CloudflareChecker.java

static void removeCookie(CookieStore store, String name) {
    boolean flag = false;
    for (Cookie cookie : store.getCookies()) {
        if (cookie.getName().equals(name)) {
            if (cookie instanceof SetCookie) {
                flag = true;/*ww  w .ja  v  a2s .com*/
                ((SetCookie) cookie).setExpiryDate(new Date(0));
            } else {
                Logger.e(TAG,
                        "cannot remove cookie (object does not implement SetCookie): " + cookie.toString());
            }
        }
    }
    if (flag)
        store.clearExpired(new Date());
}

From source file:com.aurel.track.master.ModuleBL.java

public static Cookie sendPOSTRequest(String urlString) {
    Cookie responseCookie = null;//from w ww  .  ja v  a  2 s .c  om
    try {
        HttpClient httpclient = new DefaultHttpClient();//HttpClients.createDefault();
        HttpPost httppost = new HttpPost(urlString);
        // Request parameters and other properties.
        //Execute and get the response.
        HttpContext localContext = new BasicHttpContext();
        CookieStore cookieStore = new BasicCookieStore();
        localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
        HttpResponse response = httpclient.execute(httppost, localContext);

        if (cookieStore.getCookies().size() > 0) {
            List<org.apache.http.cookie.Cookie> cookies = cookieStore.getCookies();
            for (org.apache.http.cookie.Cookie cookie : cookies) {
                if (cookie.getName().equals("JSESSIONID")) {
                    responseCookie = new Cookie(cookie.getName(), cookie.getValue());
                    responseCookie.setPath(cookie.getPath());
                    responseCookie.setDomain(cookie.getDomain());
                }
            }
        }
        if (response.getEntity() != null) {
            response.getEntity().consumeContent();
        }

    } catch (Exception ex) {
        LOGGER.debug(ExceptionUtils.getStackTrace(ex));
    }
    return responseCookie;
}

From source file:org.jboss.as.test.integration.web.sso.SSOTestBase.java

public static String getSessionIdValueFromState(CookieStore cookieStore) {
    String sessionID = null;/*from  ww  w.java 2s  .c  om*/
    for (Cookie cookie : cookieStore.getCookies()) {
        if ("JSESSIONID".equalsIgnoreCase(cookie.getName())) {
            sessionID = cookie.getValue();
            break;
        }
    }
    return sessionID;
}

From source file:org.jboss.as.test.integration.web.sso.SSOTestBase.java

public static String processSSOCookie(CookieStore cookieStore, String serverA, String serverB) {
    String ssoID = null;//from   ww  w .ja v  a2 s  . c  o  m
    for (Cookie cookie : cookieStore.getCookies()) {
        if ("JSESSIONIDSSO".equalsIgnoreCase(cookie.getName())) {
            ssoID = cookie.getValue();
            if (serverA.equals(serverB) == false) {
                // Make an sso cookie to send to serverB
                Cookie copy = copyCookie(cookie, serverB);
                cookieStore.addCookie(copy);
            }
        }
    }

    assertTrue("Didn't saw JSESSIONIDSSO", ssoID != null);
    return ssoID;
}