0

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?

6
  • 1
    First few times you get the correct response. Hence I believe the reason for Bad Request is very much because of the implementation in the Rest Service you are trying to hit. Is the number of successful hits to with the rest template constant ?
    – abj1305
    May 13, 2019 at 4:50
  • Not sure. I don't know if I can check the number of successful hits. May 13, 2019 at 5:16
  • Is it possible to enable more extensive logs ?
    – abj1305
    May 13, 2019 at 6:15
  • This is almost for sure a server-side issue. Without information about the server-side (code, logs) it will be very hard to help you.
    – jannis
    May 13, 2019 at 8:14
  • I've added some extra log statements in this method. Waiting for the issue to happen. As of now, the method is working fine. May 13, 2019 at 9:46

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.