Java Code Examples for com.android.volley.Response#ErrorListener

The following examples show how to use com.android.volley.Response#ErrorListener . 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: ShopFragment.java    From android-kubernetes-blockchain with Apache License 2.0 6 votes vote down vote up
public void getStateOfUser(String userId, final int failedAttempts) {
    try {
        JSONObject params = new JSONObject("{\"type\":\"query\",\"queue\":\"user_queue\",\"params\":{\"userId\":\"" + userId + "\", \"fcn\":\"getState\", \"args\":[" + userId + "]}}");
        JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, BACKEND_URL + "/api/execute", params,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        InitialResultFromRabbit initialResultFromRabbit = gson.fromJson(response.toString(), InitialResultFromRabbit.class);
                        if (initialResultFromRabbit.status.equals("success")) {
                            getResultFromResultId("getStateOfUser",initialResultFromRabbit.resultId,0, failedAttempts);
                        } else {
                            Log.d(TAG, "Response is: " + response.toString());
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Log.d(TAG, "That didn't work!");
            }
        });
        queue.add(jsonObjectRequest);
    } catch (JSONException e) {
        e.printStackTrace();
    }
}
 
Example 2
Source File: UserFragment.java    From android-kubernetes-blockchain with Apache License 2.0 6 votes vote down vote up
public void sendStepsToMongo(String userId, int numberOfStepsToSend) {
    StringRequest stringRequest = new StringRequest(Request.Method.POST, BACKEND_URL + "/registerees/update/" + userId + "/steps/" + String.valueOf(numberOfStepsToSend),
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    Log.d(TAG, response);
                    Log.d(TAG, "Steps updated in mongo");
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.d(TAG, "That didn't work!");
        }
    });
    this.queue.add(stringRequest);
}
 
Example 3
Source File: PaymentService.java    From tgen with Apache License 2.0 5 votes vote down vote up
public static RpcRequest GetPaymentListByStatus(final String status, final int offset, final int limit, final Listener<ArrayList<TPaymentBillSummary>> listener) {
    RpcRequest req = new RpcRequest(Request.Method.POST, TRpc.getWebApiUrl() + "Payment/GetPaymentListByStatus",
        new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                try {
                    ArrayList<TPaymentBillSummary> result;
                    result = BaseModule.doFromJSONArray(response, TPaymentBillSummary.class);

                    listener.onResponse(result);
                } catch (Exception ex) {
                     
                    // Log.d("ex", ex.toString());
                    // Log.d("jsonObject", response);
                     
                    listener.onResponse(null);
                }
            }
        }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            listener.onResponse(null);
        }
    }) {
        @Override
        public byte[] getBody() {
            HashMap<String, Object> msg = new HashMap<String, Object>();
            msg.put("status", status);
            msg.put("offset", offset);
            msg.put("limit", limit);

            return gson.toJson(msg).getBytes(Charset.forName("UTF-8"));
        }
    };
    TRpc.getQueue().add(req);
    return req;
}
 
Example 4
Source File: PaymentService.java    From tgen with Apache License 2.0 5 votes vote down vote up
public static RpcRequest UserRenewPrime(final Listener<TPrimePaymentResult> listener) {
    RpcRequest req = new RpcRequest(Request.Method.POST, TRpc.getWebApiUrl() + "Payment/UserRenewPrime",
        new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                try {
                    TPrimePaymentResult result;
                    result = BaseModule.doFromJSON(response, TPrimePaymentResult.class);

                    listener.onResponse(result);
                } catch (Exception ex) {
                     
                    // Log.d("ex", ex.toString());
                    // Log.d("jsonObject", response);
                     
                    listener.onResponse(null);
                }
            }
        }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            listener.onResponse(null);
        }
    }) {
        @Override
        public byte[] getBody() {
            return "".getBytes(Charset.forName("UTF-8"));
        }
    };
    TRpc.getQueue().add(req);
    return req;
}
 
Example 5
Source File: PaymentService.java    From tgen with Apache License 2.0 5 votes vote down vote up
public static RpcRequest AddWithdrawReqeust(final String bankName, final String account, final double amount, final String reason, final Listener<String> listener) {
    RpcRequest req = new RpcRequest(Request.Method.POST, TRpc.getWebApiUrl() + "Payment/AddWithdrawReqeust",
        new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                try {
                    String result;
                    result = BaseModule.doFromJSON(response, String.class);

                    listener.onResponse(result);
                } catch (Exception ex) {
                     
                    // Log.d("ex", ex.toString());
                    // Log.d("jsonObject", response);
                     
                    listener.onResponse(null);
                }
            }
        }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            listener.onResponse(null);
        }
    }) {
        @Override
        public byte[] getBody() {
            HashMap<String, Object> msg = new HashMap<String, Object>();
            msg.put("bankName", bankName);
            msg.put("account", account);
            msg.put("amount", amount);
            msg.put("reason", reason);

            return gson.toJson(msg).getBytes(Charset.forName("UTF-8"));
        }
    };
    TRpc.getQueue().add(req);
    return req;
}
 
Example 6
Source File: PackageService.java    From tgen with Apache License 2.0 5 votes vote down vote up
public static RpcRequest GetInvoiceByPackageId(final int packageId, final Listener<TInvoice> listener) {
    RpcRequest req = new RpcRequest(Request.Method.POST, TRpc.getWebApiUrl() + "Package/GetInvoiceByPackageId",
        new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                try {
                    TInvoice result;
                    result = BaseModule.doFromJSON(response, TInvoice.class);

                    listener.onResponse(result);
                } catch (Exception ex) {
                     
                    // Log.d("ex", ex.toString());
                    // Log.d("jsonObject", response);
                     
                    listener.onResponse(null);
                }
            }
        }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            listener.onResponse(null);
        }
    }) {
        @Override
        public byte[] getBody() {
            HashMap<String, Object> msg = new HashMap<String, Object>();
            msg.put("packageId", packageId);

            return gson.toJson(msg).getBytes(Charset.forName("UTF-8"));
        }
    };
    TRpc.getQueue().add(req);
    return req;
}
 
Example 7
Source File: PackageService.java    From tgen with Apache License 2.0 5 votes vote down vote up
public static RpcRequest GetPackageSummary(final Listener<TPackageSummary> listener) {
    RpcRequest req = new RpcRequest(Request.Method.POST, TRpc.getJsonRpcUrl(),
        new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                try {
                    TPackageSummary result;
                    result = BaseModule.fromJSON(response, TPackageSummary.class);

                    listener.onResponse(result);
                } catch (Exception ex) {
                     
                    // Log.d("ex", ex.toString());
                    // Log.d("jsonObject", response);
                     
                    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<>();

            HashMap<String, Object> msg = new HashMap<>();
            msg.put("id", getMsgID());
            msg.put("method", "Package.GetPackageSummary");
            msg.put("params", params);

            return gson.toJson(msg).getBytes(Charset.forName("UTF-8"));
        }
    };
    TRpc.getQueue().add(req);
    return req;
}
 
Example 8
Source File: ShipfForMeService.java    From tgen with Apache License 2.0 5 votes vote down vote up
public static RpcRequest UserDeleteShipForMeOrder(final int orderId, 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(orderId);

            HashMap<String, Object> msg = new HashMap<>();
            msg.put("id", getMsgID());
            msg.put("method", "ShipfForMe.UserDeleteShipForMeOrder");
            msg.put("params", params);

            return gson.toJson(msg).getBytes(Charset.forName("UTF-8"));
        }
    };
    TRpc.getQueue().add(req);
    return req;
}
 
Example 9
Source File: ShipfForMeService.java    From tgen with Apache License 2.0 5 votes vote down vote up
public static RpcRequest UserGetShipForMeAddressByRegion(final String originCode, final Listener<ArrayList<TShipformeAddress>> listener) {
    RpcRequest req = new RpcRequest(Request.Method.POST, TRpc.getWebApiUrl() + "ShipfForMe/UserGetShipForMeAddressByRegion",
        new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                try {
                    ArrayList<TShipformeAddress> result;
                    result = BaseModule.doFromJSONArray(response, TShipformeAddress.class);

                    listener.onResponse(result);
                } catch (Exception ex) {
                     
                    // Log.d("ex", ex.toString());
                    // Log.d("jsonObject", response);
                     
                    listener.onResponse(null);
                }
            }
        }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            listener.onResponse(null);
        }
    }) {
        @Override
        public byte[] getBody() {
            HashMap<String, Object> msg = new HashMap<String, Object>();
            msg.put("originCode", originCode);

            return gson.toJson(msg).getBytes(Charset.forName("UTF-8"));
        }
    };
    TRpc.getQueue().add(req);
    return req;
}
 
Example 10
Source File: QuantitySelection.java    From android-kubernetes-blockchain with Apache License 2.0 5 votes vote down vote up
public void purchaseItem() {
    try {
        JSONObject params = new JSONObject("{\"type\":\"invoke\",\"queue\":\"user_queue\",\"params\":{\"userId\":\"" + userId + "\", \"fcn\":\"makePurchase\", \"args\":[" + userId + "," + product.getSellerId() + "," + product.getProductId() + ",\"" + quantity.getText() + "\"]}}");
        Log.d(TAG, params.toString());
        JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, BACKEND_URL + "/api/execute", params,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        InitialResultFromRabbit initialResultFromRabbit = gson.fromJson(response.toString(), InitialResultFromRabbit.class);
                        if (initialResultFromRabbit.status.equals("success")) {
                            Log.d(TAG, response.toString());
                            getTransactionResult(initialResultFromRabbit.resultId,0);
                        } else {
                            Log.d(TAG, "Response is: " + response.toString());
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Log.d(TAG, "That didn't work!");
            }
        });
        queue.add(jsonObjectRequest);
    } catch (JSONException e) {
        e.printStackTrace();
    }
}
 
Example 11
Source File: CartFragment.java    From openshop.io-android with MIT License 5 votes vote down vote up
private void getCartContent() {
    User user = SettingsMy.getActiveUser();
    if (user != null) {
        String url = String.format(EndPoints.CART, SettingsMy.getActualNonNullShop(getActivity()).getId());

        progressDialog.show();
        GsonRequest<Cart> getCart = new GsonRequest<>(Request.Method.GET, url, null, Cart.class,
                new Response.Listener<Cart>() {
                    @Override
                    public void onResponse(@NonNull Cart cart) {
                        if (progressDialog != null) progressDialog.cancel();

                        MainActivity.updateCartCountNotification();
                        if (cart.getItems() == null || cart.getItems().size() == 0) {
                            setCartVisibility(false);
                        } else {
                            setCartVisibility(true);
                            cartRecyclerAdapter.refreshItems(cart);

                            cartItemCountTv.setText(getString(R.string.format_quantity, cart.getProductCount()));
                            cartTotalPriceTv.setText(cart.getTotalPriceFormatted());
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                if (progressDialog != null) progressDialog.cancel();
                setCartVisibility(false);
                Timber.e("Get request cart error: %s", error.getMessage());
                MsgUtils.logAndShowErrorMessage(getActivity(), error);
            }
        }, getFragmentManager(), user.getAccessToken());
        getCart.setRetryPolicy(MyApplication.getDefaultRetryPolice());
        getCart.setShouldCache(false);
        MyApplication.getInstance().addToRequestQueue(getCart, CONST.CART_REQUESTS_TAG);
    } else {
        LoginExpiredDialogFragment loginExpiredDialogFragment = new LoginExpiredDialogFragment();
        loginExpiredDialogFragment.show(getFragmentManager(), "loginExpiredDialogFragment");
    }
}
 
Example 12
Source File: ShipfForMeService.java    From tgen with Apache License 2.0 5 votes vote down vote up
public static RpcRequest UserGetShipForMeOrderListByStatus(final String originCode, final String warehouseCode, final String status, final int offset, final int limit, final Listener<ArrayList<TShipForMeOrder>> listener) {
    RpcRequest req = new RpcRequest(Request.Method.POST, TRpc.getWebApiUrl() + "ShipfForMe/UserGetShipForMeOrderListByStatus",
        new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                try {
                    ArrayList<TShipForMeOrder> result;
                    result = BaseModule.doFromJSONArray(response, TShipForMeOrder.class);

                    listener.onResponse(result);
                } catch (Exception ex) {
                     
                    // Log.d("ex", ex.toString());
                    // Log.d("jsonObject", response);
                     
                    listener.onResponse(null);
                }
            }
        }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            listener.onResponse(null);
        }
    }) {
        @Override
        public byte[] getBody() {
            HashMap<String, Object> msg = new HashMap<String, Object>();
            msg.put("originCode", originCode);
            msg.put("warehouseCode", warehouseCode);
            msg.put("status", status);
            msg.put("offset", offset);
            msg.put("limit", limit);

            return gson.toJson(msg).getBytes(Charset.forName("UTF-8"));
        }
    };
    TRpc.getQueue().add(req);
    return req;
}
 
Example 13
Source File: MainActivity.java    From pearl with Apache License 2.0 4 votes vote down vote up
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    img = (ImageView) findViewById(R.id.img);

    back = (ImageView) findViewById(R.id.background);

    btn = (Button) findViewById(R.id.button);
    arr = new ArrayList<String>();

    //Initialized with key "mind"
    JsonArrayRequest req = new JsonArrayRequest(urlString,
            new Response.Listener<JSONArray>() {
                @Override
                public void onResponse(JSONArray response) {
                    Log.d("MAIN", response.toString());

                    try {
                        // Parsing json array response
                        // loop through each json object
                        //jsonResponse = "";
                        for (int i = 0; i < response.length(); i++) {

                            JSONObject person = (JSONObject) response
                                    .get(i);
                            Pearl.saveJsonObject(MainActivity.this, "serializable",""+i+"tag");

                            String name = person.getString("id");
                            String email = person.getString("height");
                            Log.d("MAINE"," "+name+" email " + email);
                            JSONObject mass = person.getJSONObject("user");
                            JSONObject spehe = mass.getJSONObject("profile_image");

                            arr.add(spehe.getString("large"));

                        }


                    } catch (JSONException e) {
                        e.printStackTrace();
                        Toast.makeText(getApplicationContext(),
                                "Error: " + e.getMessage(),
                                Toast.LENGTH_LONG).show();
                    }

                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            // VolleyLog.d(TAG, "Error: " + error.getMessage());
            Toast.makeText(getApplicationContext(),
                    error.getMessage(), Toast.LENGTH_SHORT).show();
        }
    });

    // Adding request to request queue
    Volley.newRequestQueue(MainActivity.this).add(req);
    btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            Intent nextAct = new Intent(MainActivity.this, com.hanuor.pearl_demonstration.DisplayActivity.class);
            nextAct.putStringArrayListExtra("list",arr);
            startActivity(nextAct);
        }
    });
}
 
Example 14
Source File: TestRequest.java    From SaveVolley with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("deprecation") public Base(String url, Response.ErrorListener listener) {
    super(url, listener);
}
 
Example 15
Source File: NewsActivity.java    From QuickNews with MIT License 4 votes vote down vote up
public JsonObjectRequest getCommentsData(String baseUrl, String parameter1, String parameter2 ,
                                         final ListView listView){
    String url=baseUrl+"comments/?count=10&page="+parameter1+"&offset="+parameter2
            +"&item_id=0&format=json";
    System.out.println("访问的Url为"+url);

    JsonObjectRequest jsonObjectRequest=new JsonObjectRequest(url.trim(), null,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    try{
                        System.out.println("Volley得到的response是+"+response.toString());
                        Gson gson = new Gson();

                        CommentsData commentsData= gson.fromJson(response.toString(),new TypeToken<CommentsData>(){}.getType());
                        List<Comment> commentList=new ArrayList<>();
                        if (commentsData.getMessage().equals("success")){
                            commentList=commentsData.getData().getComments();
                            System.out.println("当前获取的commentList是"+commentList.size());
                            if (commentList.size()>0) {
                                mCommentList.addAll(commentList);
                            }else {
                                mIsLastRow=false;
                                mTextViewMore.setText("已没有更多评论");
                            }
                        }else {
                            mIsLastRow=false;
                            mTextViewMore.setText("已没有更多评论");

                        }

                        CommentsAdapter adapter=new CommentsAdapter(NewsActivity.this,
                                mCommentList,mRequestQueue);
                        if (mCommentList.size()>10){
                            listView.removeFooterView(mLlFooterView);
                        }
                        listView.addFooterView(mLlFooterView);

                        listView.setAdapter(adapter);
                        adapter.notifyDataSetChanged();


                    }catch (Exception e){
                        e.printStackTrace();
                    }

                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            System.out.println("获取信息失败……");
            System.out.println("error是"+error.toString());
            mIsLastRow=false;
            mTextViewMore.setText("已没有更多评论");
            listView.addFooterView(mLlFooterView);
        }
    });

    System.out.println("jsonObjectRequest"+jsonObjectRequest.toString());
    return jsonObjectRequest;
}
 
Example 16
Source File: HttpClient.java    From android-instagram-connector with Apache License 2.0 4 votes vote down vote up
/**
 * Start http request
 */
public void execute(final HttpCallback callback) {

    int intMethod = Request.Method.GET;
    switch (mMethod) {
        case GET:
            intMethod = Request.Method.GET;
            break;

        case POST:
            intMethod = Request.Method.POST;
            break;

        case DELETE:
            intMethod = Request.Method.DELETE;
            break;

        case PUT:
            intMethod = Request.Method.PUT;
            break;

        case HEAD:
            intMethod = Request.Method.HEAD;
            break;
    }

    final HttpRequest stringRequest = new HttpRequest(intMethod, mUrl, mBody, new Response.Listener<HttpResponse>() {
        @Override
        public void onResponse(HttpResponse response) {

            String body = "";
            try {
                body = new String(response.getBody(), "UTF-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            Log.d(TAG, "Response: " + ((response.getBody() != null) ? body : ""));
            callback.onResponse(body, 200);
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            callback.onFail(500);
        }
    });

    stringRequest.setTag(TAG);

    this.mRequestQueue.add(stringRequest);
}
 
Example 17
Source File: OrderService.java    From tgen with Apache License 2.0 4 votes vote down vote up
public static RpcRequest GetOrderListByStatus(final String originCode, final String orderStatus, final String warehouseCode, final Listener<ArrayList<TOrder>> listener) {
    RpcRequest req = new RpcRequest(Request.Method.POST, TRpc.getJsonRpcUrl(),
        new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                try {
                    ArrayList<TOrder> result;
                    result = BaseModule.fromJSONArray(response, TOrder.class);

                    listener.onResponse(result);
                } catch (Exception ex) {
                     
                    // Log.d("ex", ex.toString());
                    // Log.d("jsonObject", response);
                     
                    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(originCode);
            params.add(orderStatus);
            params.add(warehouseCode);

            HashMap<String, Object> msg = new HashMap<>();
            msg.put("id", getMsgID());
            msg.put("method", "Order.GetOrderListByStatus");
            msg.put("params", params);

            return gson.toJson(msg).getBytes(Charset.forName("UTF-8"));
        }
    };
    TRpc.getQueue().add(req);
    return req;
}
 
Example 18
Source File: GetChromium.java    From getChromium with GNU General Public License v3.0 4 votes vote down vote up
private void downloadLatest() {

        // Instantiate the cache
        Cache cache = new DiskBasedCache(getCacheDir(), 1024 * 1024); // 1MB cap

        // Set up the network to use HttpURLConnection as the HTTP client.
        com.android.volley.Network network = new BasicNetwork(new HurlStack());

        // Instantiate the RequestQueue with the cache and network.
        mRequestQueue = new RequestQueue(cache, network);
        mRequestQueue.start();

        // Request a string response from "https://commondatastorage.googleapis.com/chromium-browser-snapshots/Android/LAST_CHANGE"
        // The response provides the current build number of Chromium's latest build
        String urlL = "https://commondatastorage.googleapis.com/chromium-browser-snapshots/Android/LAST_CHANGE";
        final StringRequest stringRequest = new StringRequest(Request.Method.GET, urlL,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {

                        // Build new String for the current APK download URL
                        Uri.Builder builder = new Uri.Builder();
                        builder.scheme("https")
                                .authority("commondatastorage.googleapis.com")
                                .appendPath("chromium-browser-snapshots")
                                .appendPath("Android")
                                .appendPath(response) // Build revision number
                                .appendPath("chrome-android.zip"); // Name of the file that will contain the APKs.
                        String apkUrl = builder.build().toString();
                        new DownloadTask().execute(apkUrl);
                    }
                },

                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                    }
                });

        // Add the request to the RequestQueue.
        mRequestQueue.add(stringRequest);
    }
 
Example 19
Source File: SlingApi.java    From swagger-aem with Apache License 2.0 4 votes vote down vote up
/**
 * 
 * 
 * @param allowEmpty    * @param allowEmptyTypeHint    * @param allowHosts    * @param allowHostsTypeHint    * @param allowHostsRegexp    * @param allowHostsRegexpTypeHint    * @param filterMethods    * @param filterMethodsTypeHint 
*/
public void postConfigApacheSlingReferrerFilter (Boolean allowEmpty, String allowEmptyTypeHint, String allowHosts, String allowHostsTypeHint, String allowHostsRegexp, String allowHostsRegexpTypeHint, String filterMethods, String filterMethodsTypeHint, final Response.Listener<String> responseListener, final Response.ErrorListener errorListener) {
  Object postBody = null;


  // create path and map variables
  String path = "/apps/system/config/org.apache.sling.security.impl.ReferrerFilter".replaceAll("\\{format\\}","json");

  // query params
  List<Pair> queryParams = new ArrayList<Pair>();
  // header params
  Map<String, String> headerParams = new HashMap<String, String>();
  // form params
  Map<String, String> formParams = new HashMap<String, String>();

  queryParams.addAll(ApiInvoker.parameterToPairs("", "allow.empty", allowEmpty));
  queryParams.addAll(ApiInvoker.parameterToPairs("", "allow.empty@TypeHint", allowEmptyTypeHint));
  queryParams.addAll(ApiInvoker.parameterToPairs("", "allow.hosts", allowHosts));
  queryParams.addAll(ApiInvoker.parameterToPairs("", "allow.hosts@TypeHint", allowHostsTypeHint));
  queryParams.addAll(ApiInvoker.parameterToPairs("", "allow.hosts.regexp", allowHostsRegexp));
  queryParams.addAll(ApiInvoker.parameterToPairs("", "allow.hosts.regexp@TypeHint", allowHostsRegexpTypeHint));
  queryParams.addAll(ApiInvoker.parameterToPairs("", "filter.methods", filterMethods));
  queryParams.addAll(ApiInvoker.parameterToPairs("", "filter.methods@TypeHint", filterMethodsTypeHint));


  String[] contentTypes = {
    
  };
  String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";

  if (contentType.startsWith("multipart/form-data")) {
    // file uploading
    MultipartEntityBuilder localVarBuilder = MultipartEntityBuilder.create();
    

    HttpEntity httpEntity = localVarBuilder.build();
    postBody = httpEntity;
  } else {
    // normal form params
        }

  String[] authNames = new String[] { "aemAuth" };

  try {
    apiInvoker.invokeAPI(basePath, path, "POST", queryParams, postBody, headerParams, formParams, contentType, authNames,
      new Response.Listener<String>() {
        @Override
        public void onResponse(String localVarResponse) {
            responseListener.onResponse(localVarResponse);
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
          errorListener.onErrorResponse(error);
        }
    });
  } catch (ApiException ex) {
    errorListener.onErrorResponse(new VolleyError(ex));
  }
}
 
Example 20
Source File: Facts.java    From Crimson with Apache License 2.0 3 votes vote down vote up
private void getFactDetails() {

        String url = "http://webianks.com/crimson/all_facts.json";

        VolleySingleton volleySingleton = VolleySingleton.getInstance();
        RequestQueue requestQueue = volleySingleton.getRequestQueue();

        JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET,
                url, null, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {

                //got the response

                parseFacts(response);

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

                try {
                    Toast.makeText(getActivity(),"Can't fetch facts.",Toast.LENGTH_SHORT).show();
                } catch (Exception e) {
                    e.printStackTrace();
                }

            }
        });

        requestQueue.add(jsonObjectRequest);


    }