Home > Blockchain >  REST API Headers value in multivaluemap
REST API Headers value in multivaluemap

Time:01-25

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?

CodePudding user response:

if (!headers.containsKey("receiverKey") || headers.get("receiverKey").toString().equals("[]")){
        throw new restException(null, "Receiverkey", "Receiverkey not comming in Header", null, BAD_REQUEST);
    }
  •  Tags:  
  • Related