Search in sources :

Example 1 with HttpResponseCache

use of com.github.ignition.support.http.cache.HttpResponseCache in project ignition by mttkay.

the class IgnitedHttpSampleActivity method updateCacheStatus.

public void updateCacheStatus() {
    EditText memoryCacheText = (EditText) findViewById(R.id.ignitedhttp_text_cache_memory);
    memoryCacheText.setText("");
    EditText diskCacheText = (EditText) findViewById(R.id.ignitedhttp_text_cache_disk);
    diskCacheText.setText("");
    HttpResponseCache cache = http.getResponseCache();
    if (cache != null) {
        for (String key : cache.keySet()) {
            if (cache.containsKeyInMemory(key)) {
                memoryCacheText.append(cache.getFileNameForKey(key) + "\n");
            }
        }
        List<File> cachedFiles = cache.getCachedFiles();
        for (File file : cachedFiles) {
            diskCacheText.append(file.getName() + "\n");
        }
    }
}
Also used : EditText(android.widget.EditText) HttpResponseCache(com.github.ignition.support.http.cache.HttpResponseCache) File(java.io.File)

Example 2 with HttpResponseCache

use of com.github.ignition.support.http.cache.HttpResponseCache in project ignition by mttkay.

the class IgnitedHttpRequestBase method handleResponse.

@Override
public IgnitedHttpResponse handleResponse(HttpResponse response) throws IOException {
    int status = response.getStatusLine().getStatusCode();
    if (expectedStatusCodes != null && !expectedStatusCodes.isEmpty() && !expectedStatusCodes.contains(status)) {
        throw new HttpResponseException(status, "Unexpected status code: " + status);
    }
    IgnitedHttpResponse bhttpr = new IgnitedHttpResponseImpl(response);
    HttpResponseCache responseCache = ignitedHttp.getResponseCache();
    if (responseCache != null && bhttpr.getResponseBody() != null) {
        ResponseData responseData = new ResponseData(status, bhttpr.getResponseBodyAsBytes());
        responseCache.put(getRequestUrl(), responseData);
    }
    return bhttpr;
}
Also used : ResponseData(com.github.ignition.support.http.cache.CachedHttpResponse.ResponseData) HttpResponseCache(com.github.ignition.support.http.cache.HttpResponseCache) HttpResponseException(org.apache.http.client.HttpResponseException)

Aggregations

HttpResponseCache (com.github.ignition.support.http.cache.HttpResponseCache)2 EditText (android.widget.EditText)1 ResponseData (com.github.ignition.support.http.cache.CachedHttpResponse.ResponseData)1 File (java.io.File)1 HttpResponseException (org.apache.http.client.HttpResponseException)1