Issue
I have a situation condition.
Create a RestAPI. value received from header
ResponseEntity<String> methodname(@RequestBody String request, @RequestHeader MultiValueMap<String, String> headers)
Condition
if (!headers.containsKey("receiverKey")){
throw new restException(null, "Receiverkey", "Receiverkey not comming in Header", null, BAD_REQUEST);
}
if (headers.get("receiverKey").toString().equals("[]")){
throw new restException(null, "Receiverkey", "Receiverkey is not comming in Header", null, BAD_REQUEST);
}
From above code, I am able to achieve the functionality. But I have to refactor the above code means combined into single if condition.
Can any one has help me?
Solution
if (!headers.containsKey("receiverKey") || headers.get("receiverKey").toString().equals("[]")){
throw new restException(null, "Receiverkey", "Receiverkey not comming in Header", null, BAD_REQUEST);
}
Answered By - Bharat Reddy
Answer Checked By - Dawn Plyler (JavaFixing Volunteer)