Example usage for org.apache.http.cookie Cookie getDomain

List of usage examples for org.apache.http.cookie Cookie getDomain

Introduction

In this page you can find the example usage for org.apache.http.cookie Cookie getDomain.

Prototype

String getDomain();

Source Link

Document

Returns domain attribute of the cookie.

Usage

From source file:org.sharetask.data.IntegrationTest.java

@BeforeClass
public static void login() throws Exception {
    final DefaultHttpClient client = new DefaultHttpClient();
    final HttpPost httpPost = new HttpPost(BASE_URL + "/user/login");
    httpPost.addHeader(new BasicHeader("Content-Type", "application/json"));
    final StringEntity httpEntity = new StringEntity(
            "{\"username\":\"dev1@shareta.sk\"," + "\"password\":\"password\"}");
    System.out.println(EntityUtils.toString(httpEntity));
    httpPost.setEntity(httpEntity);/*from www.  j  a  v a2 s.co  m*/

    //when
    final HttpResponse response = client.execute(httpPost);

    //then
    Assert.assertEquals(HttpStatus.OK.value(), response.getStatusLine().getStatusCode());
    client.getCookieStore().getCookies();
    for (final Cookie cookie : client.getCookieStore().getCookies()) {
        if (cookie.getName().equals("JSESSIONID")) {
            DOMAIN = cookie.getDomain();
            SESSIONID = cookie.getValue();
        }
    }
}

From source file:net.emphased.lastcontact.CookieFileStore.java

private static String[] cookieToStringArray(Cookie cookie) {
    return new String[] { cookie.getName(), cookie.getValue(), String.valueOf(cookie.getExpiryDate().getTime()),
            cookie.getPath(), cookie.getDomain(), };
}

From source file:org.qi4j.library.shiro.AbstractServletTestSupport.java

protected static void soutCookies(Iterable<Cookie> cookies) {
    StringBuilder sb = new StringBuilder();
    sb.append("\nLogging cookies for the curious");
    for (Cookie eachCookie : cookies) {
        sb.append("\t").append(eachCookie.getName()).append(": ").append(eachCookie.getValue()).append(" ( ")
                .append(eachCookie.getDomain()).append(" - ").append(eachCookie.getPath()).append(" )");
    }/*from www  . j  av a 2s  . co m*/
    System.out.println(sb.append("\n").toString());
}

From source file:org.droidparts.http.CookieJar.java

private static boolean isEqual(Cookie first, Cookie second) {
    boolean equal = first.getName().equals(second.getName()) && first.getDomain().equals(second.getDomain())
            && first.getPath().equals(second.getPath());
    return equal;
}

From source file:Main.java

@Deprecated
// Deprecated because this uses org.apache.http, which is itself deprecated
public static HttpCookie servletCookieFromApacheCookie(org.apache.http.cookie.Cookie apacheCookie) {
    if (apacheCookie == null) {
        return null;
    }//  ww  w.j  a v a  2 s.c om

    String name = apacheCookie.getName();
    String value = apacheCookie.getValue();

    HttpCookie cookie = new HttpCookie(name, value);

    value = apacheCookie.getDomain();
    if (value != null) {
        cookie.setDomain(value);
    }
    value = apacheCookie.getPath();
    if (value != null) {
        cookie.setPath(value);
    }
    cookie.setSecure(apacheCookie.isSecure());

    value = apacheCookie.getComment();
    if (value != null) {
        cookie.setComment(value);
    }

    // version
    cookie.setVersion(apacheCookie.getVersion());

    // From the Apache source code, maxAge is converted to expiry date using the following formula
    // if (maxAge >= 0) {
    //     setExpiryDate(new Date(System.currentTimeMillis() + maxAge * 1000L));
    // }
    // Reverse this to get the actual max age

    Date expiryDate = apacheCookie.getExpiryDate();
    if (expiryDate != null) {
        long maxAge = (expiryDate.getTime() - System.currentTimeMillis()) / 1000;
        // we have to lower down, no other option
        cookie.setMaxAge((int) maxAge);
    }

    // return the servlet cookie
    return cookie;
}

From source file:com.cappuccino.requestframework.CookieManager.java

public static void saveCookie(DefaultHttpClient client) {

    //  //from  ww  w  .  j  av  a  2s  . c o m
    if (CookieManager.initialized == false) {
        throw new RuntimeException(" ?");
    }
    if (client == null) {
        throw new IllegalArgumentException();
    }

    //    ? ?
    List<Cookie> cookieList = client.getCookieStore().getCookies();
    if (!cookieList.isEmpty()) {
        //  ? 
        for (Cookie cookie : cookieList) {

            //  sp ? 
            String cookieName = cookie.getName();
            String cookieValue = cookie.getValue();
            String cookieDomain = cookie.getDomain();
            // Date cookieExpiryDate = cookie.getExpiryDate();

            application.setCookieName(cookieName);
            application.setCookieValue(cookieValue);
            application.setCookieDomain(cookieDomain);
            // application.setCookieExpiryDate(cookieExpiryDate);

            if (RequestConfig.debuggable() == true) {
                Log.e();
                Log.e("?  ?");
                Log.e(" ? : " + cookieName);
                Log.e("  : " + cookieValue);
                Log.e(" ?? : " + cookieDomain);
            }
        }
    }
}

From source file:org.droidparts.http.CookieJar.java

private static String toString(Cookie cookie) {
    StringBuilder sb = new StringBuilder();
    sb.append(cookie.getName());//from  ww  w.j  a va  2 s.  c om
    sb.append(SEP);
    sb.append(cookie.getValue());
    sb.append(SEP);
    sb.append(cookie.getDomain());
    sb.append(SEP);
    sb.append(cookie.getPath());
    sb.append(SEP);
    sb.append(cookie.getExpiryDate().getTime());
    return sb.toString();
}

From source file:org.droidparts.net.http.CookieJar.java

private static String toString(Cookie cookie) {
    StringBuilder sb = new StringBuilder();
    sb.append(cookie.getName());/*  ww w  .j  a v  a2 s  . c o m*/
    sb.append(SEP);
    sb.append(cookie.getValue());
    sb.append(SEP);
    sb.append(cookie.getDomain());
    sb.append(SEP);
    sb.append(cookie.getPath());
    Date expiryDate = cookie.getExpiryDate();
    if (expiryDate != null) {
        sb.append(SEP);
        sb.append(expiryDate.getTime());
    }
    return sb.toString();
}

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

static boolean isClearanceCookie(Cookie cookie, String url, String requiredCookieName) {
    try {/*from w ww  .ja va 2s .  co  m*/
        String cookieName = cookie.getName();
        String cookieDomain = cookie.getDomain();
        if (!cookieDomain.startsWith(".")) {
            cookieDomain = "." + cookieDomain;
        }

        String urlCookie = "." + Uri.parse(url).getHost();
        if (cookieName.equals(requiredCookieName) && cookieDomain.equalsIgnoreCase(urlCookie)) {
            return true;
        }
    } catch (Exception e) {
        Logger.e(TAG, e);
    }
    return false;
}

From source file:cn.ttyhuo.common.MyApplication.java

public static void getJavaCookieStore(java.net.CookieStore jCookieStore) {
    if (cookieStore == null)
        return;//from w  w  w.j a v  a2s  . c o m

    for (Cookie h : cookieStore.getCookies()) {
        HttpCookie newCookie = new HttpCookie(h.getName(), h.getValue());
        newCookie.setVersion(h.getVersion());
        newCookie.setDomain(h.getDomain());
        newCookie.setPath(h.getPath());
        newCookie.setSecure(h.isSecure());
        newCookie.setComment(h.getComment());
        jCookieStore.add(URI.create("http://" + h.getDomain()), newCookie);
    }
}