1

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:

  • Windows 10
  • Java 11 (ibm-semeru_jdk-11.0.13+8_openj9 and amazon-corretto_jdk11.0.13_8)
  • Spring Boot 2.5.6
  • OkHttpClient 4.9.2
  • IntelliJ IDEA 2021.2.3

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?

sven0379
  • 11
  • 4
  • 2
    And without knowing what you send in `requestBody` we should know what is wrong with your code? The error is in your code as both OkHttp and WebClient do the same. So the error must be somewhere before that, which is your own code. – M. Deinum Nov 17 '21 at 06:47
  • Thanks for your idea. I use the the exact value form the variable requestbody that I generate inside my code and send it with Postman and .Net Core an I get the right reponse. I will have a Look and try to send the request manual with OkHttpCLient – sven0379 Nov 17 '21 at 06:55
  • I add the complete OkHttpClient conscole app code. – sven0379 Nov 17 '21 at 07:21
  • Can it have something to do with date serialization? Maybe your spring app considers your date as local time and converts it to UTC when serializing and that is why you see different data returned. I would try to compare the requests sent out with a tool like fiddler, there you should see the difference. – fbede Nov 17 '21 at 09:07
  • I found my issue. It was my mistake. I use diffrent storages during the request. I used WarmStore, but I have to use ColdStore. – sven0379 Nov 17 '21 at 10:14
  • 1
    Can you please either add that as an answer and accept it or simply delete the question? Thanks! – João Dias Nov 17 '21 at 14:36

0 Answers0