Q: I was asked to write a REST call to a third party address service. Everything is fine but when we are trying to test it on code base level, it failed! The call to https:///v1/ failed. But it is successful in postman, how come? It is weird.

A: The service address call is a two-steps call, one is to get the token the second step is insert this token into headers and do a REST call. After investigating, I found the problem is in the headers. Below is the code:
private HttpHeaders getHttpHeaders(final String token, final String correlationId) {
final HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
return headers;
}
It seems like the downstream system does not like UTF8. So if you change it to:
private HttpHeaders getHttpHeaders(final String token, final String correlationId) {
final HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
return headers;
}
The problem is resolved.
Advertisements