cz.msebera.android.httpclient.util.EntityUtils Java Examples

The following examples show how to use cz.msebera.android.httpclient.util.EntityUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SubscriptionManagerTest.java    From pusher-websocket-android with MIT License 6 votes vote down vote up
@Test
public void testSubscribe() throws IOException {
    Subscription sub = new Subscription("donuts",
            InterestSubscriptionChange.SUBSCRIBE,
            listener);
    subscriptionManager.sendSubscription(sub);

    ArgumentCaptor<Subscription> subCaptor = ArgumentCaptor.forClass(Subscription.class);
    verify(factory).newSubscriptionChangeHandler(sub);

    ArgumentCaptor paramsCaptor = ArgumentCaptor.forClass(StringEntity.class);
    verify(client).post(
            eq(context),
            eq("https://nativepushclient-cluster1.pusher.com/client_api/v1/clients/123-456/interests/donuts"),
            (HttpEntity) paramsCaptor.capture(),
            eq("application/json"),
            eq(subscriptionChangeHandler)
    );
    StringEntity params = (StringEntity) paramsCaptor.getValue();
    assertEquals(
            "{\"app_key\":\"super-cool-key\"}",
            EntityUtils.toString(params)
    );
}
 
Example #2
Source File: TokenRegistryTest.java    From pusher-websocket-android with MIT License 6 votes vote down vote up
@Test
public void receiveUploadsWhenNoCachedId() throws Exception {
    tokenRegistry.receive("mysuperspecialfcmtoken");
    verify(factory).newTokenUploadHandler(context, stack);

    ArgumentCaptor paramsCaptor = ArgumentCaptor.forClass(StringEntity.class);

    verify(client).post(
            eq(context),
            eq("https://nativepushclient-cluster1.pusher.com/client_api/v1/clients"),
            (HttpEntity) paramsCaptor.capture(),
            eq("application/json"),
            eq(tokenUploadHandler)
    );

    // test proper params sent
    HttpEntity params = (HttpEntity) paramsCaptor.getValue();
    JSONAssert.assertEquals(
            EntityUtils.toString(params),
            "{\"platform_type\":\"fcm\",\"token\":\"mysuperspecialfcmtoken\",\"app_key\":\"superkey\"}",
            true
    );
}
 
Example #3
Source File: FeedFragment.java    From Instagram-Profile-Downloader with MIT License 5 votes vote down vote up
@Override
protected String doInBackground(Void... params) {
    HttpClient httpClient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(url);
    try {
        HttpResponse response = httpClient.execute(httpGet);
        HttpEntity httpEntity = response.getEntity();
        return EntityUtils.toString(httpEntity);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #4
Source File: ProfileFragment.java    From Instagram-Profile-Downloader with MIT License 5 votes vote down vote up
@Override
protected String doInBackground(Void... params) {
    HttpClient httpClient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(url);
    try {
        HttpResponse response = httpClient.execute(httpGet);
        HttpEntity httpEntity = response.getEntity();
        return EntityUtils.toString(httpEntity);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #5
Source File: OverviewDialog.java    From Instagram-Profile-Downloader with MIT License 5 votes vote down vote up
@Override
protected String doInBackground(Void... params) {
    HttpClient httpClient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(url);
    try {
        HttpResponse response = httpClient.execute(httpGet);
        HttpEntity httpEntity = response.getEntity();
        return EntityUtils.toString(httpEntity);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #6
Source File: MainActivity.java    From Instagram-Profile-Downloader with MIT License 5 votes vote down vote up
@Override
protected String doInBackground(Void... params) {
    HttpClient httpClient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(url);
    try {
        HttpResponse response = httpClient.execute(httpGet);
        HttpEntity httpEntity = response.getEntity();
        return EntityUtils.toString(httpEntity);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #7
Source File: MainActivity.java    From Instagram-Profile-Downloader with MIT License 5 votes vote down vote up
@Override
protected String doInBackground(Void... params) {
    HttpClient httpClient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(final_url);
    try {
        HttpResponse response = httpClient.execute(httpGet);
        HttpEntity httpEntity = response.getEntity();
        return EntityUtils.toString(httpEntity);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #8
Source File: IntroScreenActivity.java    From Instagram-Profile-Downloader with MIT License 5 votes vote down vote up
@Override
protected String doInBackground(Void... params) {
    HttpClient httpClient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(getResources().getString(R.string.get_user_info_url) + token);
    try {
        HttpResponse response = httpClient.execute(httpGet);
        HttpEntity httpEntity = response.getEntity();
        return EntityUtils.toString(httpEntity);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #9
Source File: DownloadProfileImageActivity.java    From Instagram-Profile-Downloader with MIT License 5 votes vote down vote up
@Override
protected String doInBackground(Void... params) {
    HttpClient httpClient = new DefaultHttpClient();
    try {
        HttpGet httpGet = new HttpGet(url);
        HttpResponse response = httpClient.execute(httpGet);
        HttpEntity httpEntity = response.getEntity();
        return EntityUtils.toString(httpEntity);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #10
Source File: SubscriptionManagerTest.java    From pusher-websocket-android with MIT License 5 votes vote down vote up
@Test
public void testUnsubscribe() throws IOException {
    Subscription subscription = new Subscription(
            "donuts",
            InterestSubscriptionChange.UNSUBSCRIBE,
            listener);
    subscriptionManager.sendSubscription(subscription);

    ArgumentCaptor<Subscription> subCaptor = ArgumentCaptor.forClass(Subscription.class);

    verify(factory).newSubscriptionChangeHandler(
            subscription
    );

    ArgumentCaptor paramsCaptor = ArgumentCaptor.forClass(StringEntity.class);
    verify(client).delete(
            eq(context),
            eq("https://nativepushclient-cluster1.pusher.com/client_api/v1/clients/123-456/interests/donuts"),
            (HttpEntity) paramsCaptor.capture(),
            eq("application/json"),
            eq(subscriptionChangeHandler)
    );
    StringEntity params = (StringEntity) paramsCaptor.getValue();
    assertEquals(
            "{\"app_key\":\"super-cool-key\"}",
            EntityUtils.toString(params)
    );
}
 
Example #11
Source File: TokenRegistryTest.java    From pusher-websocket-android with MIT License 5 votes vote down vote up
@Test
public void receivesUpdatesWhenCachedId() throws Exception {
    PreferenceManager.
            getDefaultSharedPreferences(context).
            edit().
            putString("__pusher__client__key__fcm__superkey", "this-is-the-client-id")
            .apply();

    tokenRegistry.receive("woot-token-woot");
    ArgumentCaptor paramsCaptor = ArgumentCaptor.forClass(StringEntity.class);

    verify(factory).newTokenUpdateHandler(
            eq("this-is-the-client-id"),
            (StringEntity) paramsCaptor.capture(),
            eq(context),
            eq(stack),
            eq(tokenRegistry)
    );


    StringEntity sentParams = (StringEntity) paramsCaptor.getValue();

    verify(client).put(
            eq(context),
            eq("https://nativepushclient-cluster1.pusher.com/client_api/v1/clients/this-is-the-client-id/token"),
            eq(sentParams),
            eq("application/json"),
            eq(tokenUpdateHandler)
    );

    JSONAssert.assertEquals(EntityUtils.toString((HttpEntity) paramsCaptor.getValue()),
            "{\"platform_type\":\"fcm\",\"token\":\"woot-token-woot\",\"app_key\":\"superkey\"}",
            true
    );
}
 
Example #12
Source File: HorochanModule.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String deletePost(DeletePostModel model, ProgressListener listener, CancellableTask task) throws Exception {
    String url = getUsingUrl(true) + "v1/posts/" + model.postNumber;
    HttpEntity entity = ExtendedMultipartBuilder.create().setDelegates(listener, task).addString("password", model.password).build();
    HttpUriRequest request = null;
    HttpResponse response = null;
    HttpEntity responseEntity = null;
    try {
        request = RequestBuilder.delete().setUri(url).setEntity(entity).build();
        response = httpClient.execute(request);
        StatusLine status = response.getStatusLine();
        switch (status.getStatusCode()) {
            case 200:
                return null;
            case 400:
                responseEntity = response.getEntity();
                InputStream stream = IOUtils.modifyInputStream(responseEntity.getContent(), null, task);
                JSONObject json = new JSONObject(new JSONTokener(new BufferedReader(new InputStreamReader(stream))));
                throw new Exception(json.getString("message"));
            default:
                throw new Exception(status.getStatusCode() + " - " + status.getReasonPhrase());
        }
    } finally {
        try { if (request != null) request.abort(); } catch (Exception e) {}
        EntityUtils.consumeQuietly(responseEntity);
        if (response != null && response instanceof Closeable) IOUtils.closeQuietly((Closeable) response);
    }
}
 
Example #13
Source File: MainActivity.java    From httpclient-android with Apache License 2.0 5 votes vote down vote up
@Override
protected String doInBackground(Void... voids) {
    String ret = null;
    CloseableHttpClient chc = HttpClients.createDefault();
    try {
        CloseableHttpResponse chr = chc.execute(HttpHost.create("https://httpbin.org"), new HttpGet("/headers"));
        ret = EntityUtils.toString(chr.getEntity());
        chr.close();
        chc.close();
    } catch (Exception e) {
        Log.e("HttpTest", e.getMessage(), e);
        ret = e.getMessage();
    }
    return ret;
}
 
Example #14
Source File: HttpClientHelper.java    From BaiduPanApi-Java with MIT License 5 votes vote down vote up
public static String getResponseString(CloseableHttpResponse closeableHttpResponse,String charset) throws IOException {
    HttpEntity bufferedHttpEntity = closeableHttpResponse.getEntity();
    if(charset == null){
        charset = CHARSET;
    }
    return EntityUtils.toString(bufferedHttpEntity, charset);
}
 
Example #15
Source File: SubscriptionManagerTest.java    From pusher-websocket-android with MIT License 4 votes vote down vote up
@Test
public void testSendingListOfSubscriptions() throws IOException {
    Subscription sub1 = new Subscription("kittens", InterestSubscriptionChange.SUBSCRIBE, listener);
    Subscription sub2 = new Subscription("donuts", InterestSubscriptionChange.UNSUBSCRIBE, listener);
    List<Subscription> list = new ArrayList<>(Arrays.asList(sub1, sub2));
    subscriptionManager.sendSubscriptions(list);

    ArgumentCaptor<Subscription> subCaptor = ArgumentCaptor.forClass(Subscription.class);
    verify(factory).newSubscriptionChangeHandler(sub1);

    ArgumentCaptor paramsCaptor = ArgumentCaptor.forClass(StringEntity.class);

    InOrder inOrder = inOrder(client);
    inOrder.verify(client).post(
            eq(context),
            eq("https://nativepushclient-cluster1.pusher.com/client_api/v1/clients/123-456/interests/kittens"),
            (HttpEntity) paramsCaptor.capture(),
            eq("application/json"),
            eq(subscriptionChangeHandler)
    );
    StringEntity params = (StringEntity) paramsCaptor.getValue();
    assertEquals(
            "{\"app_key\":\"super-cool-key\"}",
            EntityUtils.toString(params)
    );

    ArgumentCaptor<Subscription> subCaptor2 = ArgumentCaptor.forClass(Subscription.class);
    verify(factory).newSubscriptionChangeHandler(sub2);

    ArgumentCaptor deleteCaptor = ArgumentCaptor.forClass(StringEntity.class);

    inOrder.verify(client).delete(
            eq(context),
            eq("https://nativepushclient-cluster1.pusher.com/client_api/v1/clients/123-456/interests/donuts"),
            (HttpEntity) deleteCaptor.capture(),
            eq("application/json"),
            eq(subscriptionChangeHandler)
    );

    StringEntity deleteParams = (StringEntity) deleteCaptor.getValue();
    assertEquals(
            "{\"app_key\":\"super-cool-key\"}",
            EntityUtils.toString(deleteParams)
    );
}