This is an automated email from the ASF dual-hosted git repository.
sanjaydutt pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/branch_9x by this push:
new 9bd991fd101 [branch_9x] SOLR-17321: Remove Deprecated URL ctors in
Preparation for Java 21 (#2528)
9bd991fd101 is described below
commit 9bd991fd10193238dd312854d32dfe277131b4f0
Author: Sanjay Dutt <[email protected]>
AuthorDate: Thu Aug 22 20:20:59 2024 +0530
[branch_9x] SOLR-17321: Remove Deprecated URL ctors in Preparation for
Java 21 (#2528)
* SOLR-17321: Remove Deprecated URL ctors in Preparation for Java 21
(#2501)
* Switch to URI
* Added URL to the forbidden API
-------------
Co-authored-by: Uwe Schindler <[email protected]>
Co-authored-by: David Smiley <[email protected]>
(cherry picked from commit 2a56bfc2d8b48d1c93d683515569e2e97acf2077)
---
gradle/validation/forbidden-apis/defaults.all.txt | 3 +
solr/CHANGES.txt | 5 +-
.../src/java/org/apache/solr/cli/PostTool.java | 65 ++++++++++------------
.../java/org/apache/solr/cli/RunExampleTool.java | 6 +-
.../java/org/apache/solr/cli/SimplePostTool.java | 61 ++++++++++----------
.../core/src/java/org/apache/solr/cli/SolrCLI.java | 2 +-
.../src/java/org/apache/solr/cli/StatusTool.java | 4 +-
.../solr/handler/admin/AdminHandlersProxy.java | 6 +-
.../packagemanager/DefaultPackageRepository.java | 7 ++-
.../solr/packagemanager/RepositoryManager.java | 4 +-
.../solr/schema/OpenExchangeRatesOrgProvider.java | 4 +-
.../apache/solr/security/AllowListUrlChecker.java | 8 +--
.../org/apache/solr/security/SolrNodeKeyPair.java | 5 +-
.../apache/solr/servlet/SolrRequestParsers.java | 4 +-
.../update/processor/URLClassifyProcessor.java | 2 +-
.../src/test/org/apache/solr/cli/PostToolTest.java | 38 ++++++++-----
.../org/apache/solr/cli/SimplePostToolTest.java | 31 ++++++-----
.../org/apache/solr/cloud/OverseerRolesTest.java | 4 +-
.../solr/cloud/TestPullReplicaErrorHandling.java | 19 +++----
.../apache/solr/cloud/TestRequestForwarding.java | 10 +++-
.../apache/solr/handler/ReplicationTestHelper.java | 5 +-
.../solr/handler/TestReplicationHandler.java | 3 +-
.../solr/handler/TestReplicationHandlerBackup.java | 3 +-
.../apache/solr/request/TestRemoteStreaming.java | 4 +-
.../transform/TestSubQueryTransformerDistrib.java | 14 +++--
.../solr/security/AuditLoggerIntegrationTest.java | 4 +-
.../apache/solr/servlet/HttpSolrCallCloudTest.java | 5 +-
.../apache/solr/security/jwt/JWTIssuerConfig.java | 7 ++-
.../security/jwt/JWTAuthPluginIntegrationTest.java | 7 ++-
.../solr/client/solrj/impl/LBSolrClient.java | 8 +--
.../apache/solr/client/solrj/util/ClientUtils.java | 8 +--
.../solr/client/solrj/TestSolrJErrorHandling.java | 3 +-
.../client/solrj/embedded/JettyWebappTest.java | 5 +-
.../solrj/impl/CloudHttp2SolrClientTest.java | 6 +-
.../client/solrj/impl/CloudSolrClientTest.java | 6 +-
.../apache/solr/common/util/ContentStreamTest.java | 13 ++---
.../org/apache/solr/embedded/JettySolrRunner.java | 14 ++++-
.../apache/solr/handler/BackupRestoreUtils.java | 65 ++++++++++++----------
.../apache/solr/handler/TestRestoreCoreUtil.java | 3 +-
39 files changed, 253 insertions(+), 218 deletions(-)
diff --git a/gradle/validation/forbidden-apis/defaults.all.txt
b/gradle/validation/forbidden-apis/defaults.all.txt
index a7647ddbcb7..f1220bfcd05 100644
--- a/gradle/validation/forbidden-apis/defaults.all.txt
+++ b/gradle/validation/forbidden-apis/defaults.all.txt
@@ -83,3 +83,6 @@ java.util.logging.**
@defaultMessage Use List.sort(Comparator) instead of Collections.sort(List,
Comparator) please.
java.util.Collections#sort(java.util.List, java.util.Comparator)
+
+@defaultMessage Use URI.toURL() to construct an instance of URL.
+java.net.URL#<init>(**)
\ No newline at end of file
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index a07e060c70c..d74bac4c0f9 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -40,7 +40,7 @@ Dependency Upgrades
Other Changes
---------------------
-(No changes)
+* SOLR-17321: Remove Deprecated URL and replace it with URI in Preparation for
Java 21 (Sanjay Dutt, David Smiley, Uwe Schindler)
================== 9.7.0 ==================
New Features
@@ -192,6 +192,8 @@ Other Changes
* SOLR-16503: Use Jetty HTTP2 for SyncStrategy and PeerSyncWithLeader for
"recovery" operations (Sanjay Dutt, David Smiley)
+* SOLR-16796: Include cyclonedx SBOMs with maven artifacts (Arnout Engelen,
Houston Putman, Kevin Risden)
+
* PR#2524: QueryResult refactoring so that it's only returned from
SolrIndexSearcher instead of
being provided to it. Deprecated APIs in 9x; should be removed later.
(David Smiley)
@@ -205,6 +207,7 @@ Other Changes
* SOLR-16996: Update Solr Exporter for Prometheus cli to use commons-cli
instead of argparse4j. (Christos Malliaridis via Eric Pugh)
+>>>>>>> origin/branch_9x
================== 9.6.1 ==================
Bug Fixes
diff --git a/solr/core/src/java/org/apache/solr/cli/PostTool.java
b/solr/core/src/java/org/apache/solr/cli/PostTool.java
index 26e9b2999c3..e44d03481c8 100644
--- a/solr/core/src/java/org/apache/solr/cli/PostTool.java
+++ b/solr/core/src/java/org/apache/solr/cli/PostTool.java
@@ -97,7 +97,7 @@ public class PostTool extends ToolBase {
int recursive = 0;
int delay = 0;
String fileTypes = PostTool.DEFAULT_FILE_TYPES;
- URL solrUpdateUrl;
+ URI solrUpdateUrl;
String credentials;
OutputStream out = null;
String type;
@@ -272,12 +272,13 @@ public class PostTool extends ToolBase {
SolrCLI.raiseLogLevelUnlessVerbose(cli);
solrUpdateUrl = null;
+
if (cli.hasOption("solr-update-url")) {
String url = cli.getOptionValue("solr-update-url");
- solrUpdateUrl = new URI(url).toURL();
+ solrUpdateUrl = new URI(url);
} else if (cli.hasOption("name")) {
String url = SolrCLI.getDefaultSolrUrl() + "/solr/" +
cli.getOptionValue("name") + "/update";
- solrUpdateUrl = new URI(url).toURL();
+ solrUpdateUrl = new URI(url);
} else {
throw new IllegalArgumentException(
"Must specify either --solr-update-url or -c parameter to post
documents.");
@@ -403,7 +404,7 @@ public class PostTool extends ToolBase {
numPagesPosted = postWebPages(args, 0, out);
info(numPagesPosted + " web pages indexed.");
- } catch (MalformedURLException e) {
+ } catch (URISyntaxException e) {
warn("Wrong URL trying to append /extract to " + solrUpdateUrl);
}
}
@@ -529,7 +530,7 @@ public class PostTool extends ToolBase {
postFile(srcFile, out, type);
Thread.sleep(delay * 1000L);
filesPosted++;
- } catch (InterruptedException | MalformedURLException e) {
+ } catch (InterruptedException | URISyntaxException e) {
throw new RuntimeException(e);
}
}
@@ -637,8 +638,8 @@ public class PostTool extends ToolBase {
PostTool.PageFetcherResult result = pageFetcher.readPageFromUrl(url);
if (result.httpStatus == 200) {
url = (result.redirectUrl != null) ? result.redirectUrl : url;
- URL postUrl =
- new URL(
+ URI postUri =
+ new URI(
appendParam(
solrUpdateUrl.toString(),
"literal.id="
@@ -652,7 +653,7 @@ public class PostTool extends ToolBase {
null,
out,
result.contentType,
- postUrl);
+ postUri);
if (success) {
info("POSTed web resource " + url + " (depth: " + level + ")");
Thread.sleep(delay * 1000L);
@@ -665,7 +666,7 @@ public class PostTool extends ToolBase {
new ByteArrayInputStream(
content.array(), content.arrayOffset(),
content.limit()),
result.contentType,
- postUrl);
+ postUri);
subStack.addAll(children);
}
} else {
@@ -814,10 +815,10 @@ public class PostTool extends ToolBase {
}
/** Opens the file and posts its contents to the solrUrl, writes to response
to output. */
- public void postFile(File file, OutputStream output, String type) throws
MalformedURLException {
+ public void postFile(File file, OutputStream output, String type) throws
URISyntaxException {
InputStream is = null;
- URL url = solrUpdateUrl;
+ URI uri = solrUpdateUrl;
String suffix = "";
if (auto) {
if (type == null) {
@@ -829,7 +830,7 @@ public class PostTool extends ToolBase {
if (type.equals("application/json") &&
!PostTool.FORMAT_SOLR.equals(format)) {
suffix = "/json/docs";
String urlStr = appendUrlPath(solrUpdateUrl, suffix).toString();
- url = new URL(urlStr);
+ uri = new URI(urlStr);
} else if (type.equals("application/xml")
|| type.equals("text/csv")
|| type.equals("application/json")) {
@@ -847,7 +848,7 @@ public class PostTool extends ToolBase {
urlStr =
appendParam(urlStr, "literal.id=" +
URLEncoder.encode(file.getAbsolutePath(), UTF_8));
}
- url = new URL(urlStr);
+ uri = new URI(urlStr);
}
} else {
if (type == null) {
@@ -870,7 +871,7 @@ public class PostTool extends ToolBase {
+ " to [base]"
+ suffix);
is = new FileInputStream(file);
- postData(is, file.length(), output, type, url);
+ postData(is, file.length(), output, type, uri);
} catch (IOException e) {
warn("Can't open/read file: " + file);
} finally {
@@ -888,18 +889,13 @@ public class PostTool extends ToolBase {
/**
* Appends to the path of the URL
*
- * @param url the URL
+ * @param uri the URI
* @param append the path to append
* @return the final URL version
*/
- protected static URL appendUrlPath(URL url, String append) throws
MalformedURLException {
- return new URL(
- url.getProtocol()
- + "://"
- + url.getAuthority()
- + url.getPath()
- + append
- + (url.getQuery() != null ? "?" + url.getQuery() : ""));
+ protected static URI appendUrlPath(URI uri, String append) throws
URISyntaxException {
+ var newPath = uri.getPath() + append;
+ return new URI(uri.getScheme(), uri.getAuthority(), newPath,
uri.getQuery(), uri.getFragment());
}
/**
@@ -922,15 +918,15 @@ public class PostTool extends ToolBase {
* @return true if success
*/
public boolean postData(
- InputStream data, Long length, OutputStream output, String type, URL
url) {
+ InputStream data, Long length, OutputStream output, String type, URI
uri) {
if (dryRun) {
return true;
}
if (params.length() > 0) {
try {
- url = new URL(appendParam(url.toString(), params));
- } catch (MalformedURLException e) {
+ uri = new URI(appendParam(uri.toString(), params));
+ } catch (URISyntaxException e) {
warn("Malformed params");
}
}
@@ -942,7 +938,7 @@ public class PostTool extends ToolBase {
HttpURLConnection urlConnection = null;
try {
try {
- urlConnection = (HttpURLConnection) url.openConnection();
+ urlConnection = (HttpURLConnection) (uri.toURL()).openConnection();
try {
urlConnection.setRequestMethod("POST");
} catch (ProtocolException e) {
@@ -1239,9 +1235,9 @@ public class PostTool extends ToolBase {
disallows = new ArrayList<>();
URL urlRobot;
try {
- urlRobot = new URL(strRobot);
+ urlRobot = new URI(strRobot).toURL();
disallows = parseRobotsTxt(urlRobot.openStream());
- } catch (MalformedURLException e) {
+ } catch (URISyntaxException | MalformedURLException e) {
return true; // We cannot trust this robots URL, should not happen
} catch (IOException e) {
// There is no robots.txt, will cache an empty disallow list
@@ -1289,17 +1285,16 @@ public class PostTool extends ToolBase {
* @param url the URL of the web page
* @param is the input stream of the page
* @param type the content-type
- * @param postUrl the URL (typically /solr/extract) in order to pull out
links
+ * @param postUri the URI (typically /solr/extract) in order to pull out
links
* @return a set of URIs parsed from the page
*/
- protected Set<URI> getLinksFromWebPage(URL url, InputStream is, String
type, URL postUrl) {
+ protected Set<URI> getLinksFromWebPage(URL url, InputStream is, String
type, URI postUri) {
Set<URI> linksFromPage = new HashSet<>();
try {
ByteArrayOutputStream os = new ByteArrayOutputStream();
- URL extractUrl = new URL(appendParam(postUrl.toString(),
"extractOnly=true"));
- extractUrl = new URL(appendParam(extractUrl.toString(), "wt=xml"));
- boolean success = postData(is, null, os, type, extractUrl);
+ URI extractUri = new URI(appendParam(postUri.toString(),
"extractOnly=true"));
+ boolean success = postData(is, null, os, type, extractUri);
if (success) {
Document d = makeDom(os.toByteArray());
String innerXml = getXP(d, "/response/str/text()[1]", false);
@@ -1318,7 +1313,7 @@ public class PostTool extends ToolBase {
}
}
}
- } catch (MalformedURLException e) {
+ } catch (URISyntaxException e) {
warn("Malformed URL " + url);
} catch (IOException e) {
warn("IOException opening URL " + url + ": " + e.getMessage());
diff --git a/solr/core/src/java/org/apache/solr/cli/RunExampleTool.java
b/solr/core/src/java/org/apache/solr/cli/RunExampleTool.java
index e4f24c478aa..9b16a5f9390 100644
--- a/solr/core/src/java/org/apache/solr/cli/RunExampleTool.java
+++ b/solr/core/src/java/org/apache/solr/cli/RunExampleTool.java
@@ -22,7 +22,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.net.Socket;
-import java.net.URL;
+import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.Arrays;
@@ -874,7 +874,7 @@ public class RunExampleTool extends ToolBase {
StatusTool statusTool = new StatusTool();
if (verbose) echo("\nChecking status of Solr at " + solrUrl + " ...");
- URL solrURL = new URL(solrUrl);
+ URI solrURI = new URI(solrUrl);
Map<String, Object> nodeStatus =
statusTool.waitToSeeSolrUp(solrUrl, maxWaitSecs, TimeUnit.SECONDS);
nodeStatus.put("baseUrl", solrUrl);
@@ -884,7 +884,7 @@ public class RunExampleTool extends ToolBase {
if (verbose)
echo(
"\nSolr is running on "
- + solrURL.getPort()
+ + solrURI.getPort()
+ " in "
+ mode
+ " mode with status:\n"
diff --git a/solr/core/src/java/org/apache/solr/cli/SimplePostTool.java
b/solr/core/src/java/org/apache/solr/cli/SimplePostTool.java
index 1c4ceaba9e8..f24fc5dcc9c 100644
--- a/solr/core/src/java/org/apache/solr/cli/SimplePostTool.java
+++ b/solr/core/src/java/org/apache/solr/cli/SimplePostTool.java
@@ -111,7 +111,7 @@ public class SimplePostTool {
int recursive = 0;
int delay = 0;
String fileTypes;
- URL solrUrl;
+ URI solrUrl;
OutputStream out = null;
String type;
String format;
@@ -254,7 +254,7 @@ public class SimplePostTool {
}
urlStr = SimplePostTool.appendParam(urlStr, params);
- URL url = new URL(urlStr);
+ URI url = new URI(urlStr);
String user = null;
if (url.getUserInfo() != null && url.getUserInfo().trim().length() > 0) {
user = url.getUserInfo().split(":")[0];
@@ -291,7 +291,7 @@ public class SimplePostTool {
return new SimplePostTool(
mode, url, auto, type, format, recursive, delay, fileTypes, out,
commit, optimize, args);
- } catch (MalformedURLException e) {
+ } catch (URISyntaxException e) {
fatal("System Property 'url' is not a valid URL: " + urlStr);
return null;
}
@@ -315,7 +315,7 @@ public class SimplePostTool {
*/
public SimplePostTool(
String mode,
- URL url,
+ URI url,
boolean auto,
String type,
String format,
@@ -406,7 +406,7 @@ public class SimplePostTool {
}
numPagesPosted = postWebPages(args, 0, out);
info(numPagesPosted + " web pages indexed.");
- } catch (MalformedURLException e) {
+ } catch (URISyntaxException e) {
fatal("Wrong URL trying to append /extract to " + solrUrl);
}
}
@@ -708,8 +708,8 @@ public class SimplePostTool {
PageFetcherResult result = pageFetcher.readPageFromUrl(url);
if (result.httpStatus == 200) {
url = (result.redirectUrl != null) ? result.redirectUrl : url;
- URL postUrl =
- new URL(
+ URI postUri =
+ URI.create(
appendParam(
solrUrl.toString(),
"literal.id="
@@ -723,7 +723,7 @@ public class SimplePostTool {
null,
out,
result.contentType,
- postUrl);
+ postUri);
if (success) {
info("POSTed web resource " + url + " (depth: " + level + ")");
Thread.sleep(delay * 1000L);
@@ -736,7 +736,7 @@ public class SimplePostTool {
new ByteArrayInputStream(
content.array(), content.arrayOffset(),
content.limit()),
result.contentType,
- postUrl);
+ postUri);
subStack.addAll(children);
}
} else {
@@ -877,7 +877,7 @@ public class SimplePostTool {
public void postFile(File file, OutputStream output, String type) {
InputStream is = null;
try {
- URL url = solrUrl;
+ URI url = solrUrl;
String suffix = "";
if (auto) {
if (type == null) {
@@ -889,7 +889,7 @@ public class SimplePostTool {
if (type.equals("application/json") && !FORMAT_SOLR.equals(format)) {
suffix = "/json/docs";
String urlStr = appendUrlPath(solrUrl, suffix).toString();
- url = new URL(urlStr);
+ url = URI.create(urlStr);
} else if (type.equals("application/xml")
|| type.equals("text/csv")
|| type.equals("application/json")) {
@@ -908,7 +908,7 @@ public class SimplePostTool {
appendParam(
urlStr, "literal.id=" +
URLEncoder.encode(file.getAbsolutePath(), UTF_8));
}
- url = new URL(urlStr);
+ url = URI.create(urlStr);
}
} else {
if (type == null) {
@@ -924,6 +924,8 @@ public class SimplePostTool {
+ (mockMode ? " MOCK!" : ""));
is = new FileInputStream(file);
postData(is, file.length(), output, type, url);
+ } catch (URISyntaxException e) {
+ warn("Not valid URL");
} catch (IOException e) {
warn("Can't open/read file: " + file);
} finally {
@@ -938,20 +940,15 @@ public class SimplePostTool {
}
/**
- * Appends to the path of the URL
+ * Appends to the path of the URI
*
- * @param url the URL
+ * @param uri the URI
* @param append the path to append
- * @return the final URL version
+ * @return the final URI version
*/
- protected static URL appendUrlPath(URL url, String append) throws
MalformedURLException {
- return new URL(
- url.getProtocol()
- + "://"
- + url.getAuthority()
- + url.getPath()
- + append
- + (url.getQuery() != null ? "?" + url.getQuery() : ""));
+ protected static URI appendUrlPath(URI uri, String append) throws
URISyntaxException {
+ var newPath = uri.getPath() + append;
+ return new URI(uri.getScheme(), uri.getAuthority(), newPath,
uri.getQuery(), uri.getFragment());
}
/**
@@ -971,7 +968,7 @@ public class SimplePostTool {
/** Performs a simple get on the given URL */
public void doGet(String url) {
try {
- doGet(new URL(url));
+ doGet(URI.create(url).toURL());
} catch (MalformedURLException e) {
warn("The specified URL " + url + " is not a valid URL. Please check");
}
@@ -1000,7 +997,7 @@ public class SimplePostTool {
* @return true if success
*/
public boolean postData(
- InputStream data, Long length, OutputStream output, String type, URL
url) {
+ InputStream data, Long length, OutputStream output, String type, URI
uri) {
if (mockMode) {
return true;
}
@@ -1012,7 +1009,7 @@ public class SimplePostTool {
HttpURLConnection urlConnection = null;
try {
try {
- urlConnection = (HttpURLConnection) url.openConnection();
+ urlConnection = (HttpURLConnection) uri.toURL().openConnection();
try {
urlConnection.setRequestMethod("POST");
} catch (ProtocolException e) {
@@ -1311,7 +1308,7 @@ public class SimplePostTool {
disallows = new ArrayList<>();
URL urlRobot;
try {
- urlRobot = new URL(strRobot);
+ urlRobot = URI.create(strRobot).toURL();
disallows = parseRobotsTxt(urlRobot.openStream());
} catch (MalformedURLException e) {
return true; // We cannot trust this robots URL, should not happen
@@ -1361,17 +1358,17 @@ public class SimplePostTool {
* @param u the URL of the web page
* @param is the input stream of the page
* @param type the content-type
- * @param postUrl the URL (typically /solr/extract) in order to pull out
links
+ * @param postUri the URI (typically /solr/extract) in order to pull out
links
* @return a set of URIs parsed from the page
*/
- protected Set<URI> getLinksFromWebPage(URL u, InputStream is, String type,
URL postUrl) {
+ protected Set<URI> getLinksFromWebPage(URL u, InputStream is, String type,
URI postUri) {
Set<URI> linksFromPage = new HashSet<>();
URL url = null;
try {
ByteArrayOutputStream os = new ByteArrayOutputStream();
- URL extractUrl = new URL(appendParam(postUrl.toString(),
"extractOnly=true"));
- extractUrl = new URL(appendParam(extractUrl.toString(), "wt=xml"));
- boolean success = postData(is, null, os, type, extractUrl);
+ URI extractUri = URI.create(appendParam(postUri.toString(),
"extractOnly=true"));
+ extractUri = URI.create(appendParam(extractUri.toString(), "wt=xml"));
+ boolean success = postData(is, null, os, type, extractUri);
if (success) {
Document d = makeDom(os.toByteArray());
String innerXml = getXP(d, "/response/str/text()[1]", false);
diff --git a/solr/core/src/java/org/apache/solr/cli/SolrCLI.java
b/solr/core/src/java/org/apache/solr/cli/SolrCLI.java
index a87913122a7..99b2b4d12c0 100755
--- a/solr/core/src/java/org/apache/solr/cli/SolrCLI.java
+++ b/solr/core/src/java/org/apache/solr/cli/SolrCLI.java
@@ -451,7 +451,7 @@ public class SolrCLI implements CLIO {
Set<String> classes = new TreeSet<>();
if (path.startsWith("file:") && path.contains("!")) {
String[] split = path.split("!");
- URL jar = new URL(split[0]);
+ URL jar = new URI(split[0]).toURL();
try (ZipInputStream zip = new ZipInputStream(jar.openStream())) {
ZipEntry entry;
while ((entry = zip.getNextEntry()) != null) {
diff --git a/solr/core/src/java/org/apache/solr/cli/StatusTool.java
b/solr/core/src/java/org/apache/solr/cli/StatusTool.java
index d805b292d74..9e85b446bb4 100644
--- a/solr/core/src/java/org/apache/solr/cli/StatusTool.java
+++ b/solr/core/src/java/org/apache/solr/cli/StatusTool.java
@@ -18,7 +18,7 @@
package org.apache.solr.cli;
import java.io.PrintStream;
-import java.net.URL;
+import java.net.URI;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -103,7 +103,7 @@ public class StatusTool extends ToolBase {
SolrCLI.getOptionWithDeprecatedAndDefault(cli, "max-wait-secs",
"maxWaitSecs", "0"));
String solrUrl = SolrCLI.normalizeSolrUrl(cli);
if (maxWaitSecs > 0) {
- int solrPort = (new URL(solrUrl)).getPort();
+ int solrPort = new URI(solrUrl).getPort();
echo("Waiting up to " + maxWaitSecs + " seconds to see Solr running on
port " + solrPort);
try {
waitToSeeSolrUp(solrUrl, maxWaitSecs, TimeUnit.SECONDS);
diff --git
a/solr/core/src/java/org/apache/solr/handler/admin/AdminHandlersProxy.java
b/solr/core/src/java/org/apache/solr/handler/admin/AdminHandlersProxy.java
index cd278fd095a..2d5b8d9f6f2 100644
--- a/solr/core/src/java/org/apache/solr/handler/admin/AdminHandlersProxy.java
+++ b/solr/core/src/java/org/apache/solr/handler/admin/AdminHandlersProxy.java
@@ -19,7 +19,7 @@ package org.apache.solr.handler.admin;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
-import java.net.URL;
+import java.net.URI;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
@@ -133,8 +133,8 @@ public class AdminHandlersProxy {
String nodeName, String endpoint, SolrParams params, ZkController
zkController)
throws IOException, SolrServerException {
log.debug("Proxying {} request to node {}", endpoint, nodeName);
- URL baseUrl = new
URL(zkController.zkStateReader.getBaseUrlForNodeName(nodeName));
- HttpSolrClient solr = new
HttpSolrClient.Builder(baseUrl.toString()).build();
+ URI baseUri =
URI.create(zkController.zkStateReader.getBaseUrlForNodeName(nodeName));
+ HttpSolrClient solr = new
HttpSolrClient.Builder(baseUri.toString()).build();
SolrRequest<?> proxyReq = new GenericSolrRequest(SolrRequest.METHOD.GET,
endpoint, params);
HttpSolrClient.HttpUriRequestResponse proxyResp =
solr.httpUriRequest(proxyReq);
return new Pair<>(proxyResp.future, solr);
diff --git
a/solr/core/src/java/org/apache/solr/packagemanager/DefaultPackageRepository.java
b/solr/core/src/java/org/apache/solr/packagemanager/DefaultPackageRepository.java
index 820391804e1..62d241d8bce 100644
---
a/solr/core/src/java/org/apache/solr/packagemanager/DefaultPackageRepository.java
+++
b/solr/core/src/java/org/apache/solr/packagemanager/DefaultPackageRepository.java
@@ -20,6 +20,7 @@ package org.apache.solr.packagemanager;
import com.fasterxml.jackson.annotation.JsonIgnore;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
+import java.net.URI;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -86,9 +87,9 @@ public class DefaultPackageRepository extends
PackageRepository {
Path tmpDirectory = Files.createTempDirectory("solr-packages");
tmpDirectory.toFile().deleteOnExit();
URL url =
- new URL(
- new URL(repositoryURL.endsWith("/") ? repositoryURL :
repositoryURL + "/"),
- artifactName);
+ URI.create(repositoryURL.endsWith("/") ? repositoryURL : repositoryURL
+ "/")
+ .resolve(artifactName)
+ .toURL();
String fileName = FilenameUtils.getName(url.getPath());
Path destination = tmpDirectory.resolve(fileName);
diff --git
a/solr/core/src/java/org/apache/solr/packagemanager/RepositoryManager.java
b/solr/core/src/java/org/apache/solr/packagemanager/RepositoryManager.java
index ea2ecb18e51..a203ce1ee39 100644
--- a/solr/core/src/java/org/apache/solr/packagemanager/RepositoryManager.java
+++ b/solr/core/src/java/org/apache/solr/packagemanager/RepositoryManager.java
@@ -25,7 +25,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.lang.invoke.MethodHandles;
-import java.net.URL;
+import java.net.URI;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
@@ -135,7 +135,7 @@ public class RepositoryManager {
true);
}
- try (InputStream is = new URL(uri + "/publickey.der").openStream()) {
+ try (InputStream is = new URI(uri +
"/publickey.der").toURL().openStream()) {
addKey(is.readAllBytes(), repoName + ".der");
}
}
diff --git
a/solr/core/src/java/org/apache/solr/schema/OpenExchangeRatesOrgProvider.java
b/solr/core/src/java/org/apache/solr/schema/OpenExchangeRatesOrgProvider.java
index 6438af1ffe6..fcc64b111eb 100644
---
a/solr/core/src/java/org/apache/solr/schema/OpenExchangeRatesOrgProvider.java
+++
b/solr/core/src/java/org/apache/solr/schema/OpenExchangeRatesOrgProvider.java
@@ -20,7 +20,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.invoke.MethodHandles;
-import java.net.URL;
+import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
@@ -151,7 +151,7 @@ public class OpenExchangeRatesOrgProvider implements
ExchangeRateProvider {
try {
log.debug("Reloading exchange rates from {}", ratesFileLocation);
try {
- ratesJsonStream = (new URL(ratesFileLocation)).openStream();
+ ratesJsonStream = (new URI(ratesFileLocation).toURL()).openStream();
} catch (Exception e) {
ratesJsonStream = resourceLoader.openResource(ratesFileLocation);
}
diff --git
a/solr/core/src/java/org/apache/solr/security/AllowListUrlChecker.java
b/solr/core/src/java/org/apache/solr/security/AllowListUrlChecker.java
index 1354fde0ec7..9bcede9b060 100644
--- a/solr/core/src/java/org/apache/solr/security/AllowListUrlChecker.java
+++ b/solr/core/src/java/org/apache/solr/security/AllowListUrlChecker.java
@@ -20,7 +20,7 @@ package org.apache.solr.security;
import com.google.common.annotations.VisibleForTesting;
import java.lang.invoke.MethodHandles;
import java.net.MalformedURLException;
-import java.net.URL;
+import java.net.URI;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
@@ -191,16 +191,16 @@ public class AllowListUrlChecker {
// Parse the host and port.
// It doesn't really matter which protocol we set here because we are not
going to use it.
url = url.trim();
- URL u;
+ URI u;
Matcher protocolMatcher = PROTOCOL_PATTERN.matcher(url);
if (protocolMatcher.matches()) {
// Replace any protocol unsupported by URL.
if (!protocolMatcher.group(1).startsWith("http")) {
url = "http" + protocolMatcher.group(2);
}
- u = new URL(url);
+ u = URI.create(url);
} else {
- u = new URL("http://" + url);
+ u = URI.create("http://" + url);
}
if (u.getHost() == null || u.getPort() < 0) {
throw new MalformedURLException("Invalid host or port in '" + url + "'");
diff --git a/solr/core/src/java/org/apache/solr/security/SolrNodeKeyPair.java
b/solr/core/src/java/org/apache/solr/security/SolrNodeKeyPair.java
index 1e93667c5d9..8db42492354 100644
--- a/solr/core/src/java/org/apache/solr/security/SolrNodeKeyPair.java
+++ b/solr/core/src/java/org/apache/solr/security/SolrNodeKeyPair.java
@@ -18,7 +18,7 @@
package org.apache.solr.security;
import java.io.IOException;
-import java.net.URL;
+import java.net.URI;
import java.security.spec.InvalidKeySpecException;
import org.apache.solr.common.util.StrUtils;
import org.apache.solr.core.CloudConfig;
@@ -55,7 +55,8 @@ public class SolrNodeKeyPair {
}
try {
- return new CryptoKeys.RSAKeyPair(new URL(privateKey), new
URL(publicKey));
+ return new CryptoKeys.RSAKeyPair(
+ URI.create(privateKey).toURL(), URI.create(publicKey).toURL());
} catch (IOException | InvalidKeySpecException e) {
throw new RuntimeException("Bad PublicKeyHandler configuration.", e);
}
diff --git a/solr/core/src/java/org/apache/solr/servlet/SolrRequestParsers.java
b/solr/core/src/java/org/apache/solr/servlet/SolrRequestParsers.java
index 91d7e2b2498..38a45c71a91 100644
--- a/solr/core/src/java/org/apache/solr/servlet/SolrRequestParsers.java
+++ b/solr/core/src/java/org/apache/solr/servlet/SolrRequestParsers.java
@@ -24,7 +24,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.PushbackInputStream;
import java.lang.invoke.MethodHandles;
-import java.net.URL;
+import java.net.URI;
import java.nio.ByteBuffer;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset;
@@ -212,7 +212,7 @@ public class SolrRequestParsers {
throw new SolrException(ErrorCode.BAD_REQUEST, "Remote Streaming is
disabled.");
}
for (final String url : strs) {
- ContentStreamBase stream = new ContentStreamBase.URLStream(new
URL(url));
+ ContentStreamBase stream = new
ContentStreamBase.URLStream(URI.create(url).toURL());
if (contentType != null) {
stream.setContentType(contentType);
}
diff --git
a/solr/core/src/java/org/apache/solr/update/processor/URLClassifyProcessor.java
b/solr/core/src/java/org/apache/solr/update/processor/URLClassifyProcessor.java
index f26450442e4..91ecc1adad1 100644
---
a/solr/core/src/java/org/apache/solr/update/processor/URLClassifyProcessor.java
+++
b/solr/core/src/java/org/apache/solr/update/processor/URLClassifyProcessor.java
@@ -198,7 +198,7 @@ public class URLClassifyProcessor extends
UpdateRequestProcessor {
// NOTE: Do we want to make sure this URL is normalized? (Christian thinks
we should)
String urlString = url.toString();
String lps = landingPageSuffix(url);
- return new URL(urlString.replaceFirst("/" + lps + "$", "/"));
+ return URI.create(urlString.replaceFirst("/" + lps + "$", "/")).toURL();
}
/**
diff --git a/solr/core/src/test/org/apache/solr/cli/PostToolTest.java
b/solr/core/src/test/org/apache/solr/cli/PostToolTest.java
index d8f02363e47..0e7485d2267 100644
--- a/solr/core/src/test/org/apache/solr/cli/PostToolTest.java
+++ b/solr/core/src/test/org/apache/solr/cli/PostToolTest.java
@@ -200,19 +200,24 @@ public class PostToolTest extends SolrCloudTestCase {
assertEquals(
"http://[ff01::114]/index.html",
- webPostTool.computeFullUrl(new URL("http://[ff01::114]/"),
"/index.html"));
+ webPostTool.computeFullUrl(URI.create("http://[ff01::114]/").toURL(),
"/index.html"));
assertEquals(
"http://[ff01::114]/index.html",
- webPostTool.computeFullUrl(new URL("http://[ff01::114]/foo/bar/"),
"/index.html"));
+ webPostTool.computeFullUrl(
+ URI.create("http://[ff01::114]/foo/bar/").toURL(), "/index.html"));
assertEquals(
"http://[ff01::114]/fil.html",
- webPostTool.computeFullUrl(new
URL("http://[ff01::114]/foo.htm?baz#hello"), "fil.html"));
+ webPostTool.computeFullUrl(
+ URI.create("http://[ff01::114]/foo.htm?baz#hello").toURL(),
"fil.html"));
// TODO: How to know what is the base if URL path ends with "foo"??
// assertEquals("http://[ff01::114]/fil.html", t_web.computeFullUrl(new
// URL("http://[ff01::114]/foo?baz#hello"), "fil.html"));
- assertNull(webPostTool.computeFullUrl(new URL("http://[ff01::114]/"),
"fil.jpg"));
- assertNull(webPostTool.computeFullUrl(new URL("http://[ff01::114]/"),
"mailto:[email protected]"));
- assertNull(webPostTool.computeFullUrl(new URL("http://[ff01::114]/"),
"ftp://server/file"));
+
assertNull(webPostTool.computeFullUrl(URI.create("http://[ff01::114]/").toURL(),
"fil.jpg"));
+ assertNull(
+ webPostTool.computeFullUrl(
+ URI.create("http://[ff01::114]/").toURL(),
"mailto:[email protected]"));
+ assertNull(
+ webPostTool.computeFullUrl(URI.create("http://[ff01::114]/").toURL(),
"ftp://server/file"));
}
@Test
@@ -239,10 +244,10 @@ public class PostToolTest extends SolrCloudTestCase {
}
@Test
- public void testAppendUrlPath() throws MalformedURLException {
+ public void testAppendUrlPath() throws URISyntaxException {
assertEquals(
- new URL("http://[ff01::114]/a?foo=bar"),
- PostTool.appendUrlPath(new URL("http://[ff01::114]?foo=bar"), "/a"));
+ URI.create("http://[ff01::114]/a?foo=bar"),
+ PostTool.appendUrlPath(URI.create("http://[ff01::114]?foo=bar"),
"/a"));
}
@Test
@@ -260,7 +265,7 @@ public class PostToolTest extends SolrCloudTestCase {
PostTool postTool = new PostTool();
postTool.recursive = 0;
postTool.dryRun = true;
- postTool.solrUpdateUrl = new URL("http://localhost:8983/solr/fake/update");
+ postTool.solrUpdateUrl =
URI.create("http://localhost:8983/solr/fake/update");
File dir = getFile("exampledocs");
int num = postTool.postFiles(new String[] {dir.toString()}, 0, null, null);
assertEquals(2, num);
@@ -282,7 +287,7 @@ public class PostToolTest extends SolrCloudTestCase {
PostTool postTool = new PostTool();
postTool.recursive = 1; // This is the default
postTool.dryRun = true;
- postTool.solrUpdateUrl = new URL("http://localhost:8983/solr/fake/update");
+ postTool.solrUpdateUrl =
URI.create("http://localhost:8983/solr/fake/update");
File dir = getFile("exampledocs");
int num = postTool.postFiles(new String[] {dir.toString()}, 0, null, null);
assertEquals(2, num);
@@ -293,7 +298,7 @@ public class PostToolTest extends SolrCloudTestCase {
PostTool postTool = new PostTool();
postTool.pageFetcher = new MockPageFetcher();
postTool.dryRun = true;
- postTool.solrUpdateUrl = new
URL("http://user:password@localhost:5150/solr/fake/update");
+ postTool.solrUpdateUrl =
URI.create("http://user:password@localhost:5150/solr/fake/update");
// Uses mock pageFetcher
postTool.delay = 0;
@@ -318,8 +323,11 @@ public class PostToolTest extends SolrCloudTestCase {
postTool.pageFetcher = new MockPageFetcher();
postTool.dryRun = true;
- assertFalse(postTool.pageFetcher.isDisallowedByRobots(new
URL("http://[ff01::114]/")));
- assertTrue(postTool.pageFetcher.isDisallowedByRobots(new
URL("http://[ff01::114]/disallowed")));
+ assertFalse(
+
postTool.pageFetcher.isDisallowedByRobots(URI.create("http://[ff01::114]/").toURL()));
+ assertTrue(
+ postTool.pageFetcher.isDisallowedByRobots(
+ URI.create("http://[ff01::114]/disallowed").toURL()));
assertEquals(
"There should be two entries parsed from robots.txt",
2,
@@ -397,7 +405,7 @@ public class PostToolTest extends SolrCloudTestCase {
}
@Override
- public Set<URI> getLinksFromWebPage(URL url, InputStream is, String type,
URL postUrl) {
+ public Set<URI> getLinksFromWebPage(URL url, InputStream is, String type,
URI postUri) {
Set<URI> s = linkMap.get(PostTool.normalizeUrlEnding(url.toString()));
if (s == null) {
s = new HashSet<>();
diff --git a/solr/core/src/test/org/apache/solr/cli/SimplePostToolTest.java
b/solr/core/src/test/org/apache/solr/cli/SimplePostToolTest.java
index fdd58149a82..64e6e1e5dc1 100644
--- a/solr/core/src/test/org/apache/solr/cli/SimplePostToolTest.java
+++ b/solr/core/src/test/org/apache/solr/cli/SimplePostToolTest.java
@@ -92,7 +92,7 @@ public class SimplePostToolTest extends SolrTestCaseJ4 {
assertEquals(
"http://user:password@localhost:5150/solr/update?param1=foo¶m2=bar",
- t_test.solrUrl.toExternalForm());
+ t_test.solrUrl.toString());
}
@Test
@@ -109,19 +109,22 @@ public class SimplePostToolTest extends SolrTestCaseJ4 {
public void testComputeFullUrl() throws MalformedURLException {
assertEquals(
"http://[ff01::114]/index.html",
- t_web.computeFullUrl(new URL("http://[ff01::114]/"), "/index.html"));
+ t_web.computeFullUrl(URI.create("http://[ff01::114]/").toURL(),
"/index.html"));
assertEquals(
"http://[ff01::114]/index.html",
- t_web.computeFullUrl(new URL("http://[ff01::114]/foo/bar/"),
"/index.html"));
+
t_web.computeFullUrl(URI.create("http://[ff01::114]/foo/bar/").toURL(),
"/index.html"));
assertEquals(
"http://[ff01::114]/fil.html",
- t_web.computeFullUrl(new URL("http://[ff01::114]/foo.htm?baz#hello"),
"fil.html"));
+ t_web.computeFullUrl(
+ URI.create("http://[ff01::114]/foo.htm?baz#hello").toURL(),
"fil.html"));
// TODO: How to know what is the base if URL path ends with "foo"??
// assertEquals("http://[ff01::114]/fil.html", t_web.computeFullUrl(new
// URL("http://[ff01::114]/foo?baz#hello"), "fil.html"));
- assertNull(t_web.computeFullUrl(new URL("http://[ff01::114]/"),
"fil.jpg"));
- assertNull(t_web.computeFullUrl(new URL("http://[ff01::114]/"),
"mailto:[email protected]"));
- assertNull(t_web.computeFullUrl(new URL("http://[ff01::114]/"),
"ftp://server/file"));
+ assertNull(t_web.computeFullUrl(URI.create("http://[ff01::114]/").toURL(),
"fil.jpg"));
+ assertNull(
+ t_web.computeFullUrl(URI.create("http://[ff01::114]/").toURL(),
"mailto:[email protected]"));
+ assertNull(
+ t_web.computeFullUrl(URI.create("http://[ff01::114]/").toURL(),
"ftp://server/file"));
}
@Test
@@ -153,10 +156,10 @@ public class SimplePostToolTest extends SolrTestCaseJ4 {
}
@Test
- public void testAppendUrlPath() throws MalformedURLException {
+ public void testAppendUrlPath() throws URISyntaxException {
assertEquals(
- new URL("http://[ff01::114]/a?foo=bar"),
- SimplePostTool.appendUrlPath(new URL("http://[ff01::114]?foo=bar"),
"/a"));
+ URI.create("http://[ff01::114]/a?foo=bar"),
+ SimplePostTool.appendUrlPath(URI.create("http://[ff01::114]?foo=bar"),
"/a"));
}
@Test
@@ -198,8 +201,10 @@ public class SimplePostToolTest extends SolrTestCaseJ4 {
@Test
public void testRobotsExclusion() throws MalformedURLException {
- assertFalse(t_web.pageFetcher.isDisallowedByRobots(new
URL("http://[ff01::114]/")));
- assertTrue(t_web.pageFetcher.isDisallowedByRobots(new
URL("http://[ff01::114]/disallowed")));
+
assertFalse(t_web.pageFetcher.isDisallowedByRobots(URI.create("http://[ff01::114]/").toURL()));
+ assertTrue(
+ t_web.pageFetcher.isDisallowedByRobots(
+ URI.create("http://[ff01::114]/disallowed").toURL()));
assertEquals(
"There should be two entries parsed from robots.txt",
2,
@@ -277,7 +282,7 @@ public class SimplePostToolTest extends SolrTestCaseJ4 {
}
@Override
- public Set<URI> getLinksFromWebPage(URL u, InputStream is, String type,
URL postUrl) {
+ public Set<URI> getLinksFromWebPage(URL u, InputStream is, String type,
URI postUri) {
Set<URI> s =
linkMap.get(SimplePostTool.normalizeUrlEnding(u.toString()));
if (s == null) s = new HashSet<>();
return s;
diff --git a/solr/core/src/test/org/apache/solr/cloud/OverseerRolesTest.java
b/solr/core/src/test/org/apache/solr/cloud/OverseerRolesTest.java
index 8ebe618e660..3da6970e1f6 100644
--- a/solr/core/src/test/org/apache/solr/cloud/OverseerRolesTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/OverseerRolesTest.java
@@ -20,7 +20,7 @@ import static
org.apache.solr.cloud.OverseerCollectionConfigSetProcessor.getLead
import static
org.apache.solr.cloud.OverseerTaskProcessor.getSortedElectionNodes;
import java.lang.invoke.MethodHandles;
-import java.net.URL;
+import java.net.URI;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
@@ -75,7 +75,7 @@ public class OverseerRolesTest extends SolrCloudTestCase {
private JettySolrRunner getOverseerJetty() throws Exception {
String overseer = getLeaderNode(zkClient());
- URL overseerUrl = new URL("http://" + overseer.substring(0,
overseer.indexOf('_')));
+ URI overseerUrl = URI.create("http://" + overseer.substring(0,
overseer.indexOf('_')));
int hostPort = overseerUrl.getPort();
for (JettySolrRunner jetty : cluster.getJettySolrRunners()) {
try {
diff --git
a/solr/core/src/test/org/apache/solr/cloud/TestPullReplicaErrorHandling.java
b/solr/core/src/test/org/apache/solr/cloud/TestPullReplicaErrorHandling.java
index dd0363c16ac..9906d3041f1 100644
--- a/solr/core/src/test/org/apache/solr/cloud/TestPullReplicaErrorHandling.java
+++ b/solr/core/src/test/org/apache/solr/cloud/TestPullReplicaErrorHandling.java
@@ -19,7 +19,6 @@ package org.apache.solr.cloud;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.net.URI;
-import java.net.URL;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
@@ -325,24 +324,24 @@ public class TestPullReplicaErrorHandling extends
SolrCloudTestCase {
protected JettySolrRunner getJettyForReplica(Replica replica) throws
Exception {
String replicaBaseUrl = replica.getStr(ZkStateReader.BASE_URL_PROP);
assertNotNull(replicaBaseUrl);
- URL baseUrl = new URL(replicaBaseUrl);
+ URI baseUri = URI.create(replicaBaseUrl);
- JettySolrRunner proxy = jettys.get(baseUrl.toURI());
- assertNotNull("No proxy found for " + baseUrl + "!", proxy);
+ JettySolrRunner proxy = jettys.get(baseUri);
+ assertNotNull("No proxy found for " + baseUri + "!", proxy);
return proxy;
}
protected SocketProxy getProxyForReplica(Replica replica) throws Exception {
String replicaBaseUrl = replica.getStr(ZkStateReader.BASE_URL_PROP);
assertNotNull(replicaBaseUrl);
- URL baseUrl = new URL(replicaBaseUrl);
+ URI baseUri = URI.create(replicaBaseUrl);
- SocketProxy proxy = proxies.get(baseUrl.toURI());
- if (proxy == null && !baseUrl.toExternalForm().endsWith("/")) {
- baseUrl = new URL(baseUrl.toExternalForm() + "/");
- proxy = proxies.get(baseUrl.toURI());
+ SocketProxy proxy = proxies.get(baseUri);
+ if (proxy == null && !baseUri.toString().endsWith("/")) {
+ baseUri = URI.create(baseUri.toString() + "/");
+ proxy = proxies.get(baseUri);
}
- assertNotNull("No proxy found for " + baseUrl + "!", proxy);
+ assertNotNull("No proxy found for " + baseUri + "!", proxy);
return proxy;
}
diff --git
a/solr/core/src/test/org/apache/solr/cloud/TestRequestForwarding.java
b/solr/core/src/test/org/apache/solr/cloud/TestRequestForwarding.java
index a4854134f93..c672da3f4f2 100644
--- a/solr/core/src/test/org/apache/solr/cloud/TestRequestForwarding.java
+++ b/solr/core/src/test/org/apache/solr/cloud/TestRequestForwarding.java
@@ -16,11 +16,13 @@
*/
package org.apache.solr.cloud;
+import java.net.MalformedURLException;
import java.net.URL;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.SolrTestCaseJ4.SuppressSSL;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.response.CollectionAdminResponse;
+import org.apache.solr.common.util.SuppressForbidden;
import org.apache.solr.embedded.JettyConfig;
import org.apache.solr.embedded.JettySolrRunner;
import org.junit.Test;
@@ -60,7 +62,7 @@ public class TestRequestForwarding extends SolrTestCaseJ4 {
};
for (String q : queryStrings) {
try {
- URL url = new URL(jettySolrRunner.getBaseUrl().toString() +
"/collection1/select?" + q);
+ URL url = createURL(jettySolrRunner.getBaseUrl().toString() +
"/collection1/select?" + q);
url.openStream(); // Shouldn't throw any errors
} catch (Exception ex) {
throw new RuntimeException("Query '" + q + "' failed, ", ex);
@@ -69,6 +71,12 @@ public class TestRequestForwarding extends SolrTestCaseJ4 {
}
}
+ // Restricting the Scope of Forbidden API
+ @SuppressForbidden(reason = "java.net.URL#<init> deprecated since Java 20")
+ private URL createURL(String url) throws MalformedURLException {
+ return new URL(url);
+ }
+
private void createCollection(String name, String config) throws Exception {
CollectionAdminResponse response;
CollectionAdminRequest.Create create =
diff --git
a/solr/core/src/test/org/apache/solr/handler/ReplicationTestHelper.java
b/solr/core/src/test/org/apache/solr/handler/ReplicationTestHelper.java
index a9c81429467..edd68727f87 100644
--- a/solr/core/src/test/org/apache/solr/handler/ReplicationTestHelper.java
+++ b/solr/core/src/test/org/apache/solr/handler/ReplicationTestHelper.java
@@ -22,6 +22,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.Writer;
import java.lang.invoke.MethodHandles;
+import java.net.URI;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
@@ -156,7 +157,7 @@ public final class ReplicationTestHelper {
// String leaderUrl = buildUrl(pJettyPort) + "/" + DEFAULT_TEST_CORENAME +
// ReplicationHandler.PATH+"?command=" + pCommand;
String url = baseUrl + ReplicationHandler.PATH + "?command=" + pCommand;
- URL u = new URL(url);
+ URL u = URI.create(url).toURL();
InputStream stream = u.openStream();
stream.close();
}
@@ -227,7 +228,7 @@ public final class ReplicationTestHelper {
+ "?wait=true&command=fetchindex&leaderUrl="
+ srcUrl
+ ReplicationHandler.PATH;
- url = new URL(leaderUrl);
+ url = URI.create(leaderUrl).toURL();
stream = url.openStream();
stream.close();
}
diff --git
a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java
b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java
index 64a48c282e1..f0f01381c8c 100644
--- a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java
+++ b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java
@@ -28,6 +28,7 @@ import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.lang.invoke.MethodHandles;
+import java.net.URI;
import java.net.URL;
import java.nio.file.Paths;
import java.util.Arrays;
@@ -846,7 +847,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
+ "/"
+ DEFAULT_TEST_CORENAME
+ ReplicationHandler.PATH;
- URL url = new URL(leaderUrl);
+ URL url = new URI(leaderUrl).toURL();
InputStream stream = url.openStream();
stream.close();
diff --git
a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java
b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java
index 83d2f319320..f0b17d84c07 100644
---
a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java
+++
b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java
@@ -20,6 +20,7 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.invoke.MethodHandles;
+import java.net.URI;
import java.net.URL;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
@@ -262,7 +263,7 @@ public class TestReplicationHandlerBackup extends
SolrJettyTestBase {
+ "?wt=xml&command="
+ cmd
+ params;
- URL url = new URL(leaderUrl);
+ URL url = URI.create(leaderUrl).toURL();
try (InputStream stream = url.openStream()) {
assert stream != null;
}
diff --git
a/solr/core/src/test/org/apache/solr/request/TestRemoteStreaming.java
b/solr/core/src/test/org/apache/solr/request/TestRemoteStreaming.java
index 486b3396afd..8fb2da411d9 100644
--- a/solr/core/src/test/org/apache/solr/request/TestRemoteStreaming.java
+++ b/solr/core/src/test/org/apache/solr/request/TestRemoteStreaming.java
@@ -21,7 +21,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringWriter;
-import java.net.URL;
+import java.net.URI;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import org.apache.lucene.tests.util.LuceneTestCase;
@@ -83,7 +83,7 @@ public class TestRemoteStreaming extends SolrJettyTestBase {
}
private String attemptHttpGet(String getUrl) throws IOException {
- Object obj = new URL(getUrl).getContent();
+ Object obj = URI.create(getUrl).toURL().getContent();
if (obj instanceof InputStream) {
try (InputStream inputStream = (InputStream) obj) {
StringWriter strWriter = new StringWriter();
diff --git
a/solr/core/src/test/org/apache/solr/response/transform/TestSubQueryTransformerDistrib.java
b/solr/core/src/test/org/apache/solr/response/transform/TestSubQueryTransformerDistrib.java
index 087c902c7d7..41e818611b0 100644
---
a/solr/core/src/test/org/apache/solr/response/transform/TestSubQueryTransformerDistrib.java
+++
b/solr/core/src/test/org/apache/solr/response/transform/TestSubQueryTransformerDistrib.java
@@ -23,6 +23,7 @@ import static
org.apache.solr.security.Sha256AuthenticationProvider.getSaltedHas
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
@@ -211,12 +212,13 @@ public class TestSubQueryTransformerDistrib extends
SolrCloudTestCase {
params.set("wt", "json");
final URL node =
- new URL(
- cluster.getRandomJetty(random()).getBaseUrl().toString()
- + "/"
- + people
- + "/select"
- + params.toQueryString());
+ URI.create(
+ cluster.getRandomJetty(random()).getBaseUrl().toString()
+ + "/"
+ + people
+ + "/select"
+ + params.toQueryString())
+ .toURL();
final URLConnection urlConnectionWithoutAuth = node.openConnection();
assertThrows(Exception.class, () ->
urlConnectionWithoutAuth.getInputStream());
diff --git
a/solr/core/src/test/org/apache/solr/security/AuditLoggerIntegrationTest.java
b/solr/core/src/test/org/apache/solr/security/AuditLoggerIntegrationTest.java
index f349488a82a..6e3e715764e 100644
---
a/solr/core/src/test/org/apache/solr/security/AuditLoggerIntegrationTest.java
+++
b/solr/core/src/test/org/apache/solr/security/AuditLoggerIntegrationTest.java
@@ -39,7 +39,7 @@ import java.io.InputStreamReader;
import java.lang.invoke.MethodHandles;
import java.net.ServerSocket;
import java.net.Socket;
-import java.net.URL;
+import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.ArrayList;
@@ -257,7 +257,7 @@ public class AuditLoggerIntegrationTest extends
SolrCloudAuthTestCase {
expectThrows(
FileNotFoundException.class,
() -> {
- try (InputStream is = new URL(baseUrl + "/node/foo").openStream()) {
+ try (InputStream is = URI.create(baseUrl +
"/node/foo").toURL().openStream()) {
new String(is.readAllBytes(), StandardCharsets.UTF_8);
}
});
diff --git
a/solr/core/src/test/org/apache/solr/servlet/HttpSolrCallCloudTest.java
b/solr/core/src/test/org/apache/solr/servlet/HttpSolrCallCloudTest.java
index 5af1ead66ef..7fff377d3a3 100644
--- a/solr/core/src/test/org/apache/solr/servlet/HttpSolrCallCloudTest.java
+++ b/solr/core/src/test/org/apache/solr/servlet/HttpSolrCallCloudTest.java
@@ -18,7 +18,7 @@
package org.apache.solr.servlet;
import java.net.HttpURLConnection;
-import java.net.URL;
+import java.net.URI;
import java.util.HashSet;
import java.util.Set;
import javax.servlet.ReadListener;
@@ -67,7 +67,8 @@ public class HttpSolrCallCloudTest extends SolrCloudTestCase {
public void testWrongUtf8InQ() throws Exception {
var baseUrl = cluster.getJettySolrRunner(0).getBaseUrl();
var request =
- new URL(baseUrl.toString() + "/" + COLLECTION + "/select?q=%C0"); //
Illegal UTF-8 string
+ URI.create(baseUrl.toString() + "/" + COLLECTION + "/select?q=%C0")
+ .toURL(); // Illegal UTF-8 string
var connection = (HttpURLConnection) request.openConnection();
assertEquals(400, connection.getResponseCode());
}
diff --git
a/solr/modules/jwt-auth/src/java/org/apache/solr/security/jwt/JWTIssuerConfig.java
b/solr/modules/jwt-auth/src/java/org/apache/solr/security/jwt/JWTIssuerConfig.java
index 752bfd60780..7e479be74d4 100644
---
a/solr/modules/jwt-auth/src/java/org/apache/solr/security/jwt/JWTIssuerConfig.java
+++
b/solr/modules/jwt-auth/src/java/org/apache/solr/security/jwt/JWTIssuerConfig.java
@@ -24,6 +24,7 @@ import java.io.InputStream;
import java.lang.invoke.MethodHandles;
import java.net.InetAddress;
import java.net.MalformedURLException;
+import java.net.URI;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
@@ -118,7 +119,7 @@ public class JWTIssuerConfig {
}
if (wellKnownUrl != null) {
try {
- wellKnownDiscoveryConfig = fetchWellKnown(new URL(wellKnownUrl));
+ wellKnownDiscoveryConfig =
fetchWellKnown(URI.create(wellKnownUrl).toURL());
} catch (MalformedURLException e) {
throw new SolrException(
SolrException.ErrorCode.SERVER_ERROR,
@@ -469,7 +470,7 @@ public class JWTIssuerConfig {
private HttpsJwks create(String url) {
final URL jwksUrl;
try {
- jwksUrl = new URL(url);
+ jwksUrl = URI.create(url).toURL();
checkAllowOutboundHttpConnections(PARAM_JWKS_URL, jwksUrl);
} catch (MalformedURLException e) {
throw new SolrException(
@@ -506,7 +507,7 @@ public class JWTIssuerConfig {
}
public static WellKnownDiscoveryConfig parse(String urlString) throws
MalformedURLException {
- return parse(new URL(urlString), null);
+ return parse(URI.create(urlString).toURL(), null);
}
/**
diff --git
a/solr/modules/jwt-auth/src/test/org/apache/solr/security/jwt/JWTAuthPluginIntegrationTest.java
b/solr/modules/jwt-auth/src/test/org/apache/solr/security/jwt/JWTAuthPluginIntegrationTest.java
index ef7fe35d4f5..3bb08460218 100644
---
a/solr/modules/jwt-auth/src/test/org/apache/solr/security/jwt/JWTAuthPluginIntegrationTest.java
+++
b/solr/modules/jwt-auth/src/test/org/apache/solr/security/jwt/JWTAuthPluginIntegrationTest.java
@@ -26,6 +26,7 @@ import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.InetAddress;
+import java.net.URI;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
@@ -389,7 +390,7 @@ public class JWTAuthPluginIntegrationTest extends
SolrCloudAuthTestCase {
}
private Pair<String, Integer> get(String url, String token) throws
IOException {
- URL createUrl = new URL(url);
+ URL createUrl = URI.create(url).toURL();
HttpURLConnection createConn = (HttpURLConnection)
createUrl.openConnection();
if (token != null) createConn.setRequestProperty("Authorization", "Bearer
" + token);
BufferedReader br2 =
@@ -402,7 +403,7 @@ public class JWTAuthPluginIntegrationTest extends
SolrCloudAuthTestCase {
}
private Map<String, String> getHeaders(String url, String token) throws
IOException {
- URL createUrl = new URL(url);
+ URL createUrl = URI.create(url).toURL();
HttpURLConnection conn = (HttpURLConnection) createUrl.openConnection();
if (token != null) conn.setRequestProperty("Authorization", "Bearer " +
token);
conn.connect();
@@ -415,7 +416,7 @@ public class JWTAuthPluginIntegrationTest extends
SolrCloudAuthTestCase {
}
private Pair<String, Integer> post(String url, String json, String token)
throws IOException {
- URL createUrl = new URL(url);
+ URL createUrl = URI.create(url).toURL();
HttpURLConnection con = (HttpURLConnection) createUrl.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_JSON.getMimeType());
diff --git
a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBSolrClient.java
b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBSolrClient.java
index 01eabb996a2..ab2f9784eff 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBSolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBSolrClient.java
@@ -25,7 +25,7 @@ import java.net.ConnectException;
import java.net.MalformedURLException;
import java.net.SocketException;
import java.net.SocketTimeoutException;
-import java.net.URL;
+import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -696,11 +696,7 @@ public abstract class LBSolrClient extends SolrClient {
*/
@Deprecated
public String removeSolrServer(String server) {
- try {
- server = new URL(server).toExternalForm();
- } catch (MalformedURLException e) {
- throw new RuntimeException(e);
- }
+ server = URI.create(server).toString();
if (server.endsWith("/")) {
server = server.substring(0, server.length() - 1);
}
diff --git
a/solr/solrj/src/java/org/apache/solr/client/solrj/util/ClientUtils.java
b/solr/solrj/src/java/org/apache/solr/client/solrj/util/ClientUtils.java
index d0cc138a8ad..568bd7e5a77 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/util/ClientUtils.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/util/ClientUtils.java
@@ -20,7 +20,7 @@ import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.net.MalformedURLException;
-import java.net.URL;
+import java.net.URI;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
@@ -103,9 +103,9 @@ public class ClientUtils {
}
private static String changeV2RequestEndpoint(String basePath) throws
MalformedURLException {
- URL oldURL = new URL(basePath);
- String newPath = oldURL.getPath().replaceFirst("/solr", "/api");
- return new URL(oldURL.getProtocol(), oldURL.getHost(), oldURL.getPort(),
newPath).toString();
+ URI oldURI = URI.create(basePath);
+ String newPath = oldURI.getPath().replaceFirst("/solr", "/api");
+ return oldURI.resolve(newPath).toString();
}
// ------------------------------------------------------------------------
diff --git
a/solr/solrj/src/test/org/apache/solr/client/solrj/TestSolrJErrorHandling.java
b/solr/solrj/src/test/org/apache/solr/client/solrj/TestSolrJErrorHandling.java
index 0941775980d..68ba3e42606 100644
---
a/solr/solrj/src/test/org/apache/solr/client/solrj/TestSolrJErrorHandling.java
+++
b/solr/solrj/src/test/org/apache/solr/client/solrj/TestSolrJErrorHandling.java
@@ -24,6 +24,7 @@ import java.io.OutputStreamWriter;
import java.lang.invoke.MethodHandles;
import java.net.HttpURLConnection;
import java.net.Socket;
+import java.net.URI;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
@@ -280,7 +281,7 @@ public class TestSolrJErrorHandling extends
SolrJettyTestBase {
String urlString = getCoreUrl() + "/update";
HttpURLConnection conn = null;
- URL url = new URL(urlString);
+ URL url = URI.create(urlString).toURL();
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
diff --git
a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/JettyWebappTest.java
b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/JettyWebappTest.java
index 2a16e40ea0d..5a79e32478c 100644
---
a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/JettyWebappTest.java
+++
b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/JettyWebappTest.java
@@ -18,7 +18,7 @@ package org.apache.solr.client.solrj.embedded;
import java.io.File;
import java.io.InputStream;
-import java.net.URL;
+import java.net.URI;
import java.util.Locale;
import java.util.Random;
import org.apache.http.Header;
@@ -90,9 +90,8 @@ public class JettyWebappTest extends SolrTestCaseJ4 {
public void testAdminUI() throws Exception {
// Currently not an extensive test, but it does fire up the JSP pages and
make
// sure they compile ok
-
String adminPath = "http://127.0.0.1:" + port + context + "/";
- try (InputStream is = new URL(adminPath).openStream()) {
+ try (InputStream is = URI.create(adminPath).toURL().openStream()) {
assertNotNull(is.readAllBytes()); // real error will be an exception
}
diff --git
a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java
b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java
index 7408b09bc7e..1d1f5742ce4 100644
---
a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java
+++
b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java
@@ -20,7 +20,7 @@ import static
org.apache.solr.client.solrj.impl.CloudSolrClient.RouteResponse;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
-import java.net.URL;
+import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -555,8 +555,8 @@ public class CloudHttp2SolrClientTest extends
SolrCloudTestCase {
// Make sure the distributed queries were directed to a single node only
Set<Integer> ports = new HashSet<Integer>();
for (String shardAddr : shardAddresses) {
- URL url = new URL(shardAddr);
- ports.add(url.getPort());
+ URI uri = URI.create(shardAddr);
+ ports.add(uri.getPort());
}
// This assertion would hold true as long as every shard has a core on
each node
diff --git
a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java
b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java
index df15a8f9583..d8c5e2f1bcf 100644
---
a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java
+++
b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java
@@ -20,7 +20,7 @@ import static
org.apache.solr.client.solrj.SolrRequest.METHOD.POST;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
-import java.net.URL;
+import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -497,8 +497,8 @@ public class CloudSolrClientTest extends SolrCloudTestCase {
// Make sure the distributed queries were directed to a single node only
Set<Integer> ports = new HashSet<Integer>();
for (String shardAddr : shardAddresses) {
- URL url = new URL(shardAddr);
- ports.add(url.getPort());
+ URI uri = URI.create(shardAddr);
+ ports.add(uri.getPort());
}
// This assertion would hold true as long as every shard has a core on
each node
diff --git
a/solr/solrj/src/test/org/apache/solr/common/util/ContentStreamTest.java
b/solr/solrj/src/test/org/apache/solr/common/util/ContentStreamTest.java
index fdb5f4176c9..cc4fd1b156c 100644
--- a/solr/solrj/src/test/org/apache/solr/common/util/ContentStreamTest.java
+++ b/solr/solrj/src/test/org/apache/solr/common/util/ContentStreamTest.java
@@ -23,7 +23,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
-import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.util.zip.GZIPInputStream;
@@ -101,8 +100,7 @@ public class ContentStreamTest extends SolrTestCaseJ4 {
is.transferTo(os);
}
- ContentStreamBase stream =
- new ContentStreamBase.URLStream(new URL(file.toURI().toASCIIString()));
+ ContentStreamBase stream = new
ContentStreamBase.URLStream(file.toURI().toURL());
try (InputStream s = stream.getStream();
FileInputStream fis = new FileInputStream(file);
@@ -133,8 +131,7 @@ public class ContentStreamTest extends SolrTestCaseJ4 {
is.transferTo(zos);
}
- ContentStreamBase stream =
- new ContentStreamBase.URLStream(new URL(file.toURI().toASCIIString()));
+ ContentStreamBase stream = new
ContentStreamBase.URLStream(file.toURI().toURL());
try (InputStream s = stream.getStream();
FileInputStream fis = new FileInputStream(file);
GZIPInputStream zis = new GZIPInputStream(fis);
@@ -160,8 +157,7 @@ public class ContentStreamTest extends SolrTestCaseJ4 {
is.transferTo(zos);
}
- ContentStreamBase stream =
- new ContentStreamBase.URLStream(new URL(file.toURI().toASCIIString()));
+ ContentStreamBase stream = new
ContentStreamBase.URLStream(file.toURI().toURL());
try (InputStream s = stream.getStream();
FileInputStream fis = new FileInputStream(file);
GZIPInputStream zis = new GZIPInputStream(fis);
@@ -187,8 +183,7 @@ public class ContentStreamTest extends SolrTestCaseJ4 {
is.transferTo(zos);
}
- ContentStreamBase stream =
- new ContentStreamBase.URLStream(new URL(file.toURI().toASCIIString()));
+ ContentStreamBase stream = new
ContentStreamBase.URLStream(file.toURI().toURL());
try (InputStream s = stream.getStream();
FileInputStream fis = new FileInputStream(file);
GZIPInputStream zis = new GZIPInputStream(fis);
diff --git
a/solr/test-framework/src/java/org/apache/solr/embedded/JettySolrRunner.java
b/solr/test-framework/src/java/org/apache/solr/embedded/JettySolrRunner.java
index 12aa7134f15..92d8e4b2efc 100644
--- a/solr/test-framework/src/java/org/apache/solr/embedded/JettySolrRunner.java
+++ b/solr/test-framework/src/java/org/apache/solr/embedded/JettySolrRunner.java
@@ -26,6 +26,8 @@ import java.io.PrintStream;
import java.lang.invoke.MethodHandles;
import java.net.BindException;
import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
@@ -784,7 +786,9 @@ public class JettySolrRunner {
/** Returns a base URL like {@code http://localhost:8983/solr} */
public URL getBaseUrl() {
try {
- return new URL(protocol, host, jettyPort, config.context);
+ return new URI(protocol, null, host, jettyPort, config.context, null,
null).toURL();
+ } catch (URISyntaxException e) {
+ throw new RuntimeException(e);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
@@ -792,9 +796,11 @@ public class JettySolrRunner {
public URL getBaseURLV2() {
try {
- return new URL(protocol, host, jettyPort, "/api");
+ return new URI(protocol, null, host, jettyPort, "/api", null,
null).toURL();
} catch (MalformedURLException e) {
throw new RuntimeException(e);
+ } catch (URISyntaxException e) {
+ throw new RuntimeException(e);
}
}
@@ -804,9 +810,11 @@ public class JettySolrRunner {
*/
public URL getProxyBaseUrl() {
try {
- return new URL(protocol, host, getLocalPort(), config.context);
+ return new URI(protocol, null, host, getLocalPort(), config.context,
null, null).toURL();
} catch (MalformedURLException e) {
throw new RuntimeException(e);
+ } catch (URISyntaxException e) {
+ throw new RuntimeException(e);
}
}
diff --git
a/solr/test-framework/src/java/org/apache/solr/handler/BackupRestoreUtils.java
b/solr/test-framework/src/java/org/apache/solr/handler/BackupRestoreUtils.java
index 10456e4984e..bd610200895 100644
---
a/solr/test-framework/src/java/org/apache/solr/handler/BackupRestoreUtils.java
+++
b/solr/test-framework/src/java/org/apache/solr/handler/BackupRestoreUtils.java
@@ -20,11 +20,14 @@ package org.apache.solr.handler;
import java.io.IOException;
import java.io.InputStream;
import java.lang.invoke.MethodHandles;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;
+import org.apache.http.client.utils.URIBuilder;
import org.apache.lucene.tests.util.TestUtil;
import org.apache.solr.SolrTestCase;
import org.apache.solr.client.solrj.SolrClient;
@@ -74,42 +77,46 @@ public class BackupRestoreUtils extends SolrTestCase {
public static void runCoreAdminCommand(
String baseUrl, String coreName, String action, Map<String, String>
params)
- throws IOException {
- StringBuilder builder = new StringBuilder();
- builder.append(baseUrl);
- builder.append("/admin/cores?action=");
- builder.append(action);
- builder.append("&core=");
- builder.append(coreName);
- for (Map.Entry<String, String> p : params.entrySet()) {
- builder.append("&");
- builder.append(p.getKey());
- builder.append("=");
- builder.append(p.getValue());
+ throws IOException, URISyntaxException {
+ final URI uri = new URI(baseUrl);
+ final var oldPath = uri.getPath() != null ? uri.getPath().substring(1) :
"";
+ final var newPath = "admin/cores";
+ final var finalPath = oldPath.isEmpty() ? newPath : oldPath + "/" +
newPath;
+
+ final URIBuilder builder =
+ new URIBuilder(uri)
+ .setPath(finalPath)
+ .addParameter("action", action)
+ .addParameter("core", coreName);
+
+ // Add additional parameters using loop
+ for (Map.Entry<String, String> entry : params.entrySet()) {
+ builder.addParameter(entry.getKey(), entry.getValue());
}
- String leaderUrl = builder.toString();
- executeHttpRequest(leaderUrl);
+
+ executeHttpRequest(builder.build());
}
public static void runReplicationHandlerCommand(
String baseUrl, String coreName, String action, String repoName, String
backupName)
- throws IOException {
- String leaderUrl =
- baseUrl
- + "/"
- + coreName
- + ReplicationHandler.PATH
- + "?command="
- + action
- + "&repository="
- + repoName
- + "&name="
- + backupName;
- executeHttpRequest(leaderUrl);
+ throws IOException, URISyntaxException {
+ final URI uri = new URI(baseUrl);
+ final var oldPath = uri.getPath() != null ? uri.getPath().substring(1) :
"";
+ final var newPath = coreName + ReplicationHandler.PATH;
+ final var finalPath = oldPath.isEmpty() ? newPath : oldPath + "/" +
newPath;
+
+ final URI finalURI =
+ new URIBuilder(uri)
+ .setPath(finalPath)
+ .addParameter("command", action)
+ .addParameter("repository", repoName)
+ .addParameter("name", backupName)
+ .build();
+ executeHttpRequest(finalURI);
}
- static void executeHttpRequest(String requestUrl) throws IOException {
- URL url = new URL(requestUrl);
+ private static void executeHttpRequest(URI uri) throws IOException {
+ URL url = uri.toURL();
try (InputStream stream = url.openStream()) {
assert stream != null;
}
diff --git
a/solr/test-framework/src/java/org/apache/solr/handler/TestRestoreCoreUtil.java
b/solr/test-framework/src/java/org/apache/solr/handler/TestRestoreCoreUtil.java
index de275b8ec94..cd52cf2e68b 100644
---
a/solr/test-framework/src/java/org/apache/solr/handler/TestRestoreCoreUtil.java
+++
b/solr/test-framework/src/java/org/apache/solr/handler/TestRestoreCoreUtil.java
@@ -18,6 +18,7 @@ package org.apache.solr.handler;
import java.io.IOException;
import java.io.InputStream;
+import java.net.URI;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.regex.Matcher;
@@ -35,7 +36,7 @@ public class TestRestoreCoreUtil {
+ ReplicationHandler.CMD_RESTORE_STATUS;
final Pattern pException = Pattern.compile("<str
name=\"exception\">(.*?)</str>");
- URL url = new URL(leaderUrl);
+ URL url = URI.create(leaderUrl).toURL();
try (InputStream stream = url.openStream()) {
String response = new String(stream.readAllBytes(),
StandardCharsets.UTF_8);
Matcher matcher = pException.matcher(response);