Search in sources :

Example 1 with CloseableHttpClient

use of cz.msebera.android.httpclient.impl.client.CloseableHttpClient in project Simple-Dilbert by smarek.

the class GetStripUrl method doInBackground.

@Override
protected String[] doInBackground(Void... params) {
    if (this.currDate == null) {
        Log.e(TAG, "Cannot load for null date");
        return null;
    }
    String cached = this.preferences.getCachedUrl(this.currDate);
    if (cached != null) {
        return new String[] { cached, this.preferences.getCachedTitle(this.currDate) };
    }
    HttpGet get = new HttpGet("http://dilbert.com/strip/" + currDate.toString(DilbertPreferences.DATE_FORMATTER) + "/");
    HttpResponse response = null;
    CloseableHttpClient client = null;
    try {
        client = HttpClients.createSystem();
        response = client.execute(get);
    } catch (Exception e) {
        Log.e(TAG, "HttpGet failed", e);
    }
    if (response == null) {
        return null;
    }
    String[] rtn = handleParse(response);
    try {
        client.close();
    } catch (IOException e) {
        Log.e(TAG, "Closing HttpClient failed", e);
    }
    return rtn;
}
Also used : CloseableHttpClient(cz.msebera.android.httpclient.impl.client.CloseableHttpClient) HttpGet(cz.msebera.android.httpclient.client.methods.HttpGet) HttpResponse(cz.msebera.android.httpclient.HttpResponse) IOException(java.io.IOException) IOException(java.io.IOException) NetworkErrorException(android.accounts.NetworkErrorException)

Aggregations

NetworkErrorException (android.accounts.NetworkErrorException)1 HttpResponse (cz.msebera.android.httpclient.HttpResponse)1 HttpGet (cz.msebera.android.httpclient.client.methods.HttpGet)1 CloseableHttpClient (cz.msebera.android.httpclient.impl.client.CloseableHttpClient)1 IOException (java.io.IOException)1