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

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

Introduction

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

Prototype

Date getExpiryDate();

Source Link

Document

Returns the expiration Date of the cookie, or null if none exists.

Usage

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.droidparts.net.http.CookieJar.java

private static String toString(Cookie cookie) {
    StringBuilder sb = new StringBuilder();
    sb.append(cookie.getName());//  w  ww .j  av a 2  s. co  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:org.droidparts.http.CookieJar.java

private static String toString(Cookie cookie) {
    StringBuilder sb = new StringBuilder();
    sb.append(cookie.getName());// w  ww  .  j a v  a  2  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());
    sb.append(SEP);
    sb.append(cookie.getExpiryDate().getTime());
    return sb.toString();
}

From source file:fr.mixit.android.utils.NetworkUtils.java

static Cookie getCookie(DefaultHttpClient httpClient) {
    Cookie c = null;//  w w  w .  j  av  a  2s . co m
    for (final Cookie cookie : httpClient.getCookieStore().getCookies()) {
        if (cookie != null) {
            c = cookie;
            if (DEBUG_MODE) {
                Log.i("AppInfosFragment", "cookieInfos : "//
                        + "comment:" + cookie.getComment() + //
                        " commentURL:" + cookie.getCommentURL() + //
                        " domain:" + cookie.getDomain() + //
                        " name:" + cookie.getName() + //
                        " path:" + cookie.getPath() + //
                        " value:" + cookie.getValue() + //
                        " version:" + cookie.getVersion() + //
                        " expiryDate:" + cookie.getExpiryDate());
            }
        }
    }

    return c;
}

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;
    }/* w  ww . ja va 2s. c  o  m*/

    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:botvn.libraries.StorageCookies.java

public boolean Save() {
    if (mCookieStore != null) {
        FileWriter file = null;//from   w  w w.  j av  a  2s . c  o  m
        try {
            List<Cookie> ckss = mCookieStore.getCookies();
            HashMap<String, Object> d;
            JSONArray allCks = new JSONArray();
            for (Cookie cks : ckss) {
                d = new HashMap<>(ckss.size());
                String name = cks.getName();
                long expires = cks.getExpiryDate() != null ? cks.getExpiryDate().getTime() : 0;
                String path = cks.getPath();
                String domain = cks.getDomain();
                boolean secure = cks.isSecure();

                d.put("name", name);
                d.put("expires", expires);
                d.put("path", path);
                d.put("domain", domain);
                d.put("secure", secure);
                allCks.add(d);
            }

            String jsonStr = allCks.toJSONString();
            String currentDir = System.getProperty(USER_DIR);
            file = new FileWriter(currentDir + "/" + COOKIE_FILE);
            file.write(jsonStr);
            file.flush();
            file.close();
            return true;
        } catch (IOException ex) {
            Logger.getLogger(StorageCookies.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    return false;
}

From source file:net.fizzl.redditengine.impl.SerializableCookie.java

public SerializableCookie(Cookie cookie) {
    this.comment = cookie.getComment();
    this.commentURL = cookie.getCommentURL();
    this.domain = cookie.getDomain();
    this.expiryDate = cookie.getExpiryDate();
    this.name = cookie.getName();
    this.path = cookie.getPath();
    this.ports = cookie.getPorts();
    this.value = cookie.getValue();
    this.version = cookie.getVersion();
    this.secure = cookie.isSecure();
}

From source file:com.blazeroni.reddit.http.PersistentCookieStore.java

@Override
public void addCookie(Cookie cookie) {
    String name = cookie.getName();

    Date expiryDate = cookie.getExpiryDate();
    if (Log.DEBUG) {
        Log.debug("cookie value: " + cookie.getValue());
        Log.debug("Expiry date: " + (expiryDate == null ? "no expiry date" : expiryDate.toLocaleString()));
        Log.debug("persistent: " + cookie.isPersistent());
        Log.debug("Cookie class: " + cookie.getClass().getCanonicalName());
    }/*from www .j  ava 2s .c om*/

    // Save cookie into local store
    this.cookies.put(name, cookie);

    // Save cookie into persistent store
    SharedPreferences.Editor prefsWriter = this.cookiePrefs.edit();
    prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", this.cookies.keySet()));
    prefsWriter.putString(COOKIE_NAME_PREFIX + name, encodeCookie(new SerializableCookie(cookie)));
    prefsWriter.commit();

}

From source file:cn.isif.util_plus.util.PreferencesCookieStore.java

@Override
public boolean clearExpired(Date date) {
    boolean clearedAny = false;
    SharedPreferences.Editor editor = cookiePrefs.edit();

    for (ConcurrentHashMap.Entry<String, Cookie> entry : cookies.entrySet()) {
        String name = entry.getKey();
        Cookie cookie = entry.getValue();
        if (cookie.getExpiryDate() == null || cookie.isExpired(date)) {
            // Remove the cookie by name
            cookies.remove(name);/*w  w  w.  ja  va2  s  . c  om*/

            // Clear cookies from persistent store
            editor.remove(COOKIE_NAME_PREFIX + name);

            // We've cleared at least one
            clearedAny = true;
        }
    }

    // Update names in persistent store
    if (clearedAny) {
        editor.putString(COOKIE_NAME_STORE, TextUtils.join(",", cookies.keySet()));
    }
    editor.commit();

    return clearedAny;
}

From source file:com.partnet.automation.http.ApacheHttpAdapter.java

private List<CookieAdapter> convertCookieToAdapter(List<Cookie> cookies) {
    List<CookieAdapter> adapt = new ArrayList<>();

    for (Cookie cookie : cookies) {
        adapt.add(new CookieAdapter.Builder().setDomain(cookie.getDomain()).setName(cookie.getName())
                .setExpiryDate(cookie.getExpiryDate()).setPath(cookie.getPath()).setValue(cookie.getValue())
                .setVersion(cookie.getVersion()).build());
    }//from  ww w. j  a v a 2 s.c  om
    return adapt;
}