Text Stored in Indian Languages Retrieved as ???? in Servlet Application

48 views Asked by At

My scenario is like this: I have a table in SAP HANA XS where some fields will have values in various Indian languages. The servlet which is deployed on SAP BTP Neo environment does a OData $filter to the HANA XS system over HTTP GET request. While reading the stream, the response for such values comes as ??????

I have tried doing the below without any success:

  1. Save my Java file in UTF-8 encoded format
  2. UTF-8 encoding with the response
  3. Pass headers Accept-Encoding and Accept-Charset to UTF-8

The same piece of code when written in a normal Java class and run locally works fine. Not sure what causes this issue when written in a servlet. Have attached the code here, need help from experts here.


URL urlObj = new URL(executeURL);
HttpURLConnection connection = (HttpURLConnection) urlObj.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Accept", "application/json");
//          connection.setRequestProperty("charset", "utf-8");
//          connection.setRequestProperty("Accept-Encoding", "utf-8");
//          connection.setRequestProperty("Accept-Charset", "Charset=windows-1255");
connection.setRequestProperty("Authorization", "Basic " + Base64.getEncoder().encodeToString(userPass.getBytes()));
connection.setDoInput(true);

in = new BufferedReader(new InputStreamReader(connection.getInputStream(),"UTF-8"));
String inputLine;
StringBuffer responseStrBuffer = new StringBuffer();
while ((inputLine = (in.readLine())) != null) {
        responseStrBuffer.append(inputLine);
}

JsonParser parser = new JsonParser();
jsonObj = (JsonObject) parser.parse(responseStrBuffer.toString());```
0

There are 0 answers