Spring Rest template – 204 content in response from webservice

Home / Uncategorized / Spring Rest template – 204 content in response from webservice

Question:
I have a rest service and is consumed using Spring’s RestTemplate with Apache HttpClient as,
@Autowired
public ClientImpl(@Value("${base-uri}") final String baseUrl,
@Qualifier("restOperations") RestOperations restTemplate) {
serviceUrl = baseUrl;
restTemplate = restTemplate;
}

private List processRequest(CustomRequest request) throws Exception {
ResponseEntity responseEntity = restTemplate.exchange(serviceUrl, HttpMethod.POST, entity, ResponseDetails[].class);
if (responseEntity.getStatusCode().value() == 204) {
return Collections.emptyList();
}
ResponseDetails[] response = responseEntity.getBody();
return response != null ? Lists.newArrayList(response) : Collections.emptyList();
}

When the webservice returns 204 response, then the second service call after 204 response, fails with read timeout.

Spring-web : 4.3.5

I cannot figure out the cause. Any help?

EDIT: From debug logs,

org.apache.http.impl.conn.DefaultHttpResponseParser;Garbage in response: ÿþ{"id":0}HTTP/1.1 204 Could not find

Response in server logs by httpclient:

<204 No Content,{Cache-Control=[no-cache], Pragma=[no-cache], Content-Type=[application/json; charset=utf-16], Expires=[-1], Server=[some], X-AspNet-Version=[someversion], X-Powered-By=[ASP.NET], Date=[somedate]}>


Answer:

Read more

Leave a Reply

Your email address will not be published. Required fields are marked *