I created an interceptor to get the token before i do other request but i have the error "Method threw 'java.lang.StackOverflowError' exception." when i do the request.
public ClientHttpResponse intercept(HttpRequest request, byte[] body,
ClientHttpRequestExecution execution) throws IOException {
request.getHeaders().add("Authorization", "Bearer " + loginWithCredentials());
return execution.execute(request, body);
}
private String loginWithCredentials() {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
map.add("grant_type", "password");
map.add("client_id", getClientId());
map.add("client_secret", getClientSecret());
map.add("username", getUsername());
map.add("password", getPassword());
HttpEntity<String> request = new HttpEntity<>(headers);
final ResponseEntity<String> responseEntity = getRestTemplate().exchange(
getCarrierGatewayTokenUrl(),
HttpMethod.POST,
request,
String.class);
return responseEntity.getBody();
}