diff options
Diffstat (limited to 'sonar-ws/src/main/java/org/sonarqube')
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(); } |