Skip to content
This repository was archived by the owner on Mar 23, 2026. It is now read-only.

Commit 4f25d3d

Browse files
committed
feat(jdbc): add HttpTransportOptions timeout configurations
1 parent 0a3d669 commit 4f25d3d

3 files changed

Lines changed: 66 additions & 8 deletions

File tree

google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryConnection.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ public class BigQueryConnection extends BigQueryNoOpsConnection {
130130
String sslTrustStorePassword;
131131
long maxBytesBilled;
132132
Map<String, String> labels;
133+
Integer httpConnectTimeout;
134+
Integer httpReadTimeout;
133135

134136
BigQueryConnection(String url) throws IOException {
135137
this.connectionUrl = url;
@@ -271,11 +273,25 @@ public class BigQueryConnection extends BigQueryNoOpsConnection {
271273
BigQueryJdbcUrlUtility.SSL_TRUST_STORE_PWD_PROPERTY_NAME,
272274
null,
273275
this.connectionClassName);
276+
this.httpConnectTimeout =
277+
BigQueryJdbcUrlUtility.parseIntProperty(
278+
url,
279+
BigQueryJdbcUrlUtility.HTTP_CONNECT_TIMEOUT_PROPERTY_NAME,
280+
BigQueryJdbcUrlUtility.DEFAULT_HTTP_CONNECT_TIMEOUT_VALUE,
281+
this.connectionClassName);
282+
this.httpReadTimeout =
283+
BigQueryJdbcUrlUtility.parseIntProperty(
284+
url,
285+
BigQueryJdbcUrlUtility.HTTP_READ_TIMEOUT_PROPERTY_NAME,
286+
BigQueryJdbcUrlUtility.DEFAULT_HTTP_READ_TIMEOUT_VALUE,
287+
this.connectionClassName);
274288
this.httpTransportOptions =
275289
BigQueryJdbcProxyUtility.getHttpTransportOptions(
276290
proxyProperties,
277291
this.sslTrustStorePath,
278292
this.sslTrustStorePassword,
293+
this.httpConnectTimeout,
294+
this.httpReadTimeout,
279295
this.connectionClassName);
280296
this.transportChannelProvider =
281297
BigQueryJdbcProxyUtility.getTransportChannelProvider(
@@ -723,6 +739,14 @@ String getSSLTrustStorePassword() {
723739
return sslTrustStorePassword;
724740
}
725741

742+
Integer getHttpConnectTimeout() {
743+
return httpConnectTimeout;
744+
}
745+
746+
Integer getHttpReadTimeout() {
747+
return httpReadTimeout;
748+
}
749+
726750
@Override
727751
public boolean isValid(int timeout) throws SQLException {
728752
if (timeout < 0) {

google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcProxyUtility.java

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ static Map<String, String> parseProxyProperties(String URL, String callerClassNa
9797
(proxyHost == null && proxyPort != null) || (proxyHost != null && proxyPort == null);
9898
if (isMissingProxyHostOrPortWhenProxySet) {
9999
throw new IllegalArgumentException(
100-
"Both ProxyHost and ProxyPort parameters need to be specified. No defaulting behavior occurs.");
100+
"Both ProxyHost and ProxyPort parameters need to be specified. No defaulting behavior"
101+
+ " occurs.");
101102
}
102103
boolean isMissingProxyUidOrPwdWhenAuthSet =
103104
(proxyUid == null && proxyPwd != null) || (proxyUid != null && proxyPwd == null);
@@ -117,18 +118,34 @@ static HttpTransportOptions getHttpTransportOptions(
117118
Map<String, String> proxyProperties,
118119
String sslTrustStorePath,
119120
String sslTrustStorePassword,
121+
Integer connectTimeout,
122+
Integer readTimeout,
120123
String callerClassName) {
121124
LOG.finest("++enter++\t" + callerClassName);
122125

123126
if (!proxyProperties.containsKey(BigQueryJdbcUrlUtility.PROXY_HOST_PROPERTY_NAME)
124-
&& sslTrustStorePath == null) {
127+
&& sslTrustStorePath == null
128+
&& connectTimeout == null
129+
&& readTimeout == null) {
125130
return null;
126131
}
127-
return HttpTransportOptions.newBuilder()
128-
.setHttpTransportFactory(
129-
getHttpTransportFactory(
130-
proxyProperties, sslTrustStorePath, sslTrustStorePassword, callerClassName))
131-
.build();
132+
133+
HttpTransportOptions.Builder httpTransportOptionsBuilder = HttpTransportOptions.newBuilder();
134+
if (proxyProperties.containsKey(BigQueryJdbcUrlUtility.PROXY_HOST_PROPERTY_NAME)
135+
|| sslTrustStorePath != null) {
136+
httpTransportOptionsBuilder.setHttpTransportFactory(
137+
getHttpTransportFactory(
138+
proxyProperties, sslTrustStorePath, sslTrustStorePassword, callerClassName));
139+
}
140+
141+
if (connectTimeout != null) {
142+
httpTransportOptionsBuilder.setConnectTimeout(connectTimeout);
143+
}
144+
if (readTimeout != null) {
145+
httpTransportOptionsBuilder.setReadTimeout(readTimeout);
146+
}
147+
148+
return httpTransportOptionsBuilder.build();
132149
}
133150

134151
private static HttpTransportFactory getHttpTransportFactory(

google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcUrlUtility.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ final class BigQueryJdbcUrlUtility {
9898
static final String PROXY_PORT_PROPERTY_NAME = "ProxyPort";
9999
static final String PROXY_USER_ID_PROPERTY_NAME = "ProxyUid";
100100
static final String PROXY_PASSWORD_PROPERTY_NAME = "ProxyPwd";
101+
static final String HTTP_CONNECT_TIMEOUT_PROPERTY_NAME = "HttpConnectTimeout";
102+
static final String HTTP_READ_TIMEOUT_PROPERTY_NAME = "HttpReadTimeout";
103+
static final int DEFAULT_HTTP_CONNECT_TIMEOUT_VALUE = 60000;
104+
static final int DEFAULT_HTTP_READ_TIMEOUT_VALUE = 60000;
101105
static final boolean DEFAULT_ENABLE_HTAPI_VALUE = false;
102106
static final boolean DEFAULT_ENABLE_SESSION_VALUE = false;
103107
static final int DEFAULT_LOG_LEVEL = 0;
@@ -249,7 +253,8 @@ final class BigQueryJdbcUrlUtility {
249253
BigQueryConnectionProperty.newBuilder()
250254
.setName(OAUTH_SA_IMPERSONATION_CHAIN_PROPERTY_NAME)
251255
.setDescription(
252-
"Comma separated list of service account emails in the impersonation chain.")
256+
"Comma separated list of service account emails in the impersonation"
257+
+ " chain.")
253258
.build(),
254259
BigQueryConnectionProperty.newBuilder()
255260
.setName(OAUTH_SA_IMPERSONATION_SCOPES_PROPERTY_NAME)
@@ -569,6 +574,18 @@ final class BigQueryJdbcUrlUtility {
569574
.setDescription(
570575
"The password for accessing the Java TrustStore that is specified using"
571576
+ " the property SSLTrustStore.")
577+
.build(),
578+
BigQueryConnectionProperty.newBuilder()
579+
.setName(HTTP_CONNECT_TIMEOUT_PROPERTY_NAME)
580+
.setDescription(
581+
"The timeout (in milliseconds) for establishing a connection to the"
582+
+ " server.")
583+
.setDefaultValue(String.valueOf(DEFAULT_HTTP_CONNECT_TIMEOUT_VALUE))
584+
.build(),
585+
BigQueryConnectionProperty.newBuilder()
586+
.setName(HTTP_READ_TIMEOUT_PROPERTY_NAME)
587+
.setDescription("The timeout (in milliseconds) when reading from the server.")
588+
.setDefaultValue(String.valueOf(DEFAULT_HTTP_READ_TIMEOUT_VALUE))
572589
.build())));
573590

574591
private BigQueryJdbcUrlUtility() {}

0 commit comments

Comments
 (0)