title: Spring Rest template - 204 content in response from webservice
body: <p>I have a rest service and is consumed using Spring's RestTemplate with Apache HttpClient as,</p>
  
  <pre><code>    @Autowired
      public ClientImpl(@Value("${base-uri}") final String baseUrl,
                                @Qualifier("restOperations") RestOperations restTemplate) {
          serviceUrl = baseUrl;
          restTemplate = restTemplate;
      }
  
     private List&lt;ResponseDetails&gt; processRequest(CustomRequest request) throws Exception {
      ResponseEntity&lt;ResponseDetails[]&gt; responseEntity = restTemplate.exchange(serviceUrl, HttpMethod.POST, entity, ResponseDetails[].class);
      if (responseEntity.getStatusCode().value() == 204) {
          return Collections.&lt;ResponseDetails&gt;emptyList();
      }
      ResponseDetails[] response = responseEntity.getBody();
      return response != null ? Lists.newArrayList(response) : Collections.&lt;ResponseDetails&gt;emptyList();
  }
  </code></pre>
  
  <p>When the webservice returns 204 response, then the second service call after 204 response, fails with read timeout.</p>
  
  <p>Spring-web : 4.3.5</p>
  
  <p>I cannot figure out the cause. Any help?</p>
  
  <p>EDIT:
  From debug logs,</p>
  
  <blockquote>
    <p>org.apache.http.impl.conn.DefaultHttpResponseParser;Garbage in
    response: ÿþ{"id":0}HTTP/1.1 204 Could not find</p>
  </blockquote>
  
  <p><strong>Response in server logs by httpclient:</strong> </p>
  
  <blockquote>
    <p>&lt;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]}></p>
  </blockquote>