Search in sources :

Example 11 with Cookie

use of com.firenio.codec.http11.Cookie in project java-sdk by watson-developer-cloud.

the class WatsonCookieJar method loadForRequest.

/*
   * (non-Javadoc)
   *
   * @see okhttp3.CookieJar#loadForRequest(okhttp3.HttpUrl)
   */
@Override
public List<Cookie> loadForRequest(HttpUrl url) {
    List<Cookie> cookies = this.adapter.loadForRequest(url);
    // TODO: Removes the SESSIONID for speech to text session lest requests
    if (url.encodedPathSegments().contains(SPEECH_TO_TEXT) && !url.encodedPathSegments().contains(SESSIONS)) {
        List<Cookie> sessionLessCookies = new ArrayList<Cookie>();
        for (Cookie cookie : cookies) {
            if (!cookie.name().equalsIgnoreCase(SESSIONID)) {
                sessionLessCookies.add(cookie);
            }
        }
        cookies = sessionLessCookies;
    }
    return cookies;
}
Also used : Cookie(okhttp3.Cookie) ArrayList(java.util.ArrayList)

Example 12 with Cookie

use of com.firenio.codec.http11.Cookie in project WanAndroid by dangxy.

the class SharedPrefsCookiePersistor method loadAll.

@Override
public List<Cookie> loadAll() {
    List<Cookie> cookies = new ArrayList<>(sharedPreferences.getAll().size());
    for (Map.Entry<String, ?> entry : sharedPreferences.getAll().entrySet()) {
        String serializedCookie = (String) entry.getValue();
        Cookie cookie = new SerializableCookie().decode(serializedCookie);
        if (cookie != null) {
            cookies.add(cookie);
        }
    }
    return cookies;
}
Also used : Cookie(okhttp3.Cookie) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 13 with Cookie

use of com.firenio.codec.http11.Cookie in project 91Pop by DanteAndroid.

the class SharedPrefsCookiePersistor method loadAll.

@Override
public List<Cookie> loadAll() {
    List<Cookie> cookies = new ArrayList<>(sharedPreferences.getAll().size());
    for (Map.Entry<String, ?> entry : sharedPreferences.getAll().entrySet()) {
        String serializedCookie = (String) entry.getValue();
        Cookie cookie = new SerializableCookie().decode(serializedCookie);
        if (cookie != null) {
            cookies.add(cookie);
        }
    }
    return cookies;
}
Also used : Cookie(okhttp3.Cookie) SerializableCookie(com.franmontiel.persistentcookiejar.persistence.SerializableCookie) ArrayList(java.util.ArrayList) Map(java.util.Map) SerializableCookie(com.franmontiel.persistentcookiejar.persistence.SerializableCookie)

Example 14 with Cookie

use of com.firenio.codec.http11.Cookie in project 91Pop by DanteAndroid.

the class SharedPrefsCookiePersistor method saveAll.

@Override
public void saveAll(Collection<Cookie> cookies) {
    SharedPreferences.Editor editor = sharedPreferences.edit();
    for (Cookie cookie : cookies) {
        editor.putString(createCookieKey(cookie), new SerializableCookie().encode(cookie));
    }
    editor.apply();
}
Also used : Cookie(okhttp3.Cookie) SerializableCookie(com.franmontiel.persistentcookiejar.persistence.SerializableCookie) SharedPreferences(android.content.SharedPreferences) SerializableCookie(com.franmontiel.persistentcookiejar.persistence.SerializableCookie)

Example 15 with Cookie

use of com.firenio.codec.http11.Cookie in project AndroidFrame by tongxiaoyun.

the class SerializableCookie method decode.

public Cookie decode(String encodedCookie) {
    byte[] bytes = hexStringToByteArray(encodedCookie);
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
    Cookie cookie = null;
    ObjectInputStream objectInputStream = null;
    try {
        objectInputStream = new ObjectInputStream(byteArrayInputStream);
        cookie = ((SerializableCookie) objectInputStream.readObject()).cookie;
    } catch (IOException e) {
        Log.d(TAG, "IOException in decodeCookie", e);
    } catch (ClassNotFoundException e) {
        Log.d(TAG, "ClassNotFoundException in decodeCookie", e);
    } finally {
        if (objectInputStream != null) {
            try {
                objectInputStream.close();
            } catch (IOException e) {
                Log.d(TAG, "Stream not closed in decodeCookie", e);
            }
        }
    }
    return cookie;
}
Also used : Cookie(okhttp3.Cookie) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

Cookie (okhttp3.Cookie)102 ArrayList (java.util.ArrayList)31 IOException (java.io.IOException)20 HttpUrl (okhttp3.HttpUrl)18 ByteArrayInputStream (java.io.ByteArrayInputStream)16 ObjectInputStream (java.io.ObjectInputStream)16 SharedPreferences (android.content.SharedPreferences)12 Context (android.content.Context)8 HashMap (java.util.HashMap)8 List (java.util.List)8 Map (java.util.Map)8 Test (org.junit.Test)8 Response (okhttp3.Response)7 SerializableCookie (com.lzy.okgo.cookie.SerializableCookie)6 Request (okhttp3.Request)6 SuppressLint (android.annotation.SuppressLint)4 CookieManager (android.webkit.CookieManager)4 EhCookieStore (com.hippo.ehviewer.client.EhCookieStore)4 OnClick (butterknife.OnClick)3 SerializableCookie (com.franmontiel.persistentcookiejar.persistence.SerializableCookie)3