ninihood ninihood
ninihood ninihood

Reputation: 21

why response of restTemplate.exchange return null?

I have blow code and my web service works well but does not return response :

ResponseEntity<Object> reponse=null;
        try {
            reponse = restTemplate.exchange(url, HttpMethod.POST, requestEntity, Object.class);

        } catch (HttpStatusCodeException e) {
            System.out.println("reponse="+reponse);


        }

my question is that, why

response

is null but

restTemplate.exchange(url, HttpMethod.POST, requestEntity, Object.class)

is not null?

Upvotes: 1

Views: 2970

Answers (1)

ninihood ninihood
ninihood ninihood

Reputation: 21

I was incorrectly searching for errors in response entity. But it is available in the exception.

} catch (HttpClientErrorException e) {
      System.out.println(e.getStatusCode());
      System.out.println(e.getResponseBodyAsString());
    }

Upvotes: 1

Related Questions