当前位置: 首页>>代码示例>>Java>>正文


Java StringEntity类代码示例

本文整理汇总了Java中cz.msebera.android.httpclient.entity.StringEntity的典型用法代码示例。如果您正苦于以下问题:Java StringEntity类的具体用法?Java StringEntity怎么用?Java StringEntity使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


StringEntity类属于cz.msebera.android.httpclient.entity包,在下文中一共展示了StringEntity类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendSubscription

import cz.msebera.android.httpclient.entity.StringEntity; //导入依赖的package包/类
public void sendSubscription(Subscription subscription) {
    String interest =  subscription.getInterest();
    InterestSubscriptionChange change = subscription.getChange();

    JSONObject json = new JSONObject();
    try {
        json.put("app_key", appKey);
    } catch (JSONException e) {
        Log.e(TAG, e.getMessage());
    }
    StringEntity entity = new StringEntity(json.toString(), "UTF-8");

    String url = options.buildNotificationURL("/clients/" + clientId + "/interests/" + interest);
    ResponseHandlerInterface handler = factory.newSubscriptionChangeHandler(subscription);
    AsyncHttpClient client = factory.newHttpClient();
    switch (change) {
        case SUBSCRIBE:
            client.post(context, url, entity, "application/json", handler);
            break;
        case UNSUBSCRIBE:
            client.delete(context, url, entity, "application/json", handler);
            break;
    }
}
 
开发者ID:pusher,项目名称:pusher-websocket-android,代码行数:25,代码来源:SubscriptionManager.java

示例2: testSubscribe

import cz.msebera.android.httpclient.entity.StringEntity; //导入依赖的package包/类
@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)
    );
}
 
开发者ID:pusher,项目名称:pusher-websocket-android,代码行数:25,代码来源:SubscriptionManagerTest.java

示例3: receiveUploadsWhenNoCachedId

import cz.msebera.android.httpclient.entity.StringEntity; //导入依赖的package包/类
@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
    );
}
 
开发者ID:pusher,项目名称:pusher-websocket-android,代码行数:24,代码来源:TokenRegistryTest.java

示例4: uploadsOnInvalidClientId

import cz.msebera.android.httpclient.entity.StringEntity; //导入依赖的package包/类
@Test
public void uploadsOnInvalidClientId() throws Exception {
    JSONObject json = new JSONObject();
    json.put("platform_type", PlatformType.GCM.toString());
    json.put("token", "token-woot");
    json.put("app_key", "app-key-lala");
    StringEntity params = new StringEntity(json.toString(), "UTF-8");
    tokenRegistry.onInvalidClientId(params);
    verify(client).post(
            eq(context),
            eq("https://nativepushclient-cluster1.pusher.com/client_api/v1/clients"),
            eq(params),
            eq("application/json"),
            eq(tokenUploadHandler)
    );
}
 
开发者ID:pusher,项目名称:pusher-websocket-android,代码行数:17,代码来源:TokenRegistryTest.java

示例5: getRequestEntity

import cz.msebera.android.httpclient.entity.StringEntity; //导入依赖的package包/类
public HttpEntity getRequestEntity() {
    String bodyText;
    if (isRequestBodyAllowed() && (bodyText = getBodyText()) != null) {
        try {
            return new StringEntity(bodyText);
        } catch (UnsupportedEncodingException e) {
            Log.e(LOG_TAG, "cannot create String entity", e);
        }
    }
    return null;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:SampleParentActivity.java

示例6: update

import cz.msebera.android.httpclient.entity.StringEntity; //导入依赖的package包/类
private void update(String token, String cachedId) throws JSONException {
    String url = options.buildNotificationURL("/clients/" + cachedId + "/token");
    AsyncHttpClient client = factory.newHttpClient();
    StringEntity params = createRegistrationJSON(token);

    AsyncHttpResponseHandler handler = factory.newTokenUpdateHandler(
            cachedId, params, context, listenerStack, this
    );
    client.put(context, url, params, "application/json", handler);
}
 
开发者ID:pusher,项目名称:pusher-websocket-android,代码行数:11,代码来源:TokenRegistry.java

示例7: createRegistrationJSON

import cz.msebera.android.httpclient.entity.StringEntity; //导入依赖的package包/类
private StringEntity createRegistrationJSON(String token) throws JSONException {
    JSONObject params = new JSONObject();
    params.put("platform_type", platformType.toString());
    params.put("token", token);
    params.put("app_key", appKey);
    return new StringEntity(params.toString(), "UTF-8");
}
 
开发者ID:pusher,项目名称:pusher-websocket-android,代码行数:8,代码来源:TokenRegistry.java

示例8: TokenUpdateHandler

import cz.msebera.android.httpclient.entity.StringEntity; //导入依赖的package包/类
public TokenUpdateHandler(String cachedId, StringEntity retryParams, Context context, RegistrationListenerStack listenerStack, InvalidClientIdHandler invalidClientIdHandler) {
    this.cachedId = cachedId;
    this.retryParams = retryParams;
    this.context = context;
    this.listenerStack = listenerStack;
    this.invalidClientIdHandler = invalidClientIdHandler;
}
 
开发者ID:pusher,项目名称:pusher-websocket-android,代码行数:8,代码来源:TokenUpdateHandler.java

示例9: testUnsubscribe

import cz.msebera.android.httpclient.entity.StringEntity; //导入依赖的package包/类
@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)
    );
}
 
开发者ID:pusher,项目名称:pusher-websocket-android,代码行数:29,代码来源:SubscriptionManagerTest.java

示例10: setUp

import cz.msebera.android.httpclient.entity.StringEntity; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    JSONObject json = new JSONObject();
    json.put("platform_type", PlatformType.GCM.toString());
    json.put("token", "token-woot");
    json.put("app_key", "app-key-lala");
    params = new StringEntity(json.toString(), "UTF-8");

    tokenUpdateHandler = new TokenUpdateHandler(
            "cached-id", params, context,listenerStack, invalidClientIdHandler
    );
}
 
开发者ID:pusher,项目名称:pusher-websocket-android,代码行数:14,代码来源:TokenUpdateHandlerTest.java

示例11: setUp

import cz.msebera.android.httpclient.entity.StringEntity; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    PreferenceManager.getDefaultSharedPreferences(context).edit().clear().apply();

    when(factory.newHttpClient()).thenReturn(client);
    when(factory.newTokenUploadHandler(any(Context.class), any(RegistrationListenerStack.class))).thenReturn(tokenUploadHandler);
    when(factory.newTokenUpdateHandler(any(String.class), any(StringEntity.class), any(Context.class), any(RegistrationListenerStack.class), any(InvalidClientIdHandler.class))).thenReturn(tokenUpdateHandler);

    stack = new RegistrationListenerStack();
    tokenRegistry = new TokenRegistry("superkey", stack, context, PlatformType.FCM, options, factory);
}
 
开发者ID:pusher,项目名称:pusher-websocket-android,代码行数:13,代码来源:TokenRegistryTest.java

示例12: receivesUpdatesWhenCachedId

import cz.msebera.android.httpclient.entity.StringEntity; //导入依赖的package包/类
@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
    );
}
 
开发者ID:pusher,项目名称:pusher-websocket-android,代码行数:36,代码来源:TokenRegistryTest.java

示例13: post

import cz.msebera.android.httpclient.entity.StringEntity; //导入依赖的package包/类
public static void post(Context mContext, String url, JSONObject jsonObject, JsonHttpResponseHandler jsonHttpResponseHandler) {
    UserManager userManager = new UserManager(mContext);
    try {
        jsonObject.put("token", userManager.get_token());
    } catch (JSONException e) {
        e.printStackTrace();
    }
    StringEntity stringEntity = new StringEntity(jsonObject.toString(), HTTP.UTF_8);
    client.post(mContext, getAbsoluteTokenUrl(url, mContext), stringEntity, "application/json; charset=utf-8", jsonHttpResponseHandler);
}
 
开发者ID:BillBillBillBill,项目名称:WishTalk-android,代码行数:11,代码来源:WishtalkRestClient.java

示例14: put

import cz.msebera.android.httpclient.entity.StringEntity; //导入依赖的package包/类
public static void put(Context mContext, String url, JSONObject jsonObject, JsonHttpResponseHandler jsonHttpResponseHandler) {
    UserManager userManager = new UserManager(mContext);
    try {
        jsonObject.put("token", userManager.get_token());
    } catch (JSONException e) {
        e.printStackTrace();
    }
    StringEntity stringEntity = new StringEntity(jsonObject.toString(), HTTP.UTF_8);
    client.put(mContext, getAbsoluteTokenUrl(url, mContext), stringEntity, "application/json; charset=utf-8", jsonHttpResponseHandler);
}
 
开发者ID:BillBillBillBill,项目名称:WishTalk-android,代码行数:11,代码来源:WishtalkRestClient.java

示例15: get

import cz.msebera.android.httpclient.entity.StringEntity; //导入依赖的package包/类
public static void get(Context mContext, String url, JSONObject jsonObject, JsonHttpResponseHandler jsonHttpResponseHandler) {
    UserManager userManager = new UserManager(mContext);
    try {
        jsonObject.put("token", userManager.get_token());
    } catch (JSONException e) {
        e.printStackTrace();
    }
    StringEntity stringEntity = new StringEntity(jsonObject.toString(), HTTP.UTF_8);
    client.get(mContext, getAbsoluteTokenUrl(url, mContext), stringEntity, "application/json; charset=utf-8", jsonHttpResponseHandler);
}
 
开发者ID:BillBillBillBill,项目名称:WishTalk-android,代码行数:11,代码来源:WishtalkRestClient.java


注:本文中的cz.msebera.android.httpclient.entity.StringEntity类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。