Search code examples
javaandroidhttp-status-code-409

While calling a web service API, i'm getting HttpResponseException: Conflict


   RequestParams params = new RequestParams();

    params.put("mobile", mobile);
    params.put("is_online", "0");
    params.put("name", name);
    params.put("latitude", latitude);
    /*  */

    String GcmToken = FirebaseInstanceId.getInstance().getToken();
    if (GcmToken != null) {
        params.put("gcm_token", GcmToken);
    } else {
        params.put("gcm_token", gcm_token);
    }

    Server.post("user/register/format/json", params, new JsonHttpResponseHandler() {
        @Override
        public void onStart() {
            super.onStart();          
        }

        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            super.onSuccess(statusCode, headers, response);
            try {
                if (response.has("status") && response.getString("status").equalsIgnoreCase("success")) {
                    Log.d(TAG, response.toString());
                    sessionManager.setKEY(response.getJSONObject("data").getString("key"));
                    Toast.makeText(RegisterActivity.this, "success", Toast.LENGTH_LONG).show();
                    startActivity(new Intent(RegisterActivity.this, LoginActivity.class));

                    finish();
                } else {

                    Toast.makeText(RegisterActivity.this, response.getString("data"), Toast.LENGTH_LONG).show();

                }
            } catch (JSONException e) {
                Toast.makeText(RegisterActivity.this, getString(R.string.error_occurred), Toast.LENGTH_LONG).show();
            }
        }
        @Override
        public void onFinish() {
            super.onFinish();
        }
    });

When i run above code, i'm getting this type of exception message. I don't have any idea, why it is coming. However, i am able to run same code in different mobile and it is working. It seems that in some device the code is working fine but fails in other device.

onFailure(int, Header[], String, Throwable) was not overriden, but callback was received
cz.msebera.android.httpclient.client.HttpResponseException: Conflict
    at com.loopj.android.http.AsyncHttpResponseHandler.sendResponseMessage(AsyncHttpResponseHandler.java:446)
    at com.loopj.android.http.AsyncHttpRequest.makeRequest(AsyncHttpRequest.java:160)
    at com.loopj.android.http.AsyncHttpRequest.makeRequestWithRetries(AsyncHttpRequest.java:177)
    at com.loopj.android.http.AsyncHttpRequest.run(AsyncHttpRequest.java:106)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:457)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
    at java.lang.Thread.run(Thread.java:764)

I'm getting this exception only this api call, rest APIs of apps are able to call smoothly.


Solution

  • finally i got the issue, anyhow method name register was conflicting. I just renamed method name and it is working fine.