Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3655

RestOperation exchange method returning Http 406

$
0
0

I'm trying to hit a POST request using org.springframework.web.client.RestOperations, This will return me a bearer token.

{"access_token": "<token>","expires_in": 300}

I have created a POJO to map to this response.

TokenResponse.class

import com.fasterxml.jackson.annotation.JsonInclude;import com.fasterxml.jackson.annotation.JsonProperty;import com.fasterxml.jackson.annotation.JsonPropertyOrder;@JsonInclude(JsonInclude.Include.NON_NULL)@JsonPropertyOrder({"access_token","expires_in"})public class TokenResponse {    @JsonProperty("access_token")    private String accessToken;    @JsonProperty("expires_in")    private Integer expiresIn;    @JsonProperty("access_token")    public String getAccessToken() {        return accessToken;    }    @JsonProperty("access_token")    public void setAccessToken(String accessToken) {        this.accessToken = accessToken;    }    @JsonProperty("expires_in")    public Integer getExpiresIn() {        return expiresIn;    }    @JsonProperty("expires_in")    public void setExpiresIn(Integer expiresIn) {        this.expiresIn = expiresIn;    }}

When I try to hit this POST request with the below code, it's returning me an error - org.springframework.web.client.HttpClientErrorException$NotAcceptable: 406 Not Acceptable: [no body]

ResponseEntity<T> response = restOperations.exchange(                    uri,                    HttpMethod.POST,                    new HttpEntity<>(body, headers),                    TokenResponse.class            );

I know the error says there's no body, but when I change the last parameter in the above method call to String.class, I'm getting a Http 200 along with the correct response body. where am I going wrong?


Viewing all articles
Browse latest Browse all 3655

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>