JSON-запрос с использованием Android Volley всегда тайм-аут

Это GIST IAM, ссылающийся на получение изображений с сервера https://gist.github.com/anggadarkprince/a7c536da091f4b26bb4abf2f92926594

Вот JSON IAM пытается разобрать

images:[
   {
      "id":"1",
      "folder_name":"files",
      "file_name":"logo-1.png",
      "url":"http:\/\/ascentcity.com\/Mobileapp\/files\/logo-1.png"
   },
   {
      "id":"2",
      "folder_name":"files",
      "file_name":"280917052734",
      "url":"http:\/\/ascentcity.com\/Mobileapp\/280917052734files\/"
   },
   {
      "id":"3",
      "folder_name":"files",
      "file_name":"280917052822",
      "url":"http:\/\/ascentcity.com\/Mobileapp\/280917052822files\/"
   },
   {
      "id":"4",
      "folder_name":"files",
      "file_name":"280917053829",
      "url":"http:\/\/ascentcity.com\/Mobileapp\/280917053829files\/"
   },
   {
      "id":"5",
      "folder_name":"files",
      "file_name":"280917053908",
      "url":"http:\/\/ascentcity.com\/Mobileapp\/280917053908files\/"
   },
   {
      "id":"6",
      "folder_name":"files",
      "file_name":"280917053942",
      "url":"http:\/\/ascentcity.com\/Mobileapp\/280917053942files\/"
   },
   {
      "id":"7",
      "folder_name":"files",
      "file_name":"280917054020",
      "url":"http:\/\/ascentcity.com\/Mobileapp\/280917054020files\/"
   },
   {
      "id":"8",
      "folder_name":"files",
      "file_name":"",
      "url":"http:\/\/ascentcity.com\/Mobileapp\/files\/"
   },
   {
      "id":"9",
      "folder_name":"files",
      "file_name":"",
      "url":"http:\/\/ascentcity.com\/Mobileapp\/files\/"
   },
   {
      "id":"10",
      "folder_name":"files",
      "file_name":"",
      "url":"http:\/\/ascentcity.com\/Mobileapp\/files\/"
   },
   {
      "id":"11",
      "folder_name":"files",
      "file_name":"",
      "url":"http:\/\/ascentcity.com\/Mobileapp\/files\/"
   },
   {
      "id":"12",
      "folder_name":"files",
      "file_name":"",
      "url":"http:\/\/ascentcity.com\/Mobileapp\/files\/"
   },
   {
      "id":"13",
      "folder_name":"files",
      "file_name":"1.jpg",
      "url":"http:\/\/ascentcity.com\/Mobileapp\/files\/1.jpg"
   },
   {
      "id":"14",
      "folder_name":"files",
      "file_name":"1.jpg",
      "url":"http:\/\/ascentcity.com\/Mobileapp\/files\/1.jpg"
   },
   {
      "id":"15",
      "folder_name":"files",
      "file_name":"",
      "url":"http:\/\/ascentcity.com\/Mobileapp\/files\/"
   },
   {
      "id":"16",
      "folder_name":"files",
      "file_name":"",
      "url":"http:\/\/ascentcity.com\/Mobileapp\/files\/"
   },
   {
      "id":"17",
      "folder_name":"files",
      "file_name":"",
      "url":"http:\/\/ascentcity.com\/Mobileapp\/files\/"
   },
   {
      "id":"18",
      "folder_name":"files",
      "file_name":"",
      "url":"http:\/\/ascentcity.com\/Mobileapp\/files\/"
   },
   {
      "id":"19",
      "folder_name":"files",
      "file_name":"",
      "url":"http:\/\/ascentcity.com\/Mobileapp\/files\/"
   },
   {
      "id":"20",
      "folder_name":"files",
      "file_name":"",
      "url":"http:\/\/ascentcity.com\/Mobileapp\/files\/"
   },
   {
      "id":"21",
      "folder_name":"files",
      "file_name":"",
      "url":"http:\/\/ascentcity.com\/Mobileapp\/files\/"
   },
   {
      "id":"22",
      "folder_name":"files",
      "file_name":"",
      "url":"http:\/\/ascentcity.com\/Mobileapp\/files\/"
   },
   {
      "id":"23",
      "folder_name":"files",
      "file_name":"",
      "url":"http:\/\/ascentcity.com\/Mobileapp\/files\/"
   },
   {
      "id":"24",
      "folder_name":"files",
      "file_name":"",
      "url":"http:\/\/ascentcity.com\/Mobileapp\/files\/"
   },
   {
      "id":"25",
      "folder_name":"files",
      "file_name":"",
      "url":"http:\/\/ascentcity.com\/Mobileapp\/files\/"
   },
   {
      "id":"26",
      "folder_name":"files",
      "file_name":"",
      "url":"http:\/\/ascentcity.com\/Mobileapp\/files\/"
   },
   {
      "id":"27",
      "folder_name":"files",
      "file_name":"",
      "url":"http:\/\/ascentcity.com\/Mobileapp\/files\/"
   },
   {
      "id":"28",
      "folder_name":"files",
      "file_name":"",
      "url":"http:\/\/ascentcity.com\/Mobileapp\/files\/"
   },
   {
      "id":"29",
      "folder_name":"files",
      "file_name":"",
      "url":"http:\/\/ascentcity.com\/Mobileapp\/files\/"
   },
   {
      "id":"30",
      "folder_name":"files",
      "file_name":"",
      "url":"http:\/\/ascentcity.com\/Mobileapp\/files\/"
   },
   {
      "id":"31",
      "folder_name":"files",
      "file_name":"",
      "url":"http:\/\/ascentcity.com\/Mobileapp\/files\/"
   },
   {
      "id":"32",
      "folder_name":"files",
      "file_name":"",
      "url":"http:\/\/ascentcity.com\/Mobileapp\/files\/"
   },
   {
      "id":"33",
      "folder_name":"files",
      "file_name":"",
      "url":"http:\/\/ascentcity.com\/Mobileapp\/files\/"
   },
   {
      "id":"34",
      "folder_name":"files",
      "file_name":"",
      "url":"http:\/\/ascentcity.com\/Mobileapp\/files\/"
   }
]

Вот мой код

public class ServerActivity extends AppCompatActivity
    implements NavigationView.OnNavigationItemSelectedListener {

//GridView Object
private GridView gridView;

//ArrayList for Storing image urls and titles
private ArrayList<String> ids;
private ArrayList<String> folder_names;
private ArrayList<String> file_names;
private ArrayList<String> urls;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_server);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view_server);
    navigationView.setNavigationItemSelectedListener(this);

    gridView = (GridView) findViewById(R.id.gv_images);

    ids = new ArrayList<>();
    folder_names = new ArrayList<>();
    file_names = new ArrayList<>();
    urls = new ArrayList<>();

    getData();
}

@Override
public void onBackPressed() {
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else {
        super.onBackPressed();
    }
}

@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);

    if (id == R.id.nav_upload) {
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
    } else if (id == R.id.nav_view_image) {
        drawer.closeDrawer(GravityCompat.START);
    } else if (id == R.id.nav_download) {
        Intent intent = new Intent(this, DownloadActivity.class);
        startActivity(intent);
    } else if (id == R.id.nav_share) {
        Toast.makeText(this, "Share to SocialMedia is [WIP]\n",
                Toast.LENGTH_SHORT).show();
    } else if (id == R.id.nav_about) {
        Toast.makeText(this, "About Screen is [WIP]\n",
                Toast.LENGTH_SHORT).show();
    }

    drawer.closeDrawer(GravityCompat.START);
    return true;
}

private void getData(){
    //Showing a progress dialog while our app fetches the data from url
    final ProgressDialog loading = ProgressDialog.show(this, "Please wait...","Fetching data...",false,false);

    //Creating a json array request to get the json from our api
    JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Constants.IMAGES_URL,
            new Response.Listener<JSONArray>() {
                @Override
                public void onResponse(JSONArray response) {
                    //Dismissing the progressdialog on response
                    loading.dismiss();

                    //Displaying our grid
                    showGrid(response);
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {

                }
            }
    );

    //Creating a request queue
    RequestQueue requestQueue = Volley.newRequestQueue(this);
    //Adding our request to the queue
    requestQueue.add(jsonArrayRequest);

    jsonArrayRequest.setRetryPolicy(new DefaultRetryPolicy(
            5000,
            5,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
}

private void showGrid(JSONArray jsonArray){
    //Looping through all the elements of json array
    for(int i = 0; i<jsonArray.length(); i++){
        //Creating a json object of the current index
        JSONObject obj = null;
        try {
            //getting json object from current index
            obj = jsonArray.getJSONObject(i);

            //getting image url and title from json object
            ids.add(obj.getString(TAG_ID));
            folder_names.add(obj.getString(Constants.TAG_FOLDER_NAME));
            file_names.add(obj.getString(Constants.TAG_FILE_NAME));
            urls.add(obj.getString(Constants.TAG_URL));
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    //Creating GridViewAdapter Object
    GridViewAdapter gridViewAdapter = new GridViewAdapter(this,ids,folder_names,file_names,urls);

    //Adding adapter to gridview
    gridView.setAdapter(gridViewAdapter);
    }
}

Вот ссылка для завершения проекта https://github.com/sooorajjj/vstImageClassifier

Ошибка, я получаю в LogCat

DpmTcmClient: RegisterTcmMonitor from: 

com.android.okhttp.TcmIdleTimerMonitor
System.out: [socket]rx timeout:2500
System.out: [socket][0] connection ascentcity.com/119.81.195.196:80;LocalPort=44602(2500)
System.out: [CDS]connect[ascentcity.com/119.81.195.196:80] tm:2
Posix: [Posix_connect Debug]Process com.vst.image.vehiclestimageclassifier :80 
art: Explicit concurrent mark sweep GC freed 1815(118KB) AllocSpace objects, 0(0B) LOS objects, 72% free, 2MB/10MB, paused 663us total 31.382ms
System.out: [socket][/192.168.31.42:44602] connected
System.out: [socket]rx timeout:2500
  1. Ошибка, с которой я сталкиваюсь, происходит из-за медленного сервера? или что-то другое? как это отладить?
  2. Есть ли что-то, что мне нужно сообщить бэкэнд-команде (на стороне сервера), я имею в виду обработать мой запрос.

Спасибо

0 ответов

Другие вопросы по тегам