I've a RestTemplate
that is sending get requests to a URL to get some data of type String
. The code is working fine for sometime. But all of a sudden all the requests for the same URL are failing with 400: Bad Request error
.
try {
ResponseEntity<String> response = this.rest.getForEntity(uri, String.class);
body = response.getBody();
} catch (Exception e) {
String m = e.getLocalizedMessage() + "; " + uri;
log.error(m, e);
}
Caused by: org.springframework.web.client.HttpClientErrorException: 400 Bad Request at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:91) at org.springframework.web.client.RestTemplate.handleResponseError(RestTemplate.java:615) at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:573) at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:544) at org.springframework.web.client.RestTemplate.getForEntity(RestTemplate.java:277) at com.pkgajulpalli.util.URIClient.getRawBodyForURL(URIClient.java:45) ... 47 more
If I try the same URL in browser it works fine. If I restart the server, the same request works fine. Is there anything that could go wrong here with resttemplate?