I am using POSTMAN to test an api I have written in JAVA. I am able to access the api itself (I see it when I debug), but the JSON object I am sending is received as empty. At the end of execution, an empty print is happening.
In the header configurations I have the following:
and in the body section I entered the following json:
My Java code:
@POST
@Path("admin/save'")
public Response printInputText(@Context SecurityContext sc,InputStream incomingData) {
String requestText = getStringFromInputStream(incomingData);
System.out.println(requestText);
if(requestText.equals("")){
return Response.status(Status.INTERNAL_SERVER_ERROR).build();
}
return Response.status(Status.OK).build();
}
public static String getStringFromInputStream(InputStream is) {
BufferedReader br = null;
StringBuilder sb = new StringBuilder();
String line;
try {
br = new BufferedReader(new InputStreamReader(is));
while ((line = br.readLine()) != null) {
sb.append(line + System.lineSeparator());
}
} catch (IOException e) {
e.getMessage();
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return sb.toString();
}
curl (changed the url a bit but I am getting to the url so it is not the issue):
curl --location --request POST 'http://uri.com/ui/rest/admin/save' \
--header 'Authorization: Basic QzUzMDY3Nzc6QWxlWEZlckczMg==' \
--header 'Content-Type: application/json' \
--data-raw '{ "key": "value", "nextKey": "nextVal", "lastKey": "lastVal" }'