com.android.volley.VolleyError Java Examples
The following examples show how to use
com.android.volley.VolleyError.
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: BasicNetworkTest.java From volley with Apache License 2.0 | 6 votes |
@Test public void noConnectionNoRetry() throws Exception { MockHttpStack mockHttpStack = new MockHttpStack(); mockHttpStack.setExceptionToThrow(new IOException()); BasicNetwork httpNetwork = new BasicNetwork(mockHttpStack); Request<String> request = buildRequest(); request.setRetryPolicy(mMockRetryPolicy); request.setShouldRetryConnectionErrors(false); doThrow(new VolleyError()).when(mMockRetryPolicy).retry(any(VolleyError.class)); try { httpNetwork.performRequest(request); } catch (VolleyError e) { // expected } // should not retry when there is no connection verify(mMockRetryPolicy, never()).retry(any(VolleyError.class)); }
Example #2
Source File: ComposeTweetActivity.java From catnut with MIT License | 6 votes |
private void injectListener() { listener = new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { // delete posted text and thumbs mText.setText(null); if (mUris != null) { mUris.clear(); mAdapter.notifyDataSetChanged(); } Toast.makeText(ComposeTweetActivity.this, R.string.post_success, Toast.LENGTH_SHORT).show(); } }; errorListener = new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.e(TAG, "post tweet error!", error); WeiboAPIError weiboAPIError = WeiboAPIError.fromVolleyError(error); Toast.makeText(ComposeTweetActivity.this, weiboAPIError.error, Toast.LENGTH_LONG).show(); } }; mCustomizedBar.findViewById(R.id.action_geo).setOnClickListener(this); mCustomizedBar.findViewById(R.id.action_send).setOnClickListener(this); mLocationMarker.setOnClickListener(this); }
Example #3
Source File: Request4PushFreshComment.java From JianDan_OkHttpWithVolley with Apache License 2.0 | 6 votes |
@Override protected Response<Boolean> parseNetworkResponse(NetworkResponse response) { try { String resultStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); JSONObject resultObj = new JSONObject(resultStr); String result = resultObj.optString("status"); String error=resultObj.optString("error"); if ( result.equals("ok")) { return Response.success(true, HttpHeaderParser.parseCacheHeaders(response)); } else { return Response.error(new VolleyError("错误原因:" + error)); } } catch (Exception e) { e.printStackTrace(); return Response.error(new VolleyError(e)); } }
Example #4
Source File: ImageLoader.java From volley with Apache License 2.0 | 6 votes |
/** * The default implementation of ImageListener which handles basic functionality of showing a * default image until the network response is received, at which point it will switch to either * the actual image or the error image. * * @param view The imageView that the listener is associated with. * @param defaultImageResId Default image resource ID to use, or 0 if it doesn't exist. * @param errorImageResId Error image resource ID to use, or 0 if it doesn't exist. */ public static ImageListener getImageListener( final ImageView view, final int defaultImageResId, final int errorImageResId) { return new ImageListener() { @Override public void onErrorResponse(VolleyError error) { if (errorImageResId != 0) { view.setImageResource(errorImageResId); } } @Override public void onResponse(ImageContainer response, boolean isImmediate) { if (response.getBitmap() != null) { view.setImageBitmap(response.getBitmap()); } else if (defaultImageResId != 0) { view.setImageResource(defaultImageResId); } } }; }
Example #5
Source File: ImageLoader.java From volley with Apache License 2.0 | 6 votes |
protected Request<Bitmap> makeImageRequest( String requestUrl, int maxWidth, int maxHeight, ScaleType scaleType, final String cacheKey) { return new ImageRequest( requestUrl, new Listener<Bitmap>() { @Override public void onResponse(Bitmap response) { onGetImageSuccess(cacheKey, response); } }, maxWidth, maxHeight, scaleType, Config.RGB_565, new ErrorListener() { @Override public void onErrorResponse(VolleyError error) { onGetImageError(cacheKey, error); } }); }
Example #6
Source File: GalleryActivity.java From meizhi with Apache License 2.0 | 6 votes |
@Override public void onRefresh() { refresh.setRefreshing(true); new GalleryRequest() { @Override protected void deliverResponse(List<Album> response) { Log.d(TAG, "total: " + response.size()); refresh.setRefreshing(false); adapter.setList(response); application.getGalleryCache().addAll(response); } @Override public void deliverError(VolleyError error) { refresh.setRefreshing(false); Log.e(TAG, "error", error); } }.enqueue(application.getRequestQueue()); }
Example #7
Source File: ChatPresenter.java From TouchNews with Apache License 2.0 | 6 votes |
private void onRequestMessage(String message) { /*“key”: “APIKEY”, “info”: “今天天气怎么样”, “loc”:“北京市中关村”, “userid”:“12345678”*/ param.put(Keys.INFO, EncodeString(message)); param.put("userid", "12345678"); NetRequestUtil.getInstance().getJson(UrlUtil.URL_CHAT, param, new NetRequestUtil.RequestListener() { @Override public void onResponse(JSONObject response) { LogUtils.i(response); try { if (response.getString("code").equals("100000")) { mView.onReceiveRespond(response.getString("text")); } } catch (JSONException e) { e.printStackTrace(); } } @Override public void onError(VolleyError error) { } }); }
Example #8
Source File: BasicNetworkTest.java From product-emm with Apache License 2.0 | 6 votes |
@Test public void serverError_disableRetries() throws Exception { for (int i = 500; i <= 599; i++) { MockHttpStack mockHttpStack = new MockHttpStack(); BasicHttpResponse fakeResponse = new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 1), i, ""); mockHttpStack.setResponseToReturn(fakeResponse); BasicNetwork httpNetwork = new BasicNetwork(mockHttpStack); Request<String> request = buildRequest(); request.setRetryPolicy(mMockRetryPolicy); doThrow(new VolleyError()).when(mMockRetryPolicy).retry(any(VolleyError.class)); try { httpNetwork.performRequest(request); } catch (VolleyError e) { // expected } // should not retry any 500 error w/ HTTP 500 retries turned off (the default). verify(mMockRetryPolicy, never()).retry(any(VolleyError.class)); reset(mMockRetryPolicy); } }
Example #9
Source File: LocalSearch.java From MapsSDK-Native with MIT License | 6 votes |
static void sendRequest(Context context, String query, GeoboundingBox bounds, Callback callback) { if (query == null || query.isEmpty()) { Toast.makeText(context, "Invalid query", Toast.LENGTH_LONG).show(); return; } String boundsStr = String.format(Locale.ROOT, "%.6f,%.6f,%.6f,%.6f", bounds.getSouth(), bounds.getWest(), bounds.getNorth(), bounds.getEast()); RequestQueue queue = Volley.newRequestQueue(context); queue.add(new StringRequest( Request.Method.GET, URL_ENDPOINT.replace("{query}", query).replace("{bounds}", boundsStr), (String response) -> { List<Poi> results = parse(response); if (results == null || results.isEmpty()) { callback.onFailure(); return; } callback.onSuccess(results); }, (VolleyError error) -> callback.onFailure() )); }
Example #10
Source File: AboutModelImpl.java From allenglish with Apache License 2.0 | 6 votes |
@Override public void checkNewVersion() { Map<String, String> map = new HashMap<>(); map.put("appKey", "56bd51ddb76877188a1836d791ed8436"); map.put("_api_key", "a08ef5ee127a27bd4210f7e1f9e7c84e"); VolleySingleton.getInstance().addToRequestQueue(new GsonRequest<>(Request.Method.POST, "https://www.pgyer.com/apiv2/app/view", ViewBean.class, null, map, new Response.Listener<ViewBean>() { @Override public void onResponse(ViewBean response) { if (response.data.buildVersion.equals(CommonUtils.getVersionName(BaseApplication.getInstance()))) { listener.onNoNewVersion(); } else { listener.onGetANewVersion(response.data.buildUpdateDescription); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { listener.onCheckFailed(); } })); }
Example #11
Source File: BasicNetworkTest.java From product-emm with Apache License 2.0 | 6 votes |
@Test public void serverError_disableRetries() throws Exception { for (int i = 500; i <= 599; i++) { MockHttpStack mockHttpStack = new MockHttpStack(); BasicHttpResponse fakeResponse = new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 1), i, ""); mockHttpStack.setResponseToReturn(fakeResponse); BasicNetwork httpNetwork = new BasicNetwork(mockHttpStack); Request<String> request = buildRequest(); request.setRetryPolicy(mMockRetryPolicy); doThrow(new VolleyError()).when(mMockRetryPolicy).retry(any(VolleyError.class)); try { httpNetwork.performRequest(request); } catch (VolleyError e) { // expected } // should not retry any 500 error w/ HTTP 500 retries turned off (the default). verify(mMockRetryPolicy, never()).retry(any(VolleyError.class)); reset(mMockRetryPolicy); } }
Example #12
Source File: LeaderboardsFragment.java From android-kubernetes-blockchain with Apache License 2.0 | 6 votes |
public void getUserFromMongo(String userId) { JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, BACKEND_URL + "/registerees/info/" + userId , null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { UserInfoModel userInfoModel = gson.fromJson(response.toString(), UserInfoModel.class); userStats.setText(String.format("%s steps", String.valueOf(userInfoModel.getSteps()))); getUserPosition(String.valueOf(userInfoModel.getSteps())); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.d(TAG, "That didn't work!"); } }); queue.add(jsonObjectRequest); }
Example #13
Source File: RVNetwork.java From RestVolley with Apache License 2.0 | 6 votes |
/** * Attempts to prepare the request for a retry. If there are no more attempts remaining in the * request's retry policy, a timeout exception is thrown. * @param request The request to use. */ protected static void attemptRetryOnException(String logPrefix, Request<?> request, VolleyError exception) throws VolleyError { RetryPolicy retryPolicy = request.getRetryPolicy(); int oldTimeout = request.getTimeoutMs(); try { retryPolicy.retry(exception); } catch (VolleyError e) { request.addMarker(String.format("%s-timeout-giveup [timeout=%s]", logPrefix, oldTimeout)); throw e; } request.addMarker(String.format("%s-retry [timeout=%s]", logPrefix, oldTimeout)); //reentry the requestQueue RequestQueue requestQueue = getRequestQueue(request); if (requestQueue != null) { requestQueue.add(request); } throw new RetryError(); }
Example #14
Source File: PictureAdapter.java From JianDan with Apache License 2.0 | 6 votes |
private void loadData() { RequestManager.addRequest(new Request4Picture(Picture.getRequestUrl(mType, page), new Response.Listener<ArrayList<Picture>> () { @Override public void onResponse(ArrayList<Picture> response) { getCommentCounts(response); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { mLoadResultCallBack.onError(LoadResultCallBack.ERROR_NET, error.getMessage()); mLoadFinisCallBack.loadFinish(null); } }), mActivity); }
Example #15
Source File: BasicNetworkTest.java From volley with Apache License 2.0 | 6 votes |
@Test public void serverError_disableRetries() throws Exception { for (int i = 500; i <= 599; i++) { MockHttpStack mockHttpStack = new MockHttpStack(); HttpResponse fakeResponse = new HttpResponse(i, Collections.<Header>emptyList()); mockHttpStack.setResponseToReturn(fakeResponse); BasicNetwork httpNetwork = new BasicNetwork(mockHttpStack); Request<String> request = buildRequest(); request.setRetryPolicy(mMockRetryPolicy); doThrow(new VolleyError()).when(mMockRetryPolicy).retry(any(VolleyError.class)); try { httpNetwork.performRequest(request); } catch (VolleyError e) { // expected } // should not retry any 500 error w/ HTTP 500 retries turned off (the default). verify(mMockRetryPolicy, never()).retry(any(VolleyError.class)); reset(mMockRetryPolicy); } }
Example #16
Source File: CrossbowImage.java From CrossBow with Apache License 2.0 | 6 votes |
private void loadImage(ImageView imageView, int drawableID, String file, String url, int width, int height) { if(pendingImage != null) { pendingImage.cancel(); } pendingImage = new PendingImage(); if(url != null && file == null && drawableID == DEFAULT) { pendingImage.imageContainer = imageLoader.get(url, this, width, height, scaleType); } else if(url == null && file != null && drawableID == DEFAULT) { pendingImage.fileImageContainer = fileImageLoader.get(file, width, height, this); } else if(url == null && file == null && drawableID != DEFAULT) { ScaleTypeDrawable defaultScale = new ScaleTypeDrawable(defaultDrawable, this.preScaleType); imageView.setImageDrawable(defaultScale); } else { onErrorResponse(new VolleyError("No image source defined")); } }
Example #17
Source File: WrapperTests.java From api-android-java with MIT License | 5 votes |
@Test public void releaseDates() throws Exception { setUp(); Map<APIWrapper.Operator, String> args = new HashMap<>(); args.put(APIWrapper.Operator.IDS, "4"); final CountDownLatch lock = new CountDownLatch(1); wrapper.releaseDates(args, new onSuccessCallback() { @Override public void onSuccess(JSONArray result) { JSONObject jo; try { lock.countDown(); jo = result.getJSONObject(0); String s = jo.getString("human"); assertThat(s, is("2008-Oct-20")); } catch (JSONException e) { e.printStackTrace(); } } @Override public void onError(VolleyError error) { } }); lock.await(20000, TimeUnit.MILLISECONDS); }
Example #18
Source File: ShipfForMeService.java From tgen with Apache License 2.0 | 5 votes |
public static RpcRequest UserSaveShipForMeOrderPrice(final String orderIds, final double price, final Listener<Void> listener) { RpcRequest req = new RpcRequest(Request.Method.POST, TRpc.getJsonRpcUrl(), new Response.Listener<String>() { @Override public void onResponse(String response) {if (listener != null) { listener.onResponse(null); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { listener.onResponse(null); } }) { @Override public byte[] getBody() { final ArrayList<Object> params = new ArrayList<>(); params.add(orderIds); params.add(price); HashMap<String, Object> msg = new HashMap<>(); msg.put("id", getMsgID()); msg.put("method", "ShipfForMe.UserSaveShipForMeOrderPrice"); msg.put("params", params); return gson.toJson(msg).getBytes(Charset.forName("UTF-8")); } }; TRpc.getQueue().add(req); return req; }
Example #19
Source File: ThreadViewFragment.java From something.apk with MIT License | 5 votes |
@JavascriptInterface public void onLastReadClick(String postIndex){ final int index = FastUtils.safeParseInt(postIndex, 0); if(index > 0){ runOnUiThread(new Runnable() { @Override public void run() { FastAlert.process(getActivity(), getView(), getSafeString(R.string.mark_last_read_started)); queueRequest(new MarkLastReadRequest(getActivity(), threadId, index, new Response.Listener<ThreadPageRequest.ThreadPage>() { @Override public void onResponse(ThreadPageRequest.ThreadPage response) { Activity activity = getActivity(); if(activity instanceof MainActivity && ((MainActivity) activity).isFragmentFocused(ThreadViewFragment.this)){ FastAlert.notice(activity, getView(), getSafeString(R.string.mark_last_read_success)); } pageListener.onResponse(response); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { FastAlert.error(getActivity(), getView(), getSafeString(R.string.mark_last_read_failure)); } } )); } }); }else{ throw new RuntimeException("Invalid postIndex in onLastReadClick: "+postIndex); } }
Example #20
Source File: WishlistFragment.java From openshop.io-android with MIT License | 5 votes |
/** * Load wishlist content. * * @param user logged user. */ private void getWishlistContent(@NonNull User user) { String url = String.format(EndPoints.WISHLIST, SettingsMy.getActualNonNullShop(getActivity()).getId()); progressDialog.show(); GsonRequest<WishlistResponse> getWishlist = new GsonRequest<>(Request.Method.GET, url, null, WishlistResponse.class, new Response.Listener<WishlistResponse>() { @Override public void onResponse(@NonNull WishlistResponse wishlistResponse) { if (progressDialog != null) progressDialog.cancel(); for (int i = 0; i < wishlistResponse.getItems().size(); i++) { wishlistAdapter.add(i, wishlistResponse.getItems().get(i)); } checkIfEmpty(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { if (progressDialog != null) progressDialog.cancel(); MsgUtils.logAndShowErrorMessage(getActivity(), error); } }, getFragmentManager(), user.getAccessToken()); getWishlist.setRetryPolicy(MyApplication.getDefaultRetryPolice()); getWishlist.setShouldCache(false); MyApplication.getInstance().addToRequestQueue(getWishlist, CONST.CART_REQUESTS_TAG); }
Example #21
Source File: ComposeTweetService.java From catnut with MIT License | 5 votes |
private void update(final Draft draft) { mApp.getRequestQueue().add(new CatnutRequest( this, TweetAPI.update(draft.status, draft.visible, draft.list_id, draft.lat, draft._long, null, draft.rip), mSendWeiboProcessor, null, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { WeiboAPIError weiboAPIError = WeiboAPIError.fromVolleyError(error); fallback(draft, weiboAPIError.error); } } )).setTag(TAG); }
Example #22
Source File: VolleyClient.java From EasyPay with Apache License 2.0 | 5 votes |
@Override public void get(PayParams payParams, final CallBack c) { RequestQueue queue = Volley.newRequestQueue(payParams.getActivity()); String baseUrl = payParams.getApiUrl(); StringBuffer sburl = new StringBuffer(); sburl.append(baseUrl) .append("?") .append("pay_way=").append(payParams.getPayWay()) .append("&") .append("price=").append(payParams.getGoodsPrice()) .append("&") .append("goods_name=").append(payParams.getGoodsName()) .append("&") .append("goods_introduction=").append(payParams.getGoodsIntroduction()); StringRequest request = new StringRequest(Request.Method.GET, sburl.toString(), new Response.Listener<String>() { @Override public void onResponse(String response) { c.onSuccess(response); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { c.onFailure(); } }); queue.add(request); }
Example #23
Source File: ImageCache.java From SmileEssence with MIT License | 5 votes |
public ImageLoader.ImageContainer requestBitmap(String imageURL) { return imageLoader.get(imageURL, new ImageLoader.ImageListener() { @Override public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate) { } @Override public void onErrorResponse(VolleyError error) { } }); }
Example #24
Source File: WebServiceCoordinator.java From opentok-android-sdk-samples with MIT License | 5 votes |
public void stopArchive(String archiveId) { String requestUrl = OpenTokConfig.ARCHIVE_STOP_ENDPOINT.replace(":archiveId", archiveId); this.reqQueue.add(new JsonObjectRequest(Request.Method.POST, requestUrl, null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { Log.i(LOG_TAG, "archive stopped"); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { delegate.onWebServiceCoordinatorError(error); } })); }
Example #25
Source File: GenresTest.java From api-android-java with MIT License | 5 votes |
@Test public void testSingleGenres() throws InterruptedException { setUp(); Parameters parameters = new Parameters() .addIds("2"); final CountDownLatch lock = new CountDownLatch(1); wrapper.genres(parameters, new OnSuccessCallback() { @Override public void onSuccess(JSONArray result) { try { lock.countDown(); JSONObject object = result.getJSONObject(0); int testId = object.getInt("id"); assertEquals(2, testId); } catch (JSONException e) { e.printStackTrace(); fail("JSONException!!"); } } @Override public void onError(VolleyError error) { fail("Volley Error!!"); } }); lock.await(20000, TimeUnit.MILLISECONDS); }
Example #26
Source File: WishlistFragment.java From openshop.io-android with MIT License | 5 votes |
/** * Method remove concrete product from the wishlist by wishlistId. * Expected all non-null parameters. * * @param activity related activity. * @param wishlistId id of the wishlist item representing product. * @param user related user account. * @param requestTag string identifying concrete request. Useful for request cancellation. * @param requestListener listener for operation results. */ public static void removeFromWishList(final FragmentActivity activity, long wishlistId, User user, String requestTag, final RequestListener requestListener) { if (activity != null && wishlistId != 0 && user != null && requestTag != null && requestListener != null) { String url = String.format(EndPoints.WISHLIST_SINGLE, SettingsMy.getActualNonNullShop(activity).getId(), wishlistId); JsonRequest req = new JsonRequest(Request.Method.DELETE, url, null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { Timber.d("RemoveFromWishlist response: %s", response.toString()); new Handler().postDelayed(new Runnable() { @Override public void run() { requestListener.requestSuccess(0); } }, 500); } }, new Response.ErrorListener() { @Override public void onErrorResponse(final VolleyError error) { new Handler().postDelayed(new Runnable() { @Override public void run() { requestListener.requestFailed(error); } }, 500); MsgUtils.logAndShowErrorMessage(activity, error); } }, activity.getSupportFragmentManager(), user.getAccessToken()); req.setRetryPolicy(MyApplication.getDefaultRetryPolice()); req.setShouldCache(false); MyApplication.getInstance().addToRequestQueue(req, requestTag); } else { if (requestListener != null) requestListener.requestFailed(null); Timber.e(new RuntimeException(), "Remove from wishlist product with null parameters."); } }
Example #27
Source File: ThreadViewFragment.java From something.apk with MIT License | 5 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()){ case R.id.menu_thread_reply: startActivityForResult( new Intent(getActivity(), ReplyActivity.class) .putExtra("thread_id", threadId) .putExtra("reply_type", ReplyFragment.TYPE_REPLY), REQUEST_REPLY ); return true; case R.id.menu_thread_bookmark: FastAlert.process(getActivity(), getView(), getString(bookmarked ? R.string.bookmarking_thread_started_removing : R.string.bookmarking_thread_started)); queueRequest(new BookmarkRequest(threadId, !bookmarked, new Response.Listener<Boolean>() { @Override public void onResponse(Boolean response) { bookmarked = response; invalidateOptionsMenu(); FastAlert.notice(getActivity(), getView(), getString(response ? R.string.bookmarking_thread_success_add : R.string.bookmarking_thread_success_remove)); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { FastAlert.error(getActivity(), getView(), getString(R.string.bookmarking_thread_failure)); } })); return true; } return super.onOptionsItemSelected(item); }
Example #28
Source File: MainActivity.java From example with Apache License 2.0 | 5 votes |
private void getTickerData(String URL) { JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, URL, null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject jsonObject) { progressDialog.dismiss(); Log.d("debug", "data -> " + jsonObject.toString()); // parsing data json menggunakan GSON try { ticker = new Gson().fromJson(jsonObject.getJSONObject("ticker").toString(), Ticker.class); // tampilkan data showDataTicker(ticker); } catch (JSONException e) { // error e.printStackTrace(); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError volleyError) { // errror progressDialog.dismiss(); } }); progressDialog.show(); BaseApplication.getInstance().addToRequestQueue(request, "tag"); }
Example #29
Source File: PulseGroupsTest.java From api-android-java with MIT License | 5 votes |
@Test public void testMultiplePulseGroups() throws InterruptedException { setUp(); Parameters parameters = new Parameters() .addIds("5772,5775,5777"); final CountDownLatch lock = new CountDownLatch(1); wrapper.pulseGroups(parameters, new OnSuccessCallback() { @Override public void onSuccess(JSONArray result) { try { lock.countDown(); JSONObject object1 = result.getJSONObject(0); JSONObject object2 = result.getJSONObject(1); JSONObject object3 = result.getJSONObject(2); assertEquals(5772, object1.getInt("id")); assertEquals(5775, object2.getInt("id")); assertEquals(5777, object3.getInt("id")); } catch (JSONException e) { e.printStackTrace(); fail("JSONException!!"); } } @Override public void onError(VolleyError error) { fail("Volley Error!!"); } }); lock.await(20000, TimeUnit.MILLISECONDS); }
Example #30
Source File: BasicNetwork.java From android_tv_metro with Apache License 2.0 | 5 votes |
/** * Attempts to prepare the request for a retry. If there are no more attempts remaining in the * request's retry policy, a timeout exception is thrown. * @param request The request to use. */ private static void attemptRetryOnException(String logPrefix, Request<?> request, VolleyError exception) throws VolleyError { RetryPolicy retryPolicy = request.getRetryPolicy(); int oldTimeout = request.getTimeoutMs(); try { retryPolicy.retry(exception); } catch (VolleyError e) { request.addMarker( String.format("%s-timeout-giveup [timeout=%s]", logPrefix, oldTimeout)); throw e; } request.addMarker(String.format("%s-retry [timeout=%s]", logPrefix, oldTimeout)); }