3

I am unable to fetch the data from a katable to a pojo class ouput

I have tried to call rest end point of confluent kafka but I am uanble to put the output in a pojo class.

    @PostMapping("/QueryForEquipment")
    @Consumes("application/json")
    public String getEquipments() {
            String walletBalanceUrl = "http://172.21.79.18:8088/query";

            HttpHeaders httpHeaders = new HttpHeaders();
            httpHeaders.set("Content-Type", "application/json");
            httpHeaders.add("Accept", MediaType.APPLICATION_JSON.toString());

            JSONObject json = new JSONObject();
            json.put("ksql", "Select * from  EQP_STREAM limit 10;");

            JSONObject jsonSub = new JSONObject();
            jsonSub.put("ksql.streams.auto.offset.reset", "earliest");
            json.put("streamsProperties", jsonSub);

         /*   String body=new String("{
                    "ksql": "Select ROWTIME,ROWKEY,TRN_ID_KEY from TABLE_EQP_LOCATION limit 10;",
                "streamsProperties": {"ksql.streams.auto.offset.reset": "earliest"} }"); 

         */

            System.out.println(walletBalanceUrl);

            HttpEntity httpEntity = new HttpEntity(body, httpHeaders);

            RestTemplate restTemplate = new RestTemplate();
            System.out.println("json text====" + body);

            ResponseEntity<String> uri = restTemplate.postForEntity(walletBalanceUrl, httpEntity, String.class);

            return uri.getBody().toString();

Expected ouput must be in json format At present it is coming as

{"row":{"columns":[1556458915675,"CDAU603054","Q1214320190418","TRAIN","Arrived","BELLEVILLE","Q","1214","4",1555545600000," ",1555618200000,"SRS_TRAIN","-77.374856","44.179657",null,null,"CDAU603054","CDAU","603054","INTERMODAL","L","KC7","7","DTTX720029","DTTX","720029","C","T","TOP",1555621693617]},"errorMessage":null,"finalMessage":null}
{"row":{"columns":[1556458915680,"CDAU603066","Q1214320190418","TRAIN","Arrived","BELLEVILLE","Q","1214","4",1555545600000," ",1555618200000,"SRS_TRAIN","-77.374856","44.179657",null,null,"CDAU603066","CDAU","603066","INTERMODAL","L","KC7","8","DTTX720030","DTTX","720030","D","T","TOP",1555621693617]},"errorMessage":null,"finalMessage":null}
{"row":{"columns":[1556458915680,"CDAU603070","Q1214320190418","TRAIN","Arrived","BELLEVILLE","Q","1214","4",1555545600000," ",1555618200000,"SRS_TRAIN","-77.374856","44.179657",null,null,"CDAU603070","CDAU","603070","INTERMODAL","L","KC7","8","DTTX720030","DTTX","720030","A","T","TOP",1555621693617]},"errorMessage":null,"finalMessage":null}
Robin Moffatt
  • 30,382
  • 3
  • 65
  • 92

1 Answers1

0

Here, Content-Type will be application/vnd.ksql.v1+json and also set charset to utf-8.

    HttpHeaders headers = new HttpHeaders();
    headers.set("Content-Type", "application/vnd.ksql.v1+json");
    headers.set("charset", "utf-8");
    headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));

And the ksql query will be SELECT * from EQP_STREAM EMIT CHANGES limit 10;

     json.put("ksql", "SELECT * from  EQP_STREAM EMIT CHANGES limit 10;")

For reference check this link : https://docs.ksqldb.io/en/latest/developer-guide/ksqldb-rest-api/ksql-endpoint/