Java HTTP Client prints empty JSON

I run the following code:

CloseableHttpClient httpclient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet("http://10.0.0.22:8086/db/cadvisorDB/series?u=root&p=root&q=select%20max(memory_usage)%20from%20stats%20where%20container_name%20%3D%27execution_container_"+bench_list+"_"+i+"%27%20and%20memory_usage%20%3C%3E%200%20group%20by%20container_name");
//Thread.sleep(10000);
CloseableHttpResponse requestResponse = httpclient.execute(httpGet);
String response=EntityUtils.toString(requestResponse.getEntity());
System.out.println(response);

Output console:

[]

When I wait for the HttpResponse 30s, it works. I got the full answer (JSON with data points):

Thread.sleep(30000);

Is it possible, using the Apache Java client, to tell the client to wait for a value other than "[]" to be received. I do not mean empty Json.

Using timeouts does not solve the problem.

Thank you in advance

+4
source share
3 answers

Then setting the timeout will work.

HttpGet request = new HttpGet(url);

    // set timeouts as you like
    RequestConfig config = RequestConfig.custom()
            .setSocketTimeout(60 * 1000).setConnectTimeout(20 * 1000)
            .setConnectionRequestTimeout(20 * 1000).build();

    request.setConfig(config);
+1
source

, , HttpClient, , , , , . ( - .)

  • sleep() HttpClients.createDefault()?
  • , 10.0.0.22:8086 , ? ?
0

, , 2 Http- . Thread.sleep(2000) , .

, , ?

, Thread.sleep http.

0

Source: https://habr.com/ru/post/1620395/


All Articles