aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws/src/main/java/org/sonarqube
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2016-07-13 11:32:23 +0200
committerDuarte Meneses <duarte.meneses@sonarsource.com>2016-07-13 14:12:14 +0200
commitdfa96c89fc0949b7c9c3784078c96ecabf56f1dd (patch)
treebee9a8b03714866db17c18d9cf133a4c8e45c605 /sonar-ws/src/main/java/org/sonarqube
parentec692c4d95dd423740867418227d2cde54c40d79 (diff)
downloadsonarqube-dfa96c89fc0949b7c9c3784078c96ecabf56f1dd.tar.gz
sonarqube-dfa96c89fc0949b7c9c3784078c96ecabf56f1dd.zip
Fix leaked connection
Diffstat (limited to 'sonar-ws/src/main/java/org/sonarqube')
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/BaseResponse.java6
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/OkHttpResponse.java8
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/WsResponse.java6
3 files changed, 19 insertions, 1 deletions
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/BaseResponse.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/BaseResponse.java
index 2cfcd7448a5..f97a919ec91 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/BaseResponse.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/BaseResponse.java
@@ -31,6 +31,7 @@ abstract class BaseResponse implements WsResponse {
@Override
public WsResponse failIfNotSuccessful() {
if (!isSuccessful()) {
+ close();
throw new HttpException(requestUrl(), code());
}
return this;
@@ -40,4 +41,9 @@ abstract class BaseResponse implements WsResponse {
public boolean hasContent() {
return code() != HTTP_NO_CONTENT;
}
+
+ @Override
+ public void close() {
+ // override if needed
+ }
}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/OkHttpResponse.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/OkHttpResponse.java
index c2a6babc714..ce412f69de8 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/OkHttpResponse.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/OkHttpResponse.java
@@ -77,4 +77,12 @@ class OkHttpResponse extends BaseResponse {
private RuntimeException fail(Exception e) {
throw new IllegalStateException("Fail to read response of " + requestUrl(), e);
}
+
+ /**
+ * Equivalent to closing contentReader or contentStream.
+ */
+ @Override
+ public void close() {
+ okResponse.close();
+ }
}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/WsResponse.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/WsResponse.java
index 89c8977a46d..fc3d83ff177 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/WsResponse.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/WsResponse.java
@@ -19,13 +19,14 @@
*/
package org.sonarqube.ws.client;
+import java.io.Closeable;
import java.io.InputStream;
import java.io.Reader;
/**
* @since 5.3
*/
-public interface WsResponse {
+public interface WsResponse extends Closeable {
/**
* The absolute requested URL
@@ -57,5 +58,8 @@ public interface WsResponse {
Reader contentReader();
String content();
+
+ @Override
+ void close();
}