Skip to content

Commit df0627d

Browse files
authored
GH-577: Use JVM proxy settings in Netty client (#1027)
### What's Changed The Flight SQL JDBC driver ignored JVM proxy settings (`-Dhttps.proxyHost`, `-Dhttps.proxyPort`). Connections would always go directly to the target host, bypassing any configured proxy. Switched to `NettyChannelBuilder.forAddress(host, port)` for the TCP-based schemes. This causes gRPC to go through `ProxySelector`, which picks up the standard JVM proxy properties. ### Are these changes tested? Yes. Added a test to `ConnectionTest` that installs a recording `ProxySelector` as the JVM default, opens a JDBC connection, and asserts that `ProxySelector.select() `was called. This directly validates that the driver participates in JVM proxy detection without requiring a real proxy server. This change was created with AI assistance (Claude Code). All lines were manually reviewed by a human. The output is not copyrightable subject matter. Closes #577. --------- Assisted-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 4e8faf7 commit df0627d

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/NettyClientBuilder.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,12 @@ public NettyChannelBuilder build() {
139139
case LocationSchemes.GRPC_INSECURE:
140140
case LocationSchemes.GRPC_TLS:
141141
{
142-
builder = NettyChannelBuilder.forAddress(location.toSocketAddress());
142+
final int port = location.getUri().getPort();
143+
if (port < 0 || port > 65535) {
144+
throw new IllegalArgumentException(
145+
"Invalid port " + port + ": must be between 0 and 65535.");
146+
}
147+
builder = NettyChannelBuilder.forAddress(location.getUri().getHost(), port);
143148
break;
144149
}
145150
case LocationSchemes.GRPC_DOMAIN_SOCKET:

flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionTest.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,22 @@
2626
import static org.junit.jupiter.api.Assertions.fail;
2727

2828
import com.google.protobuf.Message;
29+
import java.io.IOException;
30+
import java.net.Proxy;
31+
import java.net.ProxySelector;
32+
import java.net.SocketAddress;
33+
import java.net.URI;
2934
import java.net.URISyntaxException;
3035
import java.sql.Connection;
3136
import java.sql.Driver;
3237
import java.sql.DriverManager;
3338
import java.sql.ResultSet;
3439
import java.sql.SQLException;
3540
import java.sql.Statement;
41+
import java.util.List;
3642
import java.util.Map;
3743
import java.util.Properties;
44+
import java.util.concurrent.atomic.AtomicBoolean;
3845
import java.util.function.Consumer;
3946
import org.apache.arrow.driver.jdbc.authentication.UserPasswordAuthentication;
4047
import org.apache.arrow.driver.jdbc.client.ArrowFlightSqlClientHandler;
@@ -768,4 +775,39 @@ public void testResultSetsFromDatabaseMetadataClosedOnConnectionClose() throws E
768775
assertTrue(resultSets[i].isClosed());
769776
}
770777
}
778+
779+
@Test
780+
public void testJdbcDriverConsultsProxySelectorForTcpConnections() throws Exception {
781+
AtomicBoolean consulted = new AtomicBoolean(false);
782+
ProxySelector original = ProxySelector.getDefault();
783+
ProxySelector.setDefault(
784+
new ProxySelector() {
785+
@Override
786+
public List<Proxy> select(URI uri) {
787+
consulted.set(true);
788+
return original.select(uri);
789+
}
790+
791+
@Override
792+
public void connectFailed(URI uri, SocketAddress sa, IOException e) {}
793+
});
794+
795+
try {
796+
final Properties properties = new Properties();
797+
properties.put(ArrowFlightConnectionProperty.USER.camelName(), userTest);
798+
properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), passTest);
799+
properties.put("useEncryption", false);
800+
801+
DriverManager.getConnection(
802+
"jdbc:arrow-flight-sql://localhost:" + FLIGHT_SERVER_TEST_EXTENSION.getPort(),
803+
properties)
804+
.close();
805+
806+
assertTrue(
807+
consulted.get(),
808+
"JDBC driver must consult ProxySelector so JVM proxy settings are respected");
809+
} finally {
810+
ProxySelector.setDefault(original);
811+
}
812+
}
771813
}

0 commit comments

Comments
 (0)