Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions gradle/validation/forbidden-apis/defaults.all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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>(**)
5 changes: 4 additions & 1 deletion solr/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,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
Expand Down Expand Up @@ -186,6 +186,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)

Expand All @@ -199,6 +201,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
Expand Down
65 changes: 30 additions & 35 deletions solr/core/src/java/org/apache/solr/cli/PostTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -272,12 +272,13 @@ public void runImpl(CommandLine cli) throws Exception {
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.");
Expand Down Expand Up @@ -403,7 +404,7 @@ private void doWebMode() {
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);
}
}
Expand Down Expand Up @@ -529,7 +530,7 @@ int postFiles(File[] files, OutputStream out, String type) {
postFile(srcFile, out, type);
Thread.sleep(delay * 1000L);
filesPosted++;
} catch (InterruptedException | MalformedURLException e) {
} catch (InterruptedException | URISyntaxException e) {
throw new RuntimeException(e);
}
}
Expand Down Expand Up @@ -637,8 +638,8 @@ protected int webCrawl(int level, OutputStream out) {
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="
Expand All @@ -652,7 +653,7 @@ protected int webCrawl(int level, OutputStream out) {
null,
out,
result.contentType,
postUrl);
postUri);
if (success) {
info("POSTed web resource " + url + " (depth: " + level + ")");
Thread.sleep(delay * 1000L);
Expand All @@ -665,7 +666,7 @@ protected int webCrawl(int level, OutputStream out) {
new ByteArrayInputStream(
content.array(), content.arrayOffset(), content.limit()),
result.contentType,
postUrl);
postUri);
subStack.addAll(children);
}
} else {
Expand Down Expand Up @@ -814,10 +815,10 @@ public static String appendParam(String url, String param) {
}

/** 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) {
Expand All @@ -829,7 +830,7 @@ public void postFile(File file, OutputStream output, String type) throws Malform
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")) {
Expand All @@ -847,7 +848,7 @@ public void postFile(File file, OutputStream output, String type) throws Malform
urlStr =
appendParam(urlStr, "literal.id=" + URLEncoder.encode(file.getAbsolutePath(), UTF_8));
}
url = new URL(urlStr);
uri = new URI(urlStr);
}
} else {
if (type == null) {
Expand All @@ -870,7 +871,7 @@ public void postFile(File file, OutputStream output, String type) throws Malform
+ " 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 {
Expand All @@ -888,18 +889,13 @@ public void postFile(File file, OutputStream output, String type) throws Malform
/**
* 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());
}

/**
Expand All @@ -922,15 +918,15 @@ protected static String guessType(File file) {
* @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");
}
}
Expand All @@ -942,7 +938,7 @@ public boolean postData(
HttpURLConnection urlConnection = null;
try {
try {
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection = (HttpURLConnection) (uri.toURL()).openConnection();
try {
urlConnection.setRequestMethod("POST");
} catch (ProtocolException e) {
Expand Down Expand Up @@ -1239,9 +1235,9 @@ public boolean isDisallowedByRobots(URL url) {
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
Expand Down Expand Up @@ -1289,17 +1285,16 @@ protected List<String> parseRobotsTxt(InputStream is) throws IOException {
* @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);
Expand All @@ -1318,7 +1313,7 @@ protected Set<URI> getLinksFromWebPage(URL url, InputStream is, String type, URL
}
}
}
} catch (MalformedURLException e) {
} catch (URISyntaxException e) {
warn("Malformed URL " + url);
} catch (IOException e) {
warn("IOException opening URL " + url + ": " + e.getMessage());
Expand Down
6 changes: 3 additions & 3 deletions solr/core/src/java/org/apache/solr/cli/RunExampleTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
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;
Expand Down Expand Up @@ -874,7 +874,7 @@ protected Map<String, Object> getNodeStatus(String solrUrl, int maxWaitSecs) thr
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);
Expand All @@ -884,7 +884,7 @@ protected Map<String, Object> getNodeStatus(String solrUrl, int maxWaitSecs) thr
if (verbose)
echo(
"\nSolr is running on "
+ solrURL.getPort()
+ solrURI.getPort()
+ " in "
+ mode
+ " mode with status:\n"
Expand Down
Loading