aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws/src/main
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2024-04-12 18:52:43 +0200
committersonartech <sonartech@sonarsource.com>2024-04-15 20:02:44 +0000
commitbc04c220c0c81f240149e2ee6c5af7fff6fb6f54 (patch)
tree88ee6a45049231894463ba7df877264e1cf2ec2a /sonar-ws/src/main
parent94d11b4e7035ba66617247ebe027943eb37f914d (diff)
downloadsonarqube-bc04c220c0c81f240149e2ee6c5af7fff6fb6f54.tar.gz
sonarqube-bc04c220c0c81f240149e2ee6c5af7fff6fb6f54.zip
SONAR-22039 Support new timeout properties
Diffstat (limited to 'sonar-ws/src/main')
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/HttpConnector.java12
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/OkHttpClientBuilder.java16
2 files changed, 28 insertions, 0 deletions
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/HttpConnector.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/HttpConnector.java
index 2af46da667d..50a35824b06 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/HttpConnector.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/HttpConnector.java
@@ -57,6 +57,7 @@ public class HttpConnector implements WsConnector {
public static final int DEFAULT_CONNECT_TIMEOUT_MILLISECONDS = 30_000;
public static final int DEFAULT_READ_TIMEOUT_MILLISECONDS = 60_000;
+ public static final int DEFAULT_RESPONSE_TIMEOUT_MILLISECONDS = 0;
private static final String JSON = "application/json; charset=utf-8";
/**
@@ -85,6 +86,7 @@ public class HttpConnector implements WsConnector {
okHttpClientBuilder.setProxyLogin(builder.proxyLogin);
okHttpClientBuilder.setProxyPassword(builder.proxyPassword);
okHttpClientBuilder.setConnectTimeoutMs(builder.connectTimeoutMs);
+ okHttpClientBuilder.setResponseTimeoutMs(builder.responseTimeoutMs);
okHttpClientBuilder.setReadTimeoutMs(builder.readTimeoutMs);
okHttpClientBuilder.setSSLSocketFactory(builder.sslSocketFactory);
okHttpClientBuilder.setTrustManager(builder.sslTrustManager);
@@ -264,6 +266,7 @@ public class HttpConnector implements WsConnector {
private String systemPassCode;
private int connectTimeoutMs = DEFAULT_CONNECT_TIMEOUT_MILLISECONDS;
private int readTimeoutMs = DEFAULT_READ_TIMEOUT_MILLISECONDS;
+ private int responseTimeoutMs = DEFAULT_RESPONSE_TIMEOUT_MILLISECONDS;
private SSLSocketFactory sslSocketFactory = null;
private X509TrustManager sslTrustManager = null;
private boolean acceptGzip = false;
@@ -354,6 +357,15 @@ public class HttpConnector implements WsConnector {
return this;
}
+ /**
+ * Sets the response timeout to a specified timeout, in milliseconds.
+ * A timeout of zero is interpreted as an infinite timeout. Default value is {@link #DEFAULT_RESPONSE_TIMEOUT_MILLISECONDS}
+ */
+ public Builder responseTimeoutMilliseconds(int i) {
+ this.responseTimeoutMs = i;
+ return this;
+ }
+
public Builder proxy(@Nullable Proxy proxy) {
this.proxy = proxy;
return this;
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/OkHttpClientBuilder.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/OkHttpClientBuilder.java
index 92be8643433..afb04328c27 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/OkHttpClientBuilder.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/OkHttpClientBuilder.java
@@ -70,6 +70,7 @@ public class OkHttpClientBuilder {
private Boolean followRedirects;
private long connectTimeoutMs = -1;
private long readTimeoutMs = -1;
+ private long responseTimeoutMs = -1;
private SSLSocketFactory sslSocketFactory = null;
private X509TrustManager sslTrustManager = null;
private boolean acceptGzip = false;
@@ -170,6 +171,18 @@ public class OkHttpClientBuilder {
}
/**
+ * Sets the default response timeout for new connections. A value of 0 means no timeout.
+ * Default is to have no timeout.
+ */
+ public OkHttpClientBuilder setResponseTimeoutMs(long l) {
+ if (l < 0) {
+ throw new IllegalArgumentException("Response timeout must be positive. Got " + l);
+ }
+ this.responseTimeoutMs = l;
+ return this;
+ }
+
+ /**
* Set if redirects should be followed or not.
* Default is defined by OkHttp (true, follow redirects).
*/
@@ -187,6 +200,9 @@ public class OkHttpClientBuilder {
if (readTimeoutMs >= 0) {
builder.readTimeout(readTimeoutMs, TimeUnit.MILLISECONDS);
}
+ if (responseTimeoutMs >= 0) {
+ builder.callTimeout(responseTimeoutMs, TimeUnit.MILLISECONDS);
+ }
builder.addNetworkInterceptor(this::addHeaders);
if(!acceptGzip) {
builder.addNetworkInterceptor(new GzipRejectorInterceptor());