This is an automated email from the ASF dual-hosted git repository.
FrankChen021 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/druid.git
The following commit(s) were added to refs/heads/master by this push:
new 32900042d6a refactor: replace deprecated URL constructors in
production code (#20688)
32900042d6a is described below
commit 32900042d6a82ebd343fc2a330b6cd6bdf543d67
Author: Akshat Lakhera <[email protected]>
AuthorDate: Fri Oct 23 11:55:58 2026 +0530
refactor: replace deprecated URL constructors in production code (#20688)
* refactor: replace deprecated URL constructors in production code
Part of #20525
Signed-off-by: Akshat Lakhera <[email protected]>
* Add URIs.toURL helper and use it for single-string URL construction
Signed-off-by: Akshat Lakhera <[email protected]>
---------
Signed-off-by: Akshat Lakhera <[email protected]>
---
.../emitter/prometheus/PrometheusEmitter.java | 3 +-
.../druid/security/basic/CommonCacheNotifier.java | 7 +----
.../druid/catalog/sync/RestUpdateSender.java | 7 +----
.../protobuf/FileBasedProtobufBytesDecoder.java | 3 +-
.../overlord/http/OverlordRedirectInfo.java | 3 +-
.../org/apache/druid/indexer/TaskLocation.java | 5 ++--
.../org/apache/druid/java/util/common/URIs.java | 23 +++++++++++++++
.../java/util/emitter/core/HttpPostEmitter.java | 4 +--
.../http/client/pool/ChannelResourceFactory.java | 3 +-
.../apache/druid/java/util/common/URIsTest.java | 33 ++++++++++++++++++++++
.../org/apache/druid/client/DirectDruidClient.java | 6 ++--
.../druid/client/HttpServerInventoryView.java | 7 +++--
.../java/org/apache/druid/rpc/ServiceLocation.java | 14 +++++----
.../java/org/apache/druid/server/BuildInfo.java | 3 +-
.../coordination/ChangeRequestHttpSyncer.java | 2 +-
.../coordinator/loading/HttpLoadQueuePeon.java | 10 +++----
.../druid/server/http/CoordinatorRedirectInfo.java | 3 +-
.../lookup/cache/LookupCoordinatorManager.java | 24 ++++++++--------
.../schema/SystemServerPropertiesTable.java | 4 +--
19 files changed, 111 insertions(+), 53 deletions(-)
diff --git
a/extensions-contrib/prometheus-emitter/src/main/java/org/apache/druid/emitter/prometheus/PrometheusEmitter.java
b/extensions-contrib/prometheus-emitter/src/main/java/org/apache/druid/emitter/prometheus/PrometheusEmitter.java
index e73fdfcf444..56b4fadf5a4 100644
---
a/extensions-contrib/prometheus-emitter/src/main/java/org/apache/druid/emitter/prometheus/PrometheusEmitter.java
+++
b/extensions-contrib/prometheus-emitter/src/main/java/org/apache/druid/emitter/prometheus/PrometheusEmitter.java
@@ -28,6 +28,7 @@ import io.prometheus.client.Gauge;
import io.prometheus.client.Histogram;
import io.prometheus.client.exporter.HTTPServer;
import io.prometheus.client.exporter.PushGateway;
+import org.apache.druid.java.util.common.URIs;
import org.apache.druid.java.util.common.concurrent.ScheduledExecutors;
import org.apache.druid.java.util.common.logger.Logger;
import org.apache.druid.java.util.emitter.core.Emitter;
@@ -127,7 +128,7 @@ public class PrometheusEmitter implements Emitter
private static URL createURLSneakily(final String urlString)
{
try {
- return new URL(urlString);
+ return URIs.toURL(urlString);
}
catch (MalformedURLException e) {
throw new RuntimeException(e);
diff --git
a/extensions-core/druid-basic-security/src/main/java/org/apache/druid/security/basic/CommonCacheNotifier.java
b/extensions-core/druid-basic-security/src/main/java/org/apache/druid/security/basic/CommonCacheNotifier.java
index 2616c0e470b..d95df5cafe1 100644
---
a/extensions-core/druid-basic-security/src/main/java/org/apache/druid/security/basic/CommonCacheNotifier.java
+++
b/extensions-core/druid-basic-security/src/main/java/org/apache/druid/security/basic/CommonCacheNotifier.java
@@ -195,12 +195,7 @@ public class CommonCacheNotifier
private URL getListenerURL(DruidNode druidNode, String baseUrl)
{
try {
- return new URL(
- druidNode.getServiceScheme(),
- druidNode.getHost(),
- druidNode.getPortToUse(),
- baseUrl
- );
+ return druidNode.getUriToUse().resolve(baseUrl).toURL();
}
catch (MalformedURLException mue) {
LOG.error(callerName + ": Malformed url for DruidNode[%s] and
baseUrl[%s]", druidNode, baseUrl);
diff --git
a/extensions-core/druid-catalog/src/main/java/org/apache/druid/catalog/sync/RestUpdateSender.java
b/extensions-core/druid-catalog/src/main/java/org/apache/druid/catalog/sync/RestUpdateSender.java
index 71a3f13b891..cd1ea958c09 100644
---
a/extensions-core/druid-catalog/src/main/java/org/apache/druid/catalog/sync/RestUpdateSender.java
+++
b/extensions-core/druid-catalog/src/main/java/org/apache/druid/catalog/sync/RestUpdateSender.java
@@ -177,12 +177,7 @@ public class RestUpdateSender implements Consumer<byte[]>
private URL getListenerURL(DruidNode druidNode, String baseUrl)
{
try {
- return new URL(
- druidNode.getServiceScheme(),
- druidNode.getHost(),
- druidNode.getPortToUse(),
- baseUrl
- );
+ return druidNode.getUriToUse().resolve(baseUrl).toURL();
}
catch (MalformedURLException mue) {
String msg = StringUtils.format(callerName + ": Malformed url for
DruidNode [%s] and baseUrl [%s]", druidNode, baseUrl);
diff --git
a/extensions-core/protobuf-extensions/src/main/java/org/apache/druid/data/input/protobuf/FileBasedProtobufBytesDecoder.java
b/extensions-core/protobuf-extensions/src/main/java/org/apache/druid/data/input/protobuf/FileBasedProtobufBytesDecoder.java
index 1f5b19ab0b6..bceaa5d6030 100644
---
a/extensions-core/protobuf-extensions/src/main/java/org/apache/druid/data/input/protobuf/FileBasedProtobufBytesDecoder.java
+++
b/extensions-core/protobuf-extensions/src/main/java/org/apache/druid/data/input/protobuf/FileBasedProtobufBytesDecoder.java
@@ -23,6 +23,7 @@ import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Preconditions;
import com.google.protobuf.DescriptorProtos;
+import org.apache.druid.java.util.common.URIs;
import org.apache.druid.java.util.common.parsers.ParseException;
import java.io.IOException;
@@ -65,7 +66,7 @@ public class FileBasedProtobufBytesDecoder extends
DescriptorBasedProtobufBytesD
if (fin == null) {
URL url;
try {
- url = new URL(descriptorFilePath);
+ url = URIs.toURL(descriptorFilePath);
}
catch (MalformedURLException e) {
throw new ParseException(
diff --git
a/indexing-service/src/main/java/org/apache/druid/indexing/overlord/http/OverlordRedirectInfo.java
b/indexing-service/src/main/java/org/apache/druid/indexing/overlord/http/OverlordRedirectInfo.java
index 41e1ef8b7c9..b87e02262a0 100644
---
a/indexing-service/src/main/java/org/apache/druid/indexing/overlord/http/OverlordRedirectInfo.java
+++
b/indexing-service/src/main/java/org/apache/druid/indexing/overlord/http/OverlordRedirectInfo.java
@@ -24,6 +24,7 @@ import com.google.common.collect.ImmutableSet;
import com.google.inject.Inject;
import org.apache.druid.indexing.overlord.DruidOverlord;
import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.URIs;
import org.apache.druid.server.http.RedirectInfo;
import java.net.URL;
@@ -66,7 +67,7 @@ public class OverlordRedirectInfo implements RedirectInfo
location = StringUtils.format("%s?%s", location, queryString);
}
- return new URL(location);
+ return URIs.toURL(location);
}
catch (Exception e) {
throw new RuntimeException(e);
diff --git
a/processing/src/main/java/org/apache/druid/indexer/TaskLocation.java
b/processing/src/main/java/org/apache/druid/indexer/TaskLocation.java
index 2992814de45..21e3e2ad611 100644
--- a/processing/src/main/java/org/apache/druid/indexer/TaskLocation.java
+++ b/processing/src/main/java/org/apache/druid/indexer/TaskLocation.java
@@ -25,6 +25,7 @@ import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.net.HostAndPort;
import org.apache.druid.java.util.common.IAE;
+import org.apache.druid.java.util.common.URIs;
import javax.annotation.Nullable;
import java.net.MalformedURLException;
@@ -140,8 +141,8 @@ public class TaskLocation
throw new IAE("Path must start with '/'");
}
- // Use URL constructor, not URI, since the path is already encoded.
- return new URL(scheme, host, portToUse, encodedPathAndQueryString);
+ // Build the URI from a string rather than the multi-arg URI constructors,
since the path is already encoded.
+ return URIs.toURL(scheme + "://" + HostAndPort.fromParts(host, portToUse)
+ encodedPathAndQueryString);
}
@Override
diff --git
a/processing/src/main/java/org/apache/druid/java/util/common/URIs.java
b/processing/src/main/java/org/apache/druid/java/util/common/URIs.java
index f2476e71f09..6af49a8e986 100644
--- a/processing/src/main/java/org/apache/druid/java/util/common/URIs.java
+++ b/processing/src/main/java/org/apache/druid/java/util/common/URIs.java
@@ -21,7 +21,9 @@ package org.apache.druid.java.util.common;
import com.google.common.base.Preconditions;
+import java.net.MalformedURLException;
import java.net.URI;
+import java.net.URL;
public final class URIs
{
@@ -37,6 +39,27 @@ public final class URIs
}
}
+ /**
+ * Converts a string to a {@link URL}. This is the replacement for the
deprecated {@code new URL(String)}
+ * constructor: it reports every malformed input as a {@link
MalformedURLException}, whereas
+ * {@code URI.create(value).toURL()} throws an unchecked {@link
IllegalArgumentException} for a string that is
+ * not a valid URI.
+ *
+ * @throws MalformedURLException if the string is not a valid URI or cannot
be converted to a URL. The cause is an
+ * {@link IllegalArgumentException} when the
string is not a valid URI.
+ */
+ public static URL toURL(final String value) throws MalformedURLException
+ {
+ try {
+ return URI.create(value).toURL();
+ }
+ catch (IllegalArgumentException e) {
+ final MalformedURLException exception = new
MalformedURLException("Invalid URL [" + value + "]");
+ exception.initCause(e);
+ throw exception;
+ }
+ }
+
private URIs()
{
}
diff --git
a/processing/src/main/java/org/apache/druid/java/util/emitter/core/HttpPostEmitter.java
b/processing/src/main/java/org/apache/druid/java/util/emitter/core/HttpPostEmitter.java
index 5006e025ed3..7eba26037f2 100644
---
a/processing/src/main/java/org/apache/druid/java/util/emitter/core/HttpPostEmitter.java
+++
b/processing/src/main/java/org/apache/druid/java/util/emitter/core/HttpPostEmitter.java
@@ -28,6 +28,7 @@ import org.apache.druid.concurrent.ConcurrentAwaitableCounter;
import org.apache.druid.java.util.common.ISE;
import org.apache.druid.java.util.common.RetryUtils;
import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.URIs;
import org.apache.druid.java.util.common.lifecycle.LifecycleStart;
import org.apache.druid.java.util.common.lifecycle.LifecycleStop;
import org.apache.druid.java.util.common.logger.Logger;
@@ -41,7 +42,6 @@ import java.io.Closeable;
import java.io.Flushable;
import java.io.IOException;
import java.net.MalformedURLException;
-import java.net.URL;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
@@ -170,7 +170,7 @@ public class HttpPostEmitter implements Flushable,
Closeable, Emitter
this.client = client;
this.jsonMapper = jsonMapper;
try {
- this.url = new URL(config.getRecipientBaseUrl()).toString();
+ this.url = URIs.toURL(config.getRecipientBaseUrl()).toString();
}
catch (MalformedURLException e) {
throw new ISE(e, "Bad URL: %s", config.getRecipientBaseUrl());
diff --git
a/processing/src/main/java/org/apache/druid/java/util/http/client/pool/ChannelResourceFactory.java
b/processing/src/main/java/org/apache/druid/java/util/http/client/pool/ChannelResourceFactory.java
index aed39a11b85..bc1cf805f71 100644
---
a/processing/src/main/java/org/apache/druid/java/util/http/client/pool/ChannelResourceFactory.java
+++
b/processing/src/main/java/org/apache/druid/java/util/http/client/pool/ChannelResourceFactory.java
@@ -40,6 +40,7 @@ import io.netty.handler.codec.http.HttpVersion;
import io.netty.handler.codec.http.LastHttpContent;
import io.netty.handler.ssl.SslHandler;
import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.URIs;
import org.apache.druid.java.util.common.logger.Logger;
import org.apache.druid.java.util.http.client.HttpClientProxyConfig;
import org.apache.druid.java.util.http.client.Request;
@@ -89,7 +90,7 @@ public class ChannelResourceFactory implements
ResourceFactory<String, ChannelFu
log.debug("Generating: %s", hostname);
URL url;
try {
- url = new URL(hostname);
+ url = URIs.toURL(hostname);
}
catch (MalformedURLException e) {
throw new RuntimeException(e);
diff --git
a/processing/src/test/java/org/apache/druid/java/util/common/URIsTest.java
b/processing/src/test/java/org/apache/druid/java/util/common/URIsTest.java
index e5a0af3ad1b..1cf47c276b9 100644
--- a/processing/src/test/java/org/apache/druid/java/util/common/URIsTest.java
+++ b/processing/src/test/java/org/apache/druid/java/util/common/URIsTest.java
@@ -22,7 +22,9 @@ package org.apache.druid.java.util.common;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import java.net.MalformedURLException;
import java.net.URI;
+import java.net.URL;
public class URIsTest
{
@@ -67,4 +69,35 @@ public class URIsTest
Assertions.assertEquals("127.0.0.1", uri.getHost());
Assertions.assertEquals(8000, uri.getPort());
}
+
+ @Test
+ public void testToURL() throws MalformedURLException
+ {
+ final URL url = URIs.toURL("https://127.0.0.1:8000/test/path?test-query");
+
+ Assertions.assertEquals("https", url.getProtocol());
+ Assertions.assertEquals("127.0.0.1", url.getHost());
+ Assertions.assertEquals(8000, url.getPort());
+ Assertions.assertEquals("/test/path", url.getPath());
+ Assertions.assertEquals("test-query", url.getQuery());
+ }
+
+ @Test
+ public void testToURLInvalidUri()
+ {
+ final MalformedURLException e = Assertions.assertThrows(
+ MalformedURLException.class,
+ () -> URIs.toURL("http://bad host/path")
+ );
+
+ Assertions.assertEquals("Invalid URL [http://bad host/path]",
e.getMessage());
+ Assertions.assertInstanceOf(IllegalArgumentException.class, e.getCause());
+ }
+
+ @Test
+ public void testToURLNotAbsolute()
+ {
+ // A relative URI is valid, but cannot be converted to a URL; new
URL(String) also threw MalformedURLException.
+ Assertions.assertThrows(MalformedURLException.class, () ->
URIs.toURL("/relative/path"));
+ }
}
diff --git
a/server/src/main/java/org/apache/druid/client/DirectDruidClient.java
b/server/src/main/java/org/apache/druid/client/DirectDruidClient.java
index 151c0b928c7..5ccd7cb6fce 100644
--- a/server/src/main/java/org/apache/druid/client/DirectDruidClient.java
+++ b/server/src/main/java/org/apache/druid/client/DirectDruidClient.java
@@ -35,6 +35,7 @@ import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpResponse;
import org.apache.druid.java.util.common.RE;
import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.URIs;
import org.apache.druid.java.util.common.concurrent.Execs;
import org.apache.druid.java.util.common.guava.BaseSequence;
import org.apache.druid.java.util.common.guava.Sequence;
@@ -74,7 +75,6 @@ import javax.ws.rs.core.MediaType;
import java.io.IOException;
import java.io.InputStream;
import java.io.SequenceInputStream;
-import java.net.URL;
import java.util.Enumeration;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutionException;
@@ -780,7 +780,7 @@ public class DirectDruidClient<T> implements QueryRunner<T>
future = httpClient.go(
new Request(
HttpMethod.POST,
- new URL(url)
+ URIs.toURL(url)
).setContent(objectMapper.writeValueAsBytes(Queries.withTimeout(query,
timeLeft)))
.setHeader(
HttpHeaders.Names.CONTENT_TYPE,
@@ -867,7 +867,7 @@ public class DirectDruidClient<T> implements QueryRunner<T>
Runnable cancelRunnable = () -> {
try {
Future<StatusResponseHolder> responseFuture = httpClient.go(
- new Request(HttpMethod.DELETE, new URL(cancelUrl))
+ new Request(HttpMethod.DELETE, URIs.toURL(cancelUrl))
.setContent(objectMapper.writeValueAsBytes(query))
.setHeader(HttpHeaders.Names.CONTENT_TYPE, isSmile ?
SmileMediaTypes.APPLICATION_JACKSON_SMILE : MediaType.APPLICATION_JSON),
StatusResponseHandler.getInstance(),
diff --git
a/server/src/main/java/org/apache/druid/client/HttpServerInventoryView.java
b/server/src/main/java/org/apache/druid/client/HttpServerInventoryView.java
index ea81900ad4f..3ad3074c926 100644
--- a/server/src/main/java/org/apache/druid/client/HttpServerInventoryView.java
+++ b/server/src/main/java/org/apache/druid/client/HttpServerInventoryView.java
@@ -66,7 +66,8 @@ import org.joda.time.Duration;
import javax.annotation.Nullable;
import java.net.MalformedURLException;
-import java.net.URL;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -550,7 +551,7 @@ public class HttpServerInventoryView implements
ServerInventoryView, FilteredSer
smileMapper,
httpClient,
inventorySyncExecutor,
- new URL(druidServer.getScheme(), hostAndPort.getHost(),
hostAndPort.getPort(), "/"),
+ new URI(druidServer.getScheme(), null, hostAndPort.getHost(),
hostAndPort.getPort(), "/", null, null).toURL(),
"/druid-internal/v1/segments",
SEGMENT_LIST_RESP_TYPE_REF,
config.getServerTimeout(),
@@ -558,7 +559,7 @@ public class HttpServerInventoryView implements
ServerInventoryView, FilteredSer
createSyncListener()
);
}
- catch (MalformedURLException ex) {
+ catch (MalformedURLException | URISyntaxException ex) {
throw new IAE(ex, "Failed to construct server URL.");
}
}
diff --git a/server/src/main/java/org/apache/druid/rpc/ServiceLocation.java
b/server/src/main/java/org/apache/druid/rpc/ServiceLocation.java
index 971e6554d02..cfe34764768 100644
--- a/server/src/main/java/org/apache/druid/rpc/ServiceLocation.java
+++ b/server/src/main/java/org/apache/druid/rpc/ServiceLocation.java
@@ -22,9 +22,11 @@ package org.apache.druid.rpc;
import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
+import com.google.common.net.HostAndPort;
import jakarta.validation.constraints.NotNull;
import org.apache.druid.java.util.common.IAE;
import org.apache.druid.java.util.common.ISE;
+import org.apache.druid.java.util.common.URIs;
import org.apache.druid.server.DruidNode;
import org.apache.druid.server.coordination.DruidServerMetadata;
@@ -213,11 +215,13 @@ public class ServiceLocation
}
try {
- return new URL(
- scheme,
- host,
- portToUse,
- basePath + (encodedPathAndQueryString == null ? "" :
encodedPathAndQueryString)
+ // Build the URI from a string rather than the multi-arg URI
constructors, since the path is already encoded.
+ return URIs.toURL(
+ scheme
+ + "://"
+ + HostAndPort.fromParts(host, portToUse)
+ + basePath
+ + (encodedPathAndQueryString == null ? "" :
encodedPathAndQueryString)
);
}
catch (MalformedURLException e) {
diff --git a/server/src/main/java/org/apache/druid/server/BuildInfo.java
b/server/src/main/java/org/apache/druid/server/BuildInfo.java
index 0f794a94272..2da6de7c386 100644
--- a/server/src/main/java/org/apache/druid/server/BuildInfo.java
+++ b/server/src/main/java/org/apache/druid/server/BuildInfo.java
@@ -19,6 +19,7 @@
package org.apache.druid.server;
+import org.apache.druid.java.util.common.URIs;
import org.apache.druid.java.util.common.logger.Logger;
import java.io.IOException;
@@ -50,7 +51,7 @@ public class BuildInfo
if (classUrl != null && "jar".equals(classUrl.getProtocol())) {
String classPath = classUrl.toString();
String manifestPath = classPath.substring(0,
classPath.lastIndexOf('!') + 1) + "/META-INF/MANIFEST.MF";
- try (InputStream is = new URL(manifestPath).openStream()) {
+ try (InputStream is = URIs.toURL(manifestPath).openStream()) {
return readRevisionFromManifest(is);
}
}
diff --git
a/server/src/main/java/org/apache/druid/server/coordination/ChangeRequestHttpSyncer.java
b/server/src/main/java/org/apache/druid/server/coordination/ChangeRequestHttpSyncer.java
index fdfb9cf24c5..5e63511092c 100644
---
a/server/src/main/java/org/apache/druid/server/coordination/ChangeRequestHttpSyncer.java
+++
b/server/src/main/java/org/apache/druid/server/coordination/ChangeRequestHttpSyncer.java
@@ -246,7 +246,7 @@ public class ChangeRequestHttpSyncer<T>
log.debug("Sending sync request to server[%s]", logIdentity);
ListenableFuture<InputStream> syncRequestFuture = httpClient.go(
- new Request(HttpMethod.GET, new URL(baseServerURL, req))
+ new Request(HttpMethod.GET,
baseServerURL.toURI().resolve(req).toURL())
.addHeader(HttpHeaders.Names.ACCEPT,
SmileMediaTypes.APPLICATION_JACKSON_SMILE)
.addHeader(HttpHeaders.Names.CONTENT_TYPE,
SmileMediaTypes.APPLICATION_JACKSON_SMILE),
responseHandler,
diff --git
a/server/src/main/java/org/apache/druid/server/coordinator/loading/HttpLoadQueuePeon.java
b/server/src/main/java/org/apache/druid/server/coordinator/loading/HttpLoadQueuePeon.java
index a3a2af4a71a..5d1953f6ec1 100644
---
a/server/src/main/java/org/apache/druid/server/coordinator/loading/HttpLoadQueuePeon.java
+++
b/server/src/main/java/org/apache/druid/server/coordinator/loading/HttpLoadQueuePeon.java
@@ -60,6 +60,7 @@ import javax.ws.rs.core.MediaType;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
+import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
@@ -180,7 +181,7 @@ public class HttpLoadQueuePeon implements LoadQueuePeon
private URL getLoadCapabilitiesUrl() throws MalformedURLException
{
- return new URL(new URL(serverId),
"druid-internal/v1/segments/loadCapabilities");
+ return
URI.create(serverId).resolve("/druid-internal/v1/segments/loadCapabilities").toURL();
}
/**
@@ -385,14 +386,13 @@ public class HttpLoadQueuePeon implements LoadQueuePeon
loadingRateTracker.markBatchLoadingStarted();
}
- final URL changeRequestURL = new URL(
- new URL(serverId),
+ final URL changeRequestURL = URI.create(serverId).resolve(
StringUtils.nonStrictFormat(
-
"druid-internal/v1/segments/changeRequests?timeout=%d&loadingMode=%s",
+
"/druid-internal/v1/segments/changeRequests?timeout=%d&loadingMode=%s",
config.getHostTimeout().getMillis(),
loadingMode
)
- );
+ ).toURL();
BytesAccumulatingResponseHandler responseHandler = new
BytesAccumulatingResponseHandler();
ListenableFuture<InputStream> future = httpClient.go(
diff --git
a/server/src/main/java/org/apache/druid/server/http/CoordinatorRedirectInfo.java
b/server/src/main/java/org/apache/druid/server/http/CoordinatorRedirectInfo.java
index 987ccb94842..ea54b7d80c0 100644
---
a/server/src/main/java/org/apache/druid/server/http/CoordinatorRedirectInfo.java
+++
b/server/src/main/java/org/apache/druid/server/http/CoordinatorRedirectInfo.java
@@ -22,6 +22,7 @@ package org.apache.druid.server.http;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Inject;
import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.URIs;
import org.apache.druid.server.coordinator.DruidCoordinator;
import java.net.URL;
@@ -65,7 +66,7 @@ public class CoordinatorRedirectInfo implements RedirectInfo
location = StringUtils.format("%s?%s", location, queryString);
}
- return new URL(location);
+ return URIs.toURL(location);
}
catch (Exception e) {
throw new RuntimeException(e);
diff --git
a/server/src/main/java/org/apache/druid/server/lookup/cache/LookupCoordinatorManager.java
b/server/src/main/java/org/apache/druid/server/lookup/cache/LookupCoordinatorManager.java
index 26a9de4ae51..c9eda61444b 100644
---
a/server/src/main/java/org/apache/druid/server/lookup/cache/LookupCoordinatorManager.java
+++
b/server/src/main/java/org/apache/druid/server/lookup/cache/LookupCoordinatorManager.java
@@ -50,6 +50,7 @@ import org.apache.druid.java.util.common.IOE;
import org.apache.druid.java.util.common.ISE;
import org.apache.druid.java.util.common.StreamUtils;
import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.URIs;
import org.apache.druid.java.util.common.concurrent.Execs;
import org.apache.druid.java.util.emitter.EmittingLogger;
import org.apache.druid.java.util.http.client.HttpClient;
@@ -724,22 +725,21 @@ public class LookupCoordinatorManager
static URL getLookupsURL(HostAndPortWithScheme druidNode) throws
MalformedURLException
{
- return new URL(
- druidNode.getScheme(),
- druidNode.getHostText(),
- druidNode.getPortOrDefault(-1),
- LOOKUP_BASE_REQUEST_PATH
- );
+ return lookupsURL(druidNode, LOOKUP_BASE_REQUEST_PATH);
}
static URL getLookupsUpdateURL(HostAndPortWithScheme druidNode) throws
MalformedURLException
{
- return new URL(
- druidNode.getScheme(),
- druidNode.getHostText(),
- druidNode.getPortOrDefault(-1),
- LOOKUP_UPDATE_REQUEST_PATH
- );
+ return lookupsURL(druidNode, LOOKUP_UPDATE_REQUEST_PATH);
+ }
+
+ private static URL lookupsURL(HostAndPortWithScheme druidNode, String path)
throws MalformedURLException
+ {
+ final int port = druidNode.getPortOrDefault(-1);
+ final String hostAndPort = port < 0
+ ?
HostAndPort.fromHost(druidNode.getHostText()).toString()
+ :
HostAndPort.fromParts(druidNode.getHostText(), port).toString();
+ return URIs.toURL(druidNode.getScheme() + "://" + hostAndPort + path);
}
private static boolean httpStatusIsSuccess(int statusCode)
diff --git
a/sql/src/main/java/org/apache/druid/sql/calcite/schema/SystemServerPropertiesTable.java
b/sql/src/main/java/org/apache/druid/sql/calcite/schema/SystemServerPropertiesTable.java
index bf8e74c1050..2dff95c20f4 100644
---
a/sql/src/main/java/org/apache/druid/sql/calcite/schema/SystemServerPropertiesTable.java
+++
b/sql/src/main/java/org/apache/druid/sql/calcite/schema/SystemServerPropertiesTable.java
@@ -34,6 +34,7 @@ import org.apache.calcite.schema.impl.AbstractTable;
import org.apache.druid.discovery.DiscoveryDruidNode;
import org.apache.druid.discovery.DruidNodeDiscoveryProvider;
import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.URIs;
import org.apache.druid.java.util.common.logger.Logger;
import org.apache.druid.java.util.http.client.HttpClient;
import org.apache.druid.java.util.http.client.Request;
@@ -48,7 +49,6 @@ import org.apache.druid.sql.calcite.table.RowSignatures;
import javax.annotation.Nullable;
import javax.servlet.http.HttpServletResponse;
-import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
@@ -192,7 +192,7 @@ public class SystemServerPropertiesTable extends
AbstractTable implements Projec
{
final String url =
druidNode.getUriToUse().resolve("/status/properties").toString();
try {
- final Request request = new Request(HttpMethod.GET, new URL(url));
+ final Request request = new Request(HttpMethod.GET, URIs.toURL(url));
final StringFullResponseHolder response;
response = httpClient
.go(request, new StringFullResponseHandler(StandardCharsets.UTF_8))
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]