This is an automated email from the ASF dual-hosted git repository.

lidavidm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-java.git


The following commit(s) were added to refs/heads/main by this push:
     new df0627dfd GH-577: Use JVM proxy settings in Netty client (#1027)
df0627dfd is described below

commit df0627dfd371989885352780805e629bc06588d5
Author: Pedro Matias <[email protected]>
AuthorDate: Mon Aug 31 04:20:35 2026 +0100

    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 <[email protected]>
---
 .../arrow/flight/grpc/NettyClientBuilder.java      |  7 +++-
 .../apache/arrow/driver/jdbc/ConnectionTest.java   | 42 ++++++++++++++++++++++
 2 files changed, 48 insertions(+), 1 deletion(-)

diff --git 
a/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/NettyClientBuilder.java
 
b/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/NettyClientBuilder.java
index e65871121..7df1a0a2a 100644
--- 
a/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/NettyClientBuilder.java
+++ 
b/flight/flight-core/src/main/java/org/apache/arrow/flight/grpc/NettyClientBuilder.java
@@ -139,7 +139,12 @@ public class NettyClientBuilder {
       case LocationSchemes.GRPC_INSECURE:
       case LocationSchemes.GRPC_TLS:
         {
-          builder = NettyChannelBuilder.forAddress(location.toSocketAddress());
+          final int port = location.getUri().getPort();
+          if (port < 0 || port > 65535) {
+            throw new IllegalArgumentException(
+                "Invalid port " + port + ": must be between 0 and 65535.");
+          }
+          builder = 
NettyChannelBuilder.forAddress(location.getUri().getHost(), port);
           break;
         }
       case LocationSchemes.GRPC_DOMAIN_SOCKET:
diff --git 
a/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionTest.java
 
b/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionTest.java
index 55722f60f..d9122d101 100644
--- 
a/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionTest.java
+++ 
b/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ConnectionTest.java
@@ -26,6 +26,11 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.junit.jupiter.api.Assertions.fail;
 
 import com.google.protobuf.Message;
+import java.io.IOException;
+import java.net.Proxy;
+import java.net.ProxySelector;
+import java.net.SocketAddress;
+import java.net.URI;
 import java.net.URISyntaxException;
 import java.sql.Connection;
 import java.sql.Driver;
@@ -33,8 +38,10 @@ import java.sql.DriverManager;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
+import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.function.Consumer;
 import org.apache.arrow.driver.jdbc.authentication.UserPasswordAuthentication;
 import org.apache.arrow.driver.jdbc.client.ArrowFlightSqlClientHandler;
@@ -768,4 +775,39 @@ public class ConnectionTest {
       assertTrue(resultSets[i].isClosed());
     }
   }
+
+  @Test
+  public void testJdbcDriverConsultsProxySelectorForTcpConnections() throws 
Exception {
+    AtomicBoolean consulted = new AtomicBoolean(false);
+    ProxySelector original = ProxySelector.getDefault();
+    ProxySelector.setDefault(
+        new ProxySelector() {
+          @Override
+          public List<Proxy> select(URI uri) {
+            consulted.set(true);
+            return original.select(uri);
+          }
+
+          @Override
+          public void connectFailed(URI uri, SocketAddress sa, IOException e) 
{}
+        });
+
+    try {
+      final Properties properties = new Properties();
+      properties.put(ArrowFlightConnectionProperty.USER.camelName(), userTest);
+      properties.put(ArrowFlightConnectionProperty.PASSWORD.camelName(), 
passTest);
+      properties.put("useEncryption", false);
+
+      DriverManager.getConnection(
+              "jdbc:arrow-flight-sql://localhost:" + 
FLIGHT_SERVER_TEST_EXTENSION.getPort(),
+              properties)
+          .close();
+
+      assertTrue(
+          consulted.get(),
+          "JDBC driver must consult ProxySelector so JVM proxy settings are 
respected");
+    } finally {
+      ProxySelector.setDefault(original);
+    }
+  }
 }

Reply via email to