Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.apache.v5.Apache5HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.gax.rpc.TransportChannelProvider;
import com.google.auth.http.HttpTransportFactory;
import com.google.cloud.bigquery.exception.BigQueryJdbcRuntimeException;
Expand Down Expand Up @@ -136,17 +137,15 @@ static HttpTransportOptions getHttpTransportOptions(
boolean hasProxyOrSsl =
proxyProperties.containsKey(BigQueryJdbcUrlUtility.PROXY_HOST_PROPERTY_NAME)
|| sslTrustStorePath != null;
boolean hasTimeoutConfig = connectTimeout != null || readTimeout != null;

if (!hasProxyOrSsl && !hasTimeoutConfig) {
return null;
}

HttpTransportOptions.Builder httpTransportOptionsBuilder = HttpTransportOptions.newBuilder();
if (hasProxyOrSsl) {
httpTransportOptionsBuilder.setHttpTransportFactory(
getHttpTransportFactory(
proxyProperties, sslTrustStorePath, sslTrustStorePassword, callerClassName));
} else {
final HttpTransport defaultTransport = new NetHttpTransport.Builder().build();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why using final here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed. It was originally added because the variable is captured by a lambda, but since it is effectively final, the final keyword is redundant.

httpTransportOptionsBuilder.setHttpTransportFactory(() -> defaultTransport);
}

if (connectTimeout != null) {
Expand Down Expand Up @@ -178,9 +177,8 @@ private static HttpTransportFactory getHttpTransportFactory(
HttpRoutePlanner httpRoutePlanner = new DefaultProxyRoutePlanner(proxyHostDetails);
httpClientBuilder.setRoutePlanner(httpRoutePlanner);
addAuthToProxyIfPresent(proxyProperties, httpClientBuilder, callerClassName);
} else {
httpClientBuilder.useSystemProperties();
}
httpClientBuilder.useSystemProperties();

if (sslTrustStorePath != null) {
try (FileInputStream trustStoreStream = new FileInputStream(sslTrustStorePath)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public void testGetHttpTransportOptionsWithNonAuthenticatedProxy() {
}

@Test
public void testGetHttpTransportOptionsWithNoProxySettingsReturnsNull() {
public void testGetHttpTransportOptionsWithNoProxySettingsReturnsDefaultOptions() {
String connection_uri =
"jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;"
+ "ProjectId=TestProject"
Expand All @@ -172,7 +172,8 @@ public void testGetHttpTransportOptionsWithNoProxySettingsReturnsNull() {
HttpTransportOptions result =
BigQueryJdbcProxyUtility.getHttpTransportOptions(
proxyProperties, null, null, null, null, "TestClass");
assertNull(result);
assertNotNull(result);
assertNotNull(result.getHttpTransportFactory());
}

private String getTestResourcePath(String resourceName) throws URISyntaxException {
Expand Down Expand Up @@ -299,11 +300,12 @@ public void testGetTransportChannelProvider_noProxyNoSsl_returnsNull() {
}

@Test
public void testGetHttpTransportOptions_noProxyNoSsl_returnsNull() {
public void testGetHttpTransportOptions_noProxyNoSsl_returnsDefaultOptions() {
HttpTransportOptions options =
BigQueryJdbcProxyUtility.getHttpTransportOptions(
Collections.<String, String>emptyMap(), null, null, null, null, "TestClass");
assertNull(options);
assertNotNull(options);
assertNotNull(options.getHttpTransportFactory());
}

@Test
Expand Down
Loading