Search in sources :

Example 1 with DefaultRetryPolicy

use of com.android.volley.DefaultRetryPolicy in project glide by bumptech.

the class Api method query.

public void query(Query query) {
    if (lastQueryResult != null && lastQueryResult.query.equals(query)) {
        for (QueryListener listener : queryListeners) {
            listener.onSearchCompleted(lastQueryResult.query, lastQueryResult.results);
        }
        return;
    }
    FlickrQueryResponseListener responseListener = new FlickrQueryResponseListener(new PhotoJsonStringParser(), query, queryListeners);
    StringRequest request = new StringRequest(Request.Method.GET, query.getUrl(), responseListener, responseListener);
    request.setRetryPolicy(new DefaultRetryPolicy(DefaultRetryPolicy.DEFAULT_TIMEOUT_MS, 3, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
    requestQueue.add(request);
}
Also used : StringRequest(com.android.volley.toolbox.StringRequest) DefaultRetryPolicy(com.android.volley.DefaultRetryPolicy)

Example 2 with DefaultRetryPolicy

use of com.android.volley.DefaultRetryPolicy in project WordPress-Android by wordpress-mobile.

the class RestClientUtils method getSynchronous.

/**
     * Make Synchronous GET request with params
     *
     * @throws TimeoutException
     * @throws ExecutionException
     * @throws InterruptedException
     */
public JSONObject getSynchronous(String path, Map<String, String> params, RetryPolicy retryPolicy) throws InterruptedException, ExecutionException, TimeoutException {
    RequestFuture<JSONObject> future = RequestFuture.newFuture();
    HashMap<String, String> paramsWithLocale = getRestLocaleParams(mContext);
    if (params != null) {
        paramsWithLocale.putAll(params);
    }
    String realPath = getSanitizedPath(path);
    if (TextUtils.isEmpty(realPath)) {
        realPath = path;
    }
    paramsWithLocale.putAll(getSanitizedParameters(path));
    RestRequest request = mRestClient.makeRequest(Method.GET, mRestClient.getAbsoluteURL(realPath, paramsWithLocale), null, future, future);
    if (retryPolicy == null) {
        retryPolicy = new DefaultRetryPolicy(REST_TIMEOUT_MS, REST_MAX_RETRIES_GET, REST_BACKOFF_MULT);
    }
    request.setRetryPolicy(retryPolicy);
    AuthenticatorRequest authCheck = new AuthenticatorRequest(request, null, mRestClient, mAuthenticator);
    //this insert the request into the queue. //TODO: Verify that everything is OK on REST calls without a valid token
    authCheck.send();
    JSONObject response = future.get();
    return response;
}
Also used : RestRequest(com.wordpress.rest.RestRequest) JsonRestRequest(com.wordpress.rest.JsonRestRequest) JSONObject(org.json.JSONObject) DefaultRetryPolicy(com.android.volley.DefaultRetryPolicy)

Example 3 with DefaultRetryPolicy

use of com.android.volley.DefaultRetryPolicy in project WordPress-Android by wordpress-mobile.

the class RestClientUtils method get.

/**
     * Make GET request with params
     */
public Request<JSONObject> get(String path, Map<String, String> params, RetryPolicy retryPolicy, Listener listener, ErrorListener errorListener) {
    // turn params into querystring
    HashMap<String, String> paramsWithLocale = getRestLocaleParams(mContext);
    if (params != null) {
        paramsWithLocale.putAll(params);
    }
    String realPath = getSanitizedPath(path);
    if (TextUtils.isEmpty(realPath)) {
        realPath = path;
    }
    paramsWithLocale.putAll(getSanitizedParameters(path));
    RestRequest request = mRestClient.makeRequest(Method.GET, mRestClient.getAbsoluteURL(realPath, paramsWithLocale), null, listener, errorListener);
    if (retryPolicy == null) {
        retryPolicy = new DefaultRetryPolicy(REST_TIMEOUT_MS, REST_MAX_RETRIES_GET, REST_BACKOFF_MULT);
    }
    request.setRetryPolicy(retryPolicy);
    AuthenticatorRequest authCheck = new AuthenticatorRequest(request, errorListener, mRestClient, mAuthenticator);
    authCheck.send();
    return request;
}
Also used : RestRequest(com.wordpress.rest.RestRequest) JsonRestRequest(com.wordpress.rest.JsonRestRequest) DefaultRetryPolicy(com.android.volley.DefaultRetryPolicy)

Example 4 with DefaultRetryPolicy

use of com.android.volley.DefaultRetryPolicy in project buglife-android by Buglife.

the class NetworkManager method addToRequestQueue.

public <T> void addToRequestQueue(Request<T> request) {
    // Volley's default initial timeout is way too short, so let's bump it up.
    RetryPolicy retryPolicy = new DefaultRetryPolicy(INITIAL_TIMEOUT_MS, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
    request.setRetryPolicy(retryPolicy);
    mRequestQueue.add(request);
}
Also used : DefaultRetryPolicy(com.android.volley.DefaultRetryPolicy) RetryPolicy(com.android.volley.RetryPolicy) DefaultRetryPolicy(com.android.volley.DefaultRetryPolicy)

Example 5 with DefaultRetryPolicy

use of com.android.volley.DefaultRetryPolicy in project Logdata-Android by AndroidLogData.

the class HttpService method requestCrashData.

public void requestCrashData(String apiKey, CrashReportData report, final HttpCallback callback) {
    String url = makeURL(TransferType.CRASH);
    HttpOption option = httpOptionSetting(apiKey);
    JSONObject jsonObject = makeCrashDataJSON(report);
    JsonCustomRequest request = new JsonCustomRequest(Request.Method.POST, url, option, jsonObject, new Response.Listener<JSONObject>() {

        @Override
        public void onResponse(JSONObject response) {
            try {
                Log.i("Response", response.get("result").toString());
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            Log.e("VolleyError", "Crash Transfer Error");
        }
    });
    request.setRetryPolicy(new DefaultRetryPolicy(2000, 5, 1));
    addRequestQueue(request);
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) DefaultRetryPolicy(com.android.volley.DefaultRetryPolicy)

Aggregations

DefaultRetryPolicy (com.android.volley.DefaultRetryPolicy)23 VolleyError (com.android.volley.VolleyError)15 Response (com.android.volley.Response)13 NetworkResponse (com.android.volley.NetworkResponse)10 RequestQueue (com.android.volley.RequestQueue)10 HashMap (java.util.HashMap)10 JSONObject (org.json.JSONObject)10 ExecutionException (java.util.concurrent.ExecutionException)9 TimeoutException (java.util.concurrent.TimeoutException)9 Pair (android.util.Pair)8 StringRequest (com.android.volley.toolbox.StringRequest)8 GsonBuilder (com.google.gson.GsonBuilder)8 JsonObjectRequest (com.android.volley.toolbox.JsonObjectRequest)7 Gson (com.google.gson.Gson)7 JsonRestRequest (com.wordpress.rest.JsonRestRequest)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 JSONException (org.json.JSONException)4 ErrorListener (com.android.volley.Response.ErrorListener)3 RestRequest (com.wordpress.rest.RestRequest)3 ProfileItem (ai.saiy.android.cognitive.identity.provider.microsoft.containers.ProfileItem)2