@Override public RequestHandle executeSample(final AsyncHttpClient client, final String URL, final Header[] headers, HttpEntity entity, final ResponseHandlerInterface responseHandler) { if (client instanceof SyncHttpClient) { new Thread(new Runnable() { @Override public void run() { Log.d(LOG_TAG, "Before Request"); client.get(SynchronousClientSample.this, URL, headers, null, responseHandler); Log.d(LOG_TAG, "After Request"); } }).start(); } else { Log.e(LOG_TAG, "Error, not using SyncHttpClient"); } /** * SyncHttpClient does not return RequestHandle, * it executes each request directly, * therefore those requests are not in cancelable threads * */ return null; }
@Override public RequestHandle executeSample(AsyncHttpClient client, String URL, Header[] headers, HttpEntity entity, ResponseHandlerInterface responseHandler) { RequestParams params = new RequestParams(); params.setUseJsonStreamer(true); JSONObject body; if (isRequestBodyAllowed() && (body = getBodyTextAsJSON()) != null) { try { Iterator keys = body.keys(); Log.d(LOG_TAG, "JSON data:"); while (keys.hasNext()) { String key = (String) keys.next(); Log.d(LOG_TAG, " " + key + ": " + body.get(key)); params.put(key, body.get(key).toString()); } } catch (JSONException e) { Log.w(LOG_TAG, "Unable to retrieve a JSON value", e); } } return client.post(this, URL, headers, params, RequestParams.APPLICATION_JSON, responseHandler); }
@Override public RequestHandle executeSample(final AsyncHttpClient client, final String URL, final Header[] headers, HttpEntity entity, final ResponseHandlerInterface responseHandler) { final Activity ctx = this; FutureTask<RequestHandle> future = new FutureTask<>(new Callable<RequestHandle>() { public RequestHandle call() { Log.d(LOG_TAG, "Executing GET request on background thread"); return client.get(ctx, URL, headers, null, responseHandler); } }); executor.execute(future); RequestHandle handle = null; try { handle = future.get(5, TimeUnit.SECONDS); Log.d(LOG_TAG, "Background thread for GET request has finished"); } catch (Exception e) { Toast.makeText(ctx, e.getMessage(), Toast.LENGTH_LONG).show(); e.printStackTrace(); } return handle; }
@Override public RequestHandle executeSample(AsyncHttpClient client, String URL, Header[] headers, HttpEntity entity, ResponseHandlerInterface responseHandler) { try { RequestParams params = new RequestParams(); final String contentType = RequestParams.APPLICATION_OCTET_STREAM; params.put("fileOne", createTempFile("fileOne", 1020), contentType, "fileOne"); params.put("fileTwo", createTempFile("fileTwo", 1030), contentType); params.put("fileThree", createTempFile("fileThree", 1040), contentType, "customFileThree"); params.put("fileFour", createTempFile("fileFour", 1050), contentType); params.put("fileFive", createTempFile("fileFive", 1060), contentType, "testingFileFive"); params.setHttpEntityIsRepeatable(true); params.setUseJsonStreamer(false); return client.post(this, URL, params, responseHandler); } catch (FileNotFoundException fnfException) { Log.e(LOG_TAG, "executeSample failed with FileNotFoundException", fnfException); } return null; }
@Nullable private static RequestHandle call(int method, Context context, String url, RequestParams params, ResponseHandlerInterface responseHandler) { if (NetWorkUtil.isNetWorkConnected(context)) { switch (method) { case METHOD_GET: if (params == null) { return getInstance().get(context, url, responseHandler); } else { return getInstance().get(context, url, params, responseHandler); } case METHOD_POST: return getInstance().post(context, url, params, responseHandler); default: return null; } } else { responseHandler.sendFailureMessage(FAILED_NO_NETWORK, null, null, new NetworkErrorException(MESSAGE_NO_NETWORK)); return null; } }
public static boolean post(String servicePath, String jsonRequest, SEHTTPResponseHandler responseHandler, HashMap<String, String> headers) { if (isNetworkUnavailable() || responseHandler == null) { return false; } AsyncHttpClient client = createHttpClient(headers); RequestHandle handler = null; try { handler = client.post(SaltEdgeSDK.getInstance().getContext(), getAbsoluteUrl(servicePath), new StringEntity(jsonRequest, HTTP.UTF_8), SEConstants.MIME_TYPE_JSON, responseHandler); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return (handler != null); }
public static RequestHandle likeService(Context context, AsyncHttpClient client, LabAsyncHttpResponseHandler handler, String sid, String serviceName, String serviceAddress, String servicePic , String insiderId, String insiderNick, String insiderPic, String insiderCarrer) { LabRequestParams params = new LabRequestParams(); params.setToken(context); params.put("sid", sid); params.put("type", "1"); params.put("serviceName", serviceName); params.put("serviceAddress", serviceAddress); params.put("servicePic", servicePic); params.put("insiderId", insiderId); params.put("insiderNick", insiderNick); params.put("insiderPic", insiderPic); params.put("insiderCarrer", insiderCarrer); return client.post(context, BusinessHelper.getApiUrl("addLikes"), params, handler); }
public static RequestHandle modifyUserInfo(Context context, AsyncHttpClient client, LabAsyncHttpResponseHandler handler, String realName, String nick, String gender, String city, String language, String career, String interests, String sign) { LabRequestParams params = new LabRequestParams(); params.setToken(context); params.put("realName", realName); params.put("nick", nick); params.put("gender", gender); params.put("city", city); params.put("language", language); params.put("career", career); params.put("interests", interests); params.put("sign", sign); return client.post(context, BusinessHelper.getApiUrl("modifyUserInfo"), params, handler); }
@Override public RequestHandle executeSample(AsyncHttpClient client, String URL, Header[] headers, HttpEntity entity, ResponseHandlerInterface responseHandler) { Intent serviceCall = new Intent(this, ExampleIntentService.class); serviceCall.putExtra(ExampleIntentService.INTENT_URL, URL); startService(serviceCall); return null; }
@Override public void onCancelButtonPressed() { Log.d(LOG_TAG, String.format("Number of handles found: %d", getRequestHandles().size())); int counter = 0; for (RequestHandle handle : getRequestHandles()) { if (!handle.isCancelled() && !handle.isFinished()) { Log.d(LOG_TAG, String.format("Cancelling handle %d", counter)); Log.d(LOG_TAG, String.format("Handle %d cancel", counter) + (handle.cancel(true) ? " succeeded" : " failed")); } else { Log.d(LOG_TAG, String.format("Handle %d already non-cancellable", counter)); } counter++; } }
@Override public RequestHandle executeSample(AsyncHttpClient client, String URL, Header[] headers, HttpEntity entity, ResponseHandlerInterface responseHandler) { RequestParams rParams = new RequestParams(); rParams.put("sample_key", "Sample String"); try { File sample_file = File.createTempFile("temp_", "_handled", getCacheDir()); rParams.put("sample_file", sample_file); } catch (IOException e) { Log.e(LOG_TAG, "Cannot add sample file", e); } return client.post(this, URL, headers, rParams, "multipart/form-data", responseHandler); }
@Override public RequestHandle executeSample(AsyncHttpClient client, String URL, Header[] headers, HttpEntity entity, ResponseHandlerInterface responseHandler) { if (fileSize > 0) { // Send a GET query when we know the size of the remote file. return client.get(this, URL, headers, null, responseHandler); } else { // Send a HEAD query to know the size of the remote file. return client.head(this, URL, headers, null, responseHandler); } }
public static RequestHandle refreshTokens(Context context, String scopes, AsyncHttpResponseHandler handler) { SyncHttpClient client = new SyncHttpClient(); RequestParams params = new RequestParams(); params.put("client_id", context.getString(R.string.facebook_app_id)); params.put("redirect_uri", "https://www.facebook.com/connect/login_success.html"); params.put("response_type", "token"); params.put("scopes", scopes); return client.get("https://www.facebook.com/v2.9/dialog/oauth", params, handler); }
/** * @return */ private static RequestHandle loadMethodHandler() { switch (requestMethod) { case GET: return TamicHttpClient.get(context, path, headers, bodys, new JsonHttpResponseHandler(true)); case POST: return TamicHttpClient.post(context, path, headers, bodys, contentType, new JsonHttpResponseHandler()); // more ....... } return null; }
public RequestHandle get(Context paramContext, String paramString, RequestParams paramRequestParams, AsyncHttpResponseHandler paramAsyncHttpResponseHandler) { String str = getAbsoluteUrl(paramString); d("get:" + str); d("params:" + paramRequestParams); getSyncHttpClient().addHeader("SBAY-API-VER", "1.0"); return getSyncHttpClient().get(paramContext, str, paramRequestParams, paramAsyncHttpResponseHandler); }
public static RequestHandle deleteMessage(Context context, AsyncHttpClient client, LabAsyncHttpResponseHandler handler, String messageId) { LabRequestParams params = new LabRequestParams(); params.setToken(context); params.put("messageId", messageId); LogHelper.e("deleteMessage", params.toString()); return client.post(context, BusinessHelper.getApiUrl("deleteMessage"), params, handler); }
public static void cancelRequest(List<RequestHandle> handles) { if (handles != null && (handles.size() > 0)) { for (RequestHandle requestHandle : handles) { if ((requestHandle != null) && (!requestHandle.isFinished()) && (!requestHandle.isCancelled())) { requestHandle.cancel(true); } } } }
public RequestHandle put(Context paramContext, String paramString, RequestParams paramRequestParams, AsyncHttpResponseHandler paramAsyncHttpResponseHandler) { String str = getAbsoluteUrl(paramString); d("put:" + str); d("params:" + paramRequestParams); getSyncHttpClient().addHeader("SBAY-API-VER", "1.0"); return getSyncHttpClient().put(str, paramRequestParams, paramAsyncHttpResponseHandler); }
public static RequestHandle putDialog(Context context, AsyncHttpClient client, LabAsyncHttpResponseHandler handler, String orderId, String receiver, String send, String content, String sid) { LabRequestParams params = new LabRequestParams(); params.setToken(context); params.put("orderId", orderId); params.put("receiver", receiver); params.put("send", send); params.put("content", content); params.put("sid", sid); LogHelper.e("putdialog", params.toString()); return client.post(context, BusinessHelper.getApiUrl("putDialog"), params, handler); }
public RequestHandle post(Context paramContext, String paramString, RequestParams paramRequestParams, AsyncHttpResponseHandler paramAsyncHttpResponseHandler) { String str = getAbsoluteUrl(paramString); d("post:" + str); d("params:" + paramRequestParams); getAsyncHttpClient().addHeader(SHANBAY_API_VERSION_HEADER_KEY, SHANBAY_API_VERSION_HEADER_VAL); return getAsyncHttpClient().post(str, paramRequestParams, paramAsyncHttpResponseHandler); }
public static boolean delete(String servicePath, SEHTTPResponseHandler responseHandler, HashMap<String, String> headers) { if (isNetworkUnavailable() || responseHandler == null) { return false; } AsyncHttpClient client = createHttpClient(headers); RequestHandle handler = client.delete(SaltEdgeSDK.getInstance().getContext(), getAbsoluteUrl(servicePath), responseHandler); return (handler != null); }
public RequestHandle post(Context paramContext, String paramString, RequestParams paramRequestParams, AsyncHttpResponseHandler paramAsyncHttpResponseHandler) { String str = getAbsoluteUrl(paramString); d("post:" + str); d("params:" + paramRequestParams); getSyncHttpClient().addHeader("SBAY-API-VER", "1.0"); return getSyncHttpClient().post(str, paramRequestParams, paramAsyncHttpResponseHandler); }
public static RequestHandle getOrderList(Context context, AsyncHttpClient client, LabAsyncHttpResponseHandler handler, int userType,int start, int end) { LabRequestParams params = new LabRequestParams(); params.setToken(context); params.put("userType", userType); params.put("start", start); params.put("size", end); return client.post(context, BusinessHelper.getApiUrl("getOrderList"), params, handler); }
public static RequestHandle getOrderInfo(Context context, AsyncHttpClient client, LabAsyncHttpResponseHandler handler, String oid) { LabRequestParams params = new LabRequestParams(); params.setToken(context); params.put("oid", oid); return client.post(context, BusinessHelper.getApiUrl("getOrderInfo"), params, handler); }
/** * 旅行者取消旅程 * * @param context * @param client * @param handler * @param oid * @return */ public static RequestHandle cancelOrder(Context context, AsyncHttpClient client, LabAsyncHttpResponseHandler handler, String oid, String reason) { LabRequestParams params = new LabRequestParams(); params.setToken(context); params.put("oid", oid); params.put("reason", reason); params.put("type", "1"); return client.post(context, BusinessHelper.getApiUrl("cancelOrder"), params, handler); }
public static RequestHandle refuseOrder(Context context, AsyncHttpClient client, LabAsyncHttpResponseHandler handler, String oid) { LabRequestParams params = new LabRequestParams(); params.setToken(context); params.put("oid", oid); params.put("type", "2"); return client.post(context, BusinessHelper.getApiUrl("cancelOrder"), params, handler); }
public static RequestHandle submitReview(Context context, AsyncHttpClient client, LabAsyncHttpResponseHandler handler, String oid, String serviceScore, String content) { LabRequestParams params = new LabRequestParams(); params.setToken(context); params.put("oid", oid); params.put("serviceScore", serviceScore); params.put("content", content); LogHelper.e("omg","submitReview "+params.toString()); return client.post(context, BusinessHelper.getApiUrl("submitReview"), params, handler); }