]> source.dussan.org Git - sonarqube.git/commitdiff
Fix close connection
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Wed, 13 Jul 2016 15:01:55 +0000 (17:01 +0200)
committerDuarte Meneses <duarte.meneses@sonarsource.com>
Wed, 13 Jul 2016 16:07:38 +0000 (18:07 +0200)
sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/BatchWsClient.java
sonar-ws/src/main/java/org/sonarqube/ws/client/OkHttpResponse.java

index ea47cececbd372aaecfc24ad538a3224fdf88d4f..98269c46a6786490749835e171802713b61c7139 100644 (file)
@@ -97,7 +97,6 @@ public class BatchWsClient {
     }
     if (code == HTTP_FORBIDDEN || code == HTTP_BAD_REQUEST) {
       // SONAR-4397 Details are in response content
-      response.close();
       throw MessageException.of(tryParseAsJsonError(response.content()));
     }
     response.failIfNotSuccessful();
index ce412f69de82b50d287798d4a980640e75ea962a..0532e9f70f8bd08fc87f51c020db36aaa3aa0dd7 100644 (file)
@@ -20,6 +20,8 @@
 package org.sonarqube.ws.client;
 
 import okhttp3.Response;
+import okhttp3.ResponseBody;
+
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.Reader;
@@ -65,12 +67,18 @@ class OkHttpResponse extends BaseResponse {
     return okResponse.body().charStream();
   }
 
+  /**
+   * Get body content as a String. This response will be automatically closed.
+   */
   @Override
   public String content() {
+    ResponseBody body = okResponse.body();
     try {
-      return okResponse.body().string();
+      return body.string();
     } catch (IOException e) {
       throw fail(e);
+    } finally {
+      body.close();
     }
   }