sven0379
sven0379

Reputation: 11

Response of an Http request not contain the whole data

I send a http POST request to an azure timeseries insights by using the standard Spring Boot weblient.

Inside the response body I miss values.

Environment:

Here are my steps:

I try this with the spring boot webclient

final ResponseEntity<String> responseEntity = webClient.post()
                                                       .uri(tsiUrl)
                                                       .header(HttpHeaders.AUTHORIZATION, "Bearer " + token)
                                                       .contentType(MediaType.APPLICATION_JSON)
                                                       .bodyValue(requestBody)
                                                       .retrieve()
                                                       .toEntity(String.class)
                                                       .block();
return responseEntity != null ? responseEntity.getBody() : null;

and this with OkHttpClient (to verify the response, but I get the same reponse content)

public class App 
{
    public static final okhttp3.MediaType JSON = okhttp3.MediaType.get("application/json; charset=utf-8");

    public static void main( String[] args )
    {
        String requestBody = "{\n"
                      + "    \"aggregateSeries\": {\n"
                      + "        \"searchSpan\": {\n"
                      + "            \"from\": \"2021-01-01T00:00Z\",\n"
                      + "            \"to\": \"2021-12-31T00:00:01Z\"\n"
                      + "        },\n"
                      + "        \"timeSeriesId\": [\n"
                      + "            \"edge-goldwind-qa-002-astraios\",\n"
                      + "            \"GcmProcessed\"\n"
                      + "        ],\n"
                      + "        \"interval\": \"P1D\",\n"
                      + "        \"inlineVariables\": {\n"
                      + "            \"gcm01DeteriorationMax\": {\n"
                      + "             \"kind\": \"numeric\",\n"
                      + "             \"value\": {\n"
                      + "                  \"tsx\": \"$event.GCM01Deterioration.Double\"\n"
                      + "              },\n"
                      + "              \"filter\": null,\n"
                      + "              \"aggregation\": {\n"
                      + "                  \"tsx\": \"max($value)\"\n"
                      + "              }\n"
                      + "          },\"gcm01TemperatureOpticsMax\": {\n"
                      + "             \"kind\": \"numeric\",\n"
                      + "             \"value\": {\n"
                      + "                  \"tsx\": \"$event.GCM01TemperatureOptics.Long\"\n"
                      + "              },\n"
                      + "              \"filter\": null,\n"
                      + "              \"aggregation\": {\n"
                      + "                  \"tsx\": \"max($value)\"\n"
                      + "              }\n"
                      + "          }\n"
                      + "        },\n"
                      + "        \"projectedVariables\": [\n"
                      + "            \"gcm01DeteriorationMax\",\n"
                      + "            \"gcm01TemperatureOpticsMax\"\n"
                      + "        ]\n"
                      + "    }\n"
                      + "}";

        String token = "bearertoken"; //removed original bearer token


        try {
            OkHttpClient client = new OkHttpClient();
            Request request = new Request.Builder()
                    .header("Authorization", "Bearer " + token)
                    .url("https://1ff924d7-55b5-48c7-8c29-7fcbc18b8776.env.timeseries.azure.cn/timeseries/query?api-version=2020-07-31&storeType=WarmStore")
                    .post(RequestBody.create(requestBody, JSON))
                    .build();
            Response response = client.newCall(request).execute();
            final ResponseBody body = response.body();
            final String string = body.string();
        } catch (Exception e) {
            e.fillInStackTrace();
        }
    }
}

and I send this POST body:

{
    "aggregateSeries": {
        "searchSpan": {
            "from": "2021-01-01T00:00Z",
            "to": "2021-12-31T00:00:01Z"
        },
        "timeSeriesId": [
            "edge-goldwind-qa-002-astraios",
            "GcmProcessed"
        ],
        "interval": "P1D",
        "inlineVariables": {
            "gcm01DeteriorationMax": {
             "kind": "numeric",
             "value": {
                  "tsx": "$event.GCM01Deterioration.Double"
              },
              "filter": null,
              "aggregation": {
                  "tsx": "max($value)"
              }
          },"gcm01TemperatureOpticsMax": {
             "kind": "numeric",
             "value": {
                  "tsx": "$event.GCM01TemperatureOptics.Long"
              },
              "filter": null,
              "aggregation": {
                  "tsx": "max($value)"
              }
          }
        },
        "projectedVariables": [
            "gcm01DeteriorationMax",
            "gcm01TemperatureOpticsMax"
        ]
    }
}

The result of the Spring Boot webclient and OkHttpClient (not expected)

{"values":[null,..,null,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,null,...,null],"name":"gcm01DeteriorationMax","type":"Double"}

(I removed all the null values, to see the differences simple)

But if I send the same POST with Postman I get this result (expected):

{"values":[null,..,null,69.209999084472656,95.569999694824219,87.209999084472656,90.419998168945313,89.419998168945313,65.120002746582031,73.19000244140625,75.6500015258789,77.44000244140625,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,null,null,null,null,null,null,null,null,null,100.0,100.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,null,..,null],"name":"gcm01DeteriorationMax","type":"Double"}

As you can see the result of the Postman contains more values and less null values. I have tried the same POST with .Net Core 5 httpclient and I get the same results as with the Postman.

My question is, does anyone have an idea what is going wrong here?

Upvotes: 1

Views: 392

Answers (0)

Related Questions