kaisun2000 commented on a change in pull request #1472:
URL: https://github.com/apache/helix/pull/1472#discussion_r506745498



##########
File path: 
helix-rest/src/main/java/org/apache/helix/rest/client/CustomRestClientImpl.java
##########
@@ -116,25 +116,36 @@ protected JsonNode getJsonObject(HttpResponse 
httpResponse) throws IOException {
       LOG.info("Expected HttpResponse statusCode: {}", HttpStatus.SC_OK);
       return jsonConverter.convert(getJsonObject(httpResponse));
     } else {
+      // Ensure entity is fully consumed so stream is closed.
+      EntityUtils.consumeQuietly(httpResponse.getEntity());
       throw new ClientProtocolException("Unexpected response status: " + 
status + ", reason: "
           + httpResponse.getStatusLine().getReasonPhrase());
     }
   }
 
   @VisibleForTesting
   protected HttpResponse post(String url, Map<String, String> payloads) throws 
IOException {
+    HttpPost postRequest = new HttpPost(url);
     try {
-      HttpPost postRequest = new HttpPost(url);
       postRequest.setHeader("Accept", ACCEPT_CONTENT_TYPE);
       StringEntity entity = new 
StringEntity(OBJECT_MAPPER.writeValueAsString(payloads),
           ContentType.APPLICATION_JSON);
       postRequest.setEntity(entity);
       LOG.info("Executing request: {}, headers: {}, entity: {}", 
postRequest.getRequestLine(),
           postRequest.getAllHeaders(), postRequest.getEntity());
-      return _httpClient.execute(postRequest);
+
+      HttpResponse response = _httpClient.execute(postRequest);

Review comment:
       handleResponse() handles the result from post() assuming post has not IO 
exception. That is the original author's thinking.  So looking at the response 
code previously is in handleResponse(). If sticking to the same line of 
thinking, we can add this warning log to handleResponse, instead in post() here.
   
   But in reality, it does not really matter. More like a style of personal 
choice.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to