Skip to content

Commit 24c16d5

Browse files
refactor: change proxyUrl to proxyAddress
1 parent 44a0a83 commit 24c16d5

File tree

7 files changed

+44
-44
lines changed

7 files changed

+44
-44
lines changed

examples/src/main/java/com/influxdb/v3/ProxyExample.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ private ProxyExample() { }
3535
public static void main(final String[] args) throws Exception {
3636
// Run docker-compose.yml file to start Envoy proxy
3737

38-
String proxyUrl = "http://127.0.0.1:10000";
39-
String certificateFilePath = "src/test/java/com/influxdb/v3/client/testdata/valid-certificates.pem";
38+
String proxyAddress = new InetSocketAddress("localhost", 10000);
39+
String certificateFilePath = "src/test/java/com/influxdb/v3/client/testdata/influxdb-certificate.pem";
4040
ClientConfig clientConfig = new ClientConfig.Builder()
4141
.host(System.getenv("TESTING_INFLUXDB_URL"))
4242
.token(System.getenv("TESTING_INFLUXDB_TOKEN").toCharArray())
4343
.database(System.getenv("TESTING_INFLUXDB_DATABASE"))
44-
.proxyUrl(proxyUrl)
44+
.proxyAddress(proxyAddress)
4545
.certificateFilePath(certificateFilePath)
4646
.build();
4747

src/main/java/com/influxdb/v3/client/config/ClientConfig.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
package com.influxdb.v3.client.config;
2323

2424
import java.net.Authenticator;
25+
import java.net.InetSocketAddress;
2526
import java.net.MalformedURLException;
2627
import java.net.ProxySelector;
2728
import java.net.URL;
@@ -58,7 +59,7 @@
5859
* disable server certificate validation for HTTPS connections
5960
* </li>
6061
* <li><code>proxy</code> - HTTP proxy selector</li>
61-
* <li><code>proxyUrl</code> - Proxy url for query api and write api</li>
62+
* <li><code>proxyAddress</code> - Proxy address for query api and write api</li>
6263
* <li><code>queryApiProxy</code> - HTTP query detector</li>
6364
* <li><code>authenticator</code> - HTTP proxy authenticator</li>
6465
* <li><code>headers</code> - headers to be added to requests</li>
@@ -100,13 +101,13 @@ public final class ClientConfig {
100101
private final Duration timeout;
101102
private final Boolean allowHttpRedirects;
102103
private final Boolean disableServerCertificateValidation;
103-
private final String proxyUrl;
104+
private final InetSocketAddress proxyAddress;
104105
private final Authenticator authenticator;
105106
private final Map<String, String> headers;
106107
private final String certificateFilePath;
107108

108109
/**
109-
* Deprecated use {@link #proxyUrl}.
110+
* Deprecated use {@link #proxyAddress}.
110111
*/
111112
@Deprecated
112113
private final ProxySelector proxy;
@@ -224,7 +225,7 @@ public Boolean getDisableServerCertificateValidation() {
224225
* Gets the proxy.
225226
*
226227
* @return the proxy, may be null
227-
* Deprecated use {@link #proxyUrl}
228+
* Deprecated use {@link #proxyAddress}
228229
*/
229230
@Nullable
230231
@Deprecated
@@ -233,13 +234,13 @@ public ProxySelector getProxy() {
233234
}
234235

235236
/**
236-
* Gets the proxy url.
237+
* Gets the proxy address.
237238
*
238-
* @return the proxy url, may be null
239+
* @return the proxy address, may be null
239240
*/
240241
@Nullable
241-
public String getProxyUrl() {
242-
return proxyUrl;
242+
public InetSocketAddress getProxyAddress() {
243+
return proxyAddress;
243244
}
244245

245246
/**
@@ -302,7 +303,7 @@ public boolean equals(final Object o) {
302303
&& Objects.equals(allowHttpRedirects, that.allowHttpRedirects)
303304
&& Objects.equals(disableServerCertificateValidation, that.disableServerCertificateValidation)
304305
&& Objects.equals(proxy, that.proxy)
305-
&& Objects.equals(proxyUrl, that.proxyUrl)
306+
&& Objects.equals(proxyAddress, that.proxyAddress)
306307
&& Objects.equals(authenticator, that.authenticator)
307308
&& Objects.equals(headers, that.headers)
308309
&& Objects.equals(certificateFilePath, that.certificateFilePath);
@@ -313,7 +314,7 @@ public int hashCode() {
313314
return Objects.hash(host, Arrays.hashCode(token), authScheme, organization,
314315
database, writePrecision, gzipThreshold,
315316
timeout, allowHttpRedirects, disableServerCertificateValidation,
316-
proxy, proxyUrl, authenticator, headers,
317+
proxy, proxyAddress, authenticator, headers,
317318
defaultTags, certificateFilePath);
318319
}
319320

@@ -329,7 +330,7 @@ public String toString() {
329330
.add("allowHttpRedirects=" + allowHttpRedirects)
330331
.add("disableServerCertificateValidation=" + disableServerCertificateValidation)
331332
.add("proxy=" + proxy)
332-
.add("proxyUrl=" + proxyUrl)
333+
.add("proxyAddress=" + proxyAddress)
333334
.add("authenticator=" + authenticator)
334335
.add("headers=" + headers)
335336
.add("defaultTags=" + defaultTags)
@@ -355,7 +356,7 @@ public static final class Builder {
355356
private Boolean allowHttpRedirects;
356357
private Boolean disableServerCertificateValidation;
357358
private ProxySelector proxy;
358-
private String proxyUrl;
359+
private InetSocketAddress proxyAddress;
359360
private Authenticator authenticator;
360361
private Map<String, String> headers;
361362
private String certificateFilePath;
@@ -511,7 +512,7 @@ public Builder disableServerCertificateValidation(@Nullable final Boolean disabl
511512
*
512513
* @param proxy Proxy selector.
513514
* @return this
514-
* Deprecated use {@link #proxyUrl}
515+
* Deprecated use {@link #proxyAddress}
515516
*/
516517
@Nonnull
517518
public Builder proxy(@Nullable final ProxySelector proxy) {
@@ -521,15 +522,15 @@ public Builder proxy(@Nullable final ProxySelector proxy) {
521522
}
522523

523524
/**
524-
* Sets the proxy url. Default is 'null'.
525+
* Sets the proxyAddress. Default is 'null'.
525526
*
526-
* @param proxyUrl Proxy url.
527+
* @param proxyAddress Proxy address.
527528
* @return this
528529
*/
529530
@Nonnull
530-
public Builder proxyUrl(@Nullable final String proxyUrl) {
531+
public Builder proxyAddress(@Nullable final InetSocketAddress proxyAddress) {
531532

532-
this.proxyUrl = proxyUrl;
533+
this.proxyAddress = proxyAddress;
533534
return this;
534535
}
535536

@@ -726,7 +727,7 @@ private ClientConfig(@Nonnull final Builder builder) {
726727
disableServerCertificateValidation = builder.disableServerCertificateValidation != null
727728
? builder.disableServerCertificateValidation : false;
728729
proxy = builder.proxy;
729-
proxyUrl = builder.proxyUrl;
730+
proxyAddress = builder.proxyAddress;
730731
authenticator = builder.authenticator;
731732
headers = builder.headers;
732733
certificateFilePath = builder.certificateFilePath;

src/main/java/com/influxdb/v3/client/internal/FlightSqlClient.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,13 @@ FlightClient createFlightClient(@Nonnull final ClientConfig config) {
171171
nettyChannelBuilder.usePlaintext();
172172
}
173173

174-
if (config.getProxyUrl() != null) {
175-
ProxyDetector proxyDetector = createProxyDetector(config.getHost(), config.getProxyUrl());
174+
if (config.getProxyAddress() != null) {
175+
ProxyDetector proxyDetector = createProxyDetector(config.getHost(), config.getProxyAddress());
176176
nettyChannelBuilder.proxyDetector(proxyDetector);
177177
}
178178

179179
if (config.getProxy() != null) {
180-
LOG.warn("proxy property will not work in query api, use proxyUrl property instead");
180+
LOG.warn("proxy property in ClientConfig will not work in query api, use proxyAddress property instead");
181181
}
182182

183183
nettyChannelBuilder.maxTraceEvents(0)
@@ -272,14 +272,13 @@ private void setChannelTypeAndEventLoop(@Nonnull final NettyChannelBuilder netty
272272
}
273273
}
274274

275-
ProxyDetector createProxyDetector(@Nonnull final String hostUrl, @Nonnull final String proxyUrl) {
276-
URI proxyUri = URI.create(proxyUrl);
275+
ProxyDetector createProxyDetector(@Nonnull final String hostUrl, @Nonnull final InetSocketAddress proxyAddress) {
277276
URI hostUri = URI.create(hostUrl);
278277
return (targetServerAddress) -> {
279278
InetSocketAddress targetAddress = (InetSocketAddress) targetServerAddress;
280279
if (hostUri.getHost().equals(targetAddress.getHostString())) {
281280
return HttpConnectProxiedSocketAddress.newBuilder()
282-
.setProxyAddress(new InetSocketAddress(proxyUri.getHost(), proxyUri.getPort()))
281+
.setProxyAddress(proxyAddress)
283282
.setTargetAddress(targetAddress)
284283
.build();
285284
}

src/main/java/com/influxdb/v3/client/internal/RestClient.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222
package com.influxdb.v3.client.internal;
2323

2424
import java.io.FileInputStream;
25-
import java.net.InetSocketAddress;
2625
import java.net.ProxySelector;
27-
import java.net.URI;
2826
import java.net.URISyntaxException;
2927
import java.net.http.HttpClient;
3028
import java.net.http.HttpRequest;
@@ -106,9 +104,8 @@ public void checkServerTrusted(
106104
// default headers
107105
this.defaultHeaders = config.getHeaders() != null ? Map.copyOf(config.getHeaders()) : null;
108106

109-
if (config.getProxyUrl() != null) {
110-
URI uri = URI.create(config.getProxyUrl());
111-
ProxySelector proxy = ProxySelector.of(new InetSocketAddress(uri.getHost(), uri.getPort()));
107+
if (config.getProxyAddress() != null) {
108+
ProxySelector proxy = ProxySelector.of(config.getProxyAddress());
112109
builder.proxy(proxy);
113110
if (config.getAuthenticator() != null) {
114111
builder.authenticator(config.getAuthenticator());

src/test/java/com/influxdb/v3/client/InfluxDBClientTest.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import java.io.IOException;
2525
import java.math.BigInteger;
26+
import java.net.InetSocketAddress;
2627
import java.net.URL;
2728
import java.net.URLConnection;
2829
import java.time.Instant;
@@ -47,10 +48,12 @@ public class InfluxDBClientTest {
4748
@EnabledIfEnvironmentVariable(named = "TESTING_INFLUXDB_DATABASE", matches = ".*")
4849
@Test
4950
void testQueryWithProxy() {
50-
String proxyUrl = "http://127.0.0.1:10000";
51+
InetSocketAddress proxyAddress = new InetSocketAddress("localhost", 10000);
52+
5153
try {
5254
// Continue to run this test only if Envoy proxy is running in this address http://127.0.0.1:10000
53-
URLConnection hpCon = new URL(proxyUrl).openConnection();
55+
String url = String.format("http://%s:%d/", proxyAddress.getHostName(), proxyAddress.getPort());
56+
URLConnection hpCon = new URL(url).openConnection();
5457
hpCon.connect();
5558
} catch (IOException e) {
5659
return;
@@ -60,7 +63,7 @@ void testQueryWithProxy() {
6063
.host(System.getenv("TESTING_INFLUXDB_URL"))
6164
.token(System.getenv("TESTING_INFLUXDB_TOKEN").toCharArray())
6265
.database(System.getenv("TESTING_INFLUXDB_DATABASE"))
63-
.proxyUrl(proxyUrl)
66+
.proxyAddress(proxyAddress)
6467
.build();
6568

6669
InfluxDBClient influxDBClient = InfluxDBClient.getInstance(clientConfig);
@@ -128,12 +131,12 @@ void disableServerCertificateValidation() throws Exception {
128131
}
129132

130133
@Test
131-
void withProxyUrl() {
132-
String proxyUrl = "http://127.0.0.1:10000";
134+
void withProxyAddress() {
135+
InetSocketAddress proxyAddress = new InetSocketAddress("127.0.0.1", 10000);
133136
ClientConfig.Builder builder = new ClientConfig.Builder();
134-
builder.proxyUrl(proxyUrl);
137+
builder.proxyAddress(proxyAddress);
135138
ClientConfig clientConfig = builder.build();
136-
Assertions.assertThat(clientConfig.getProxyUrl()).isEqualTo(proxyUrl);
139+
Assertions.assertThat(clientConfig.getProxyAddress()).isEqualTo(proxyAddress);
137140
}
138141

139142
@Test

src/test/java/com/influxdb/v3/client/internal/FlightSqlClientTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ void createProxyDetector() {
281281
.build();
282282
try (FlightSqlClient flightSqlClient = new FlightSqlClient(clientConfig)) {
283283
String hostUrl = "https://youtube.com";
284-
String proxyUrl = "https://facebook.com";
285-
ProxyDetector proxyDetector = flightSqlClient.createProxyDetector(hostUrl, proxyUrl);
284+
InetSocketAddress proxyAddress = new InetSocketAddress("localhost", 10000);
285+
ProxyDetector proxyDetector = flightSqlClient.createProxyDetector(hostUrl, proxyAddress);
286286
Assertions.assertThat(proxyDetector.proxyFor(
287287
new InetSocketAddress("142.250.198.142", 80)
288288
)).isNull();

src/test/java/com/influxdb/v3/client/internal/RestClientTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,12 @@ public void proxy() throws InterruptedException {
292292
}
293293

294294
@Test
295-
public void proxyUrl() throws InterruptedException {
295+
public void proxyAddress() throws InterruptedException {
296296
mockServer.enqueue(createResponse(200));
297297

298298
restClient = new RestClient(new ClientConfig.Builder()
299299
.host("http://foo.com:8086")
300-
.proxyUrl(String.format("http://%s:%s", mockServer.getHostName(), mockServer.getPort()))
300+
.proxyAddress(new InetSocketAddress(mockServer.getHostName(), mockServer.getPort()))
301301
.build());
302302

303303
restClient.request("ping", HttpMethod.GET, null, null, null);
@@ -316,7 +316,7 @@ public void proxyWithAuthentication() throws InterruptedException {
316316

317317
restClient = new RestClient(new ClientConfig.Builder()
318318
.host("http://foo.com:8086")
319-
.proxyUrl(String.format("http://%s:%s", mockServer.getHostName(), mockServer.getPort()))
319+
.proxyAddress(new InetSocketAddress(mockServer.getHostName(), mockServer.getPort()))
320320
.authenticator(new Authenticator() {
321321
@Override
322322
protected PasswordAuthentication getPasswordAuthentication() {

0 commit comments

Comments
 (0)