0

My API returns below response

enter image description here

But when I am consuming from webclient

public static String accessToken(String jwtToken) {
   
        WebClient webClient = WebClient.create();

        final WebClient.ResponseSpec response = webClient.post()
                  .uri(UriComponentsBuilder.fromUriString("https://account-d.docusign.com/oauth/token")
                    .queryParam("grant_type", "urn:ietf:params:oauth:grant-type:jwt-bearer")
                    .queryParam("assertion", jwtToken)
                    .toUriString())
                  .retrieve();
        System.out.println(response);
        
        return response.toString();
}

response is

org.springframework.web.reactive.function.client.DefaultWebClient$DefaultResponseSpec@7f0393b5

how can I make the response proper?

when I created custome POJO class

public class JwtToken {
    
    private String access_token;
    private String token_type;
    private Integer expires_in;
    private String scope;
    
    
    @Override
    public String toString() {
        return access_token;
    }
 
    public String getAccess_token() {
        return access_token;
    }
    public void setAccess_token(String access_token) {
        this.access_token = access_token;
    }
    public String getToken_type() {
        return token_type;
    }
    public void setToken_type(String token_type) {
        this.token_type = token_type;
    }
    public Integer getExpires_in() {
        return expires_in;
    }
    public void setExpires_in(Integer expires_in) {
        this.expires_in = expires_in;
    }
    public String getScope() {
        return scope;
    }
    public void setScope(String scope) {
        this.scope = scope;
    }
}

and use it like below and used like below

 public static String accessToken(String jwtToken) {
   
        WebClient webClient = WebClient.create();

        final JwtToken response = webClient.post()
                  .uri(UriComponentsBuilder.fromUriString("https://account-d.docusign.com/oauth/token")
                    .queryParam("grant_type", "urn:ietf:params:oauth:grant-type:jwt-bearer")
                    .queryParam("assertion", jwtToken)
                    .toUriString())
                  .retrieve()
                  .bodyToMono(JwtToken.class)
                  .block();
        System.out.println(response);
        
        return response.toString();
    }

it is throwing exception.

enter image description here

I only need to extract accesstoken from response. how can I get the same?

Oze
  • 23
  • 4
  • 2
    Does this answer your question? [How do I print my Java object without getting "SomeType@2f92e0f4"?](https://stackoverflow.com/questions/29140402/how-do-i-print-my-java-object-without-getting-sometype2f92e0f4) – tgdavies Jun 21 '22 at 02:57
  • I have edited the quetion. could you please have a look once, please – Oze Jun 21 '22 at 05:26
  • 1
    You should update the title of your question to match the new problem. – tgdavies Jun 21 '22 at 05:51
  • ya, did that. can you help on the same. – Oze Jun 21 '22 at 06:00

0 Answers0