Android ConnectTimeoutException is coming often

178 views Asked by At

I'm trying to create an mobile application in which was all the webservices where working properly untill friday night. But now when I'm checking now each and every JSON which I'm calling throws ConnectTimeoutException. These JSON's working perfectly last week and I didn't do any change in my code. Here's my Log for your reference:

  08-24 12:22:36.270: W/System.err(32545): org.apache.http.conn.ConnectTimeoutException: Connect to /54.193.42.98:80 timed out
08-24 12:22:36.274: W/System.err(32545):    at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:121)
08-24 12:22:36.279: W/System.err(32545):    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144)
08-24 12:22:36.280: W/System.err(32545):    at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
08-24 12:22:36.281: W/System.err(32545):    at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
08-24 12:22:36.283: W/System.err(32545):    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:374)
08-24 12:22:36.288: W/System.err(32545):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:575)
08-24 12:22:36.289: W/System.err(32545):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:498)
08-24 12:22:36.293: W/System.err(32545):    at com.loopj.android.http.AsyncHttpRequest.makeRequest(AsyncHttpRequest.java:76)
08-24 12:22:36.293: W/System.err(32545):    at com.loopj.android.http.AsyncHttpRequest.makeRequestWithRetries(AsyncHttpRequest.java:95)
08-24 12:22:36.294: W/System.err(32545):    at com.loopj.android.http.AsyncHttpRequest.run(AsyncHttpRequest.java:57)
08-24 12:22:36.294: W/System.err(32545):    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
08-24 12:22:36.295: W/System.err(32545):    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
08-24 12:22:36.295: W/System.err(32545):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
08-24 12:22:36.296: W/System.err(32545):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
08-24 12:22:36.297: W/System.err(32545):    at java.lang.Thread.run(Thread.java:841)

When I check in the backend I could see that there is no request is sent to the server. Can you please help me solving this issue. Here's my code to for calling a webservice for your reference:

private void RecommendedCategories_WS() {
    // TODO Auto-generated method stub
    Log.i("FavouritesList_WS",
            "FavouritesList_WS: "
                    + "http://beta.teambv.us/mobile/services/json/RecomondedCategories.json/1877746/100@0");

    Data1.loading_box(Download.this, "");

    AsyncHttpClient client = new AsyncHttpClient();
    RequestParams params = new RequestParams();
    client.get(
            "http://beta.teambv.us/mobile/services/json/RecomondedCategories.json/1877746/100@0",
            new AsyncHttpResponseHandler() {

                @Override
                public void onSuccess(String response) {
                    // TODO Auto-generated method stub
                    Log.i("RecommendedCategories_WS",
                            "RecommendedCategories_WS: " + response);
                    recommendedCategories = new ArrayList<QQ_RecommendedCategoriesList>();

                    try {
                        JSONObject jsonObject = new JSONObject(response);

                        JSONObject jobJsonObj = jsonObject
                                .getJSONObject("mobile");

                        JSONArray jsonArray = jobJsonObj
                                .getJSONArray("recomondedList");

                        Log.i("length", "length: " + jsonArray.length());

                        if (jsonArray.length() == 0) {

                        } else {
                            for (int i = 0; i < jsonArray.length(); i++) {
                                JSONObject details = jsonArray
                                        .getJSONObject(i);
                                String recomndedType = details
                                        .getString("recomndedType");
                                String recomondedName = details
                                        .getString("recomondedName");
                                int recomondedId = details
                                        .getInt("recomondedId");

                                recommendedCategories
                                        .add(new QQ_RecommendedCategoriesList(
                                                recomndedType,
                                                recomondedName,
                                                recomondedId));
                            }
                            sellMethod();
                            Data1.loading_box_stop();
                        }

                    } catch (JSONException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }

                @Override
                public void onFailure(Throwable arg0) {
                    // TODO Auto-generated method stub

                }

            });
}
1

There are 1 answers

0
QAMAR On

Try increasing timeout using

org.asynchttpclient.connectTimeout=5000 in api/src/main/resources/ahc-default.properties ref

https://github.com/AsyncHttpClient/async-http-client/search?utf8=%E2%9C%93&q=timeout&type=Code