Skip to content

Commit

Permalink
Simplify client config (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
aymeric-dispa authored Oct 5, 2022
1 parent 5918be3 commit 721724f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 16 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group 'com.firebolt'
version = '2.2.0'
version = '2.2.1-SNAPSHOT'

repositories {
mavenCentral()
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/firebolt/jdbc/client/FireboltClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ private String getInternalErrorWithHeadersText(CloseableHttpResponse response) {
}

private RequestConfig createRequestConfig(int connectionTimeoutMillis, int networkTimoutMillis) {
return RequestConfig.custom().setConnectTimeout(Timeout.of(connectionTimeoutMillis, TimeUnit.MILLISECONDS))
return RequestConfig.custom()
.setConnectTimeout(Timeout.of(connectionTimeoutMillis, TimeUnit.MILLISECONDS))
.setConnectionRequestTimeout(Timeout.of(connectionTimeoutMillis, TimeUnit.MILLISECONDS))
.setCookieSpec(StandardCookieSpec.RELAXED)
.setResponseTimeout(Timeout.ofMilliseconds(networkTimoutMillis)).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.util.concurrent.TimeUnit;

import javax.net.ssl.*;

import org.apache.commons.lang3.StringUtils;
import org.apache.hc.client5.http.HttpRequestRetryStrategy;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.cookie.StandardCookieSpec;
import org.apache.hc.client5.http.impl.DefaultHttpRequestRetryStrategy;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
Expand All @@ -32,7 +29,6 @@
import org.apache.hc.core5.http.io.HttpConnectionFactory;
import org.apache.hc.core5.http.io.SocketConfig;
import org.apache.hc.core5.util.TimeValue;
import org.apache.hc.core5.util.Timeout;

import com.firebolt.jdbc.client.ssl.InsecureTrustManager;
import com.firebolt.jdbc.connection.settings.FireboltProperties;
Expand All @@ -54,7 +50,6 @@ public static CloseableHttpClient createClient(FireboltProperties properties) th

return HttpClientBuilder.create().setConnectionManager(getConnectionManager(properties))
.setConnectionManagerShared(true).disableDefaultUserAgent()
.setDefaultRequestConfig(getDefaultRequestConfig(properties))
.setConnectionReuseStrategy(new DefaultConnectionReuseStrategy())
.setRetryStrategy(createRetryStrategy(properties)).disableContentCompression().build();
}
Expand All @@ -63,12 +58,6 @@ private static HttpRequestRetryStrategy createRetryStrategy(FireboltProperties p
return new DefaultHttpRequestRetryStrategy(properties.getMaxRetries(), TimeValue.ofMilliseconds(500));
}

private static RequestConfig getDefaultRequestConfig(FireboltProperties fireboltProperties) {
return RequestConfig.custom()
.setConnectTimeout(Timeout.of(fireboltProperties.getConnectionTimeoutMillis(), TimeUnit.MILLISECONDS))
.setCookieSpec(StandardCookieSpec.RELAXED).build();
}

private static PoolingHttpClientConnectionManager getConnectionManager(FireboltProperties fireboltProperties)
throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException,
KeyManagementException {
Expand All @@ -88,10 +77,8 @@ private static PoolingHttpClientConnectionManager getConnectionManager(FireboltP
.validateAfterInactivity(
TimeValue.ofMilliseconds(fireboltProperties.getValidateAfterInactivityMillis()))
.maxConnTotal(fireboltProperties.getMaxConnectionsTotal())
.defaultSocketConfig(SocketConfig.custom().setSoKeepAlive(true).build())
.timeToLive(TimeValue.ofMilliseconds(fireboltProperties.getTimeToLiveMillis()))
.defaultSocketConfig(SocketConfig.custom().setSoKeepAlive(true).setSoReuseAddress(true)
.setTcpNoDelay(true).setSoLinger(TimeValue.ofMilliseconds(Integer.MAX_VALUE))
.setSoTimeout(Timeout.ofMilliseconds(fireboltProperties.getSocketTimeoutMillis())).build())
.fireboltProperties(fireboltProperties).build().create();
}

Expand Down

0 comments on commit 721724f

Please sign in to comment.