I am trying a hit a POST API which is returning a token of the format - "ABC:XYZ". When I am trying to parse this into a String it is not able to do it. I suspect, it is because of the presence of a colon( : ) in the token because of which it is treating it as a JSON. I am using REST Template. I tried setting the Accept Header as MediaType.TEXT_PLAIN but that also didn't work for me.
Below is my code
ResponseEntity<Object> response = null;
HttpHeaders headers = new HttpHeaders();
try {
UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromHttpUrl("https://XXXX/YYYY");
Map<String, String> criteria = new HashMap<>();
criteria.put("username", "JOHNDOE");
uriBuilder.queryParam("username", "{username}");
criteria.put("target_site", "SITE");
uriBuilder.queryParam("target_site", "{target_site}");
headers.setAccept(Collections.singletonList(MediaType.TEXT_PLAIN));
HttpEntity<String> entity = new HttpEntity<>(headers);
// ParameterizedTypeReference<String> responseType = new ParameterizedTypeReference<String>() {
// };
response =
restTemplateSSLIgnore.exchange(
uriBuilder.build().toUriString(),
HttpMethod.POST,
entity,
Object.class,
criteria);
logger.info(response.getBody());
}catch (Exception e){
logger.error(e.getMessage(),e);
return false;
}
return response.getBody();
Can somebody help me with this?