This is an automated email from the ASF dual-hosted git repository.
dsmiley pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/main by this push:
new 9f6ef0acfeb SOLR-17884: SolrJ, minimize org.apache.http usage (#3602)
9f6ef0acfeb is described below
commit 9f6ef0acfebd9458cae8c5b1bc3ba0224ff26933
Author: David Smiley <[email protected]>
AuthorDate: Mon Sep 8 20:08:21 2025 -0400
SOLR-17884: SolrJ, minimize org.apache.http usage (#3602)
SolrJ users not using deprecated SolrClients can safely exclude Apache
HttpClient dependencies.
* SolrJ Utils: Move org.apache.http usage to HttpClientUtil
* SolrHttpConstants extracted from HttpClientUtil
Did *not* bother updating deprecated classes that refer to
HttpClientUtil; not necessary.
---
solr/CHANGES.txt | 3 +
.../java/org/apache/solr/core/SolrXmlConfig.java | 10 +-
.../java/org/apache/solr/handler/IndexFetcher.java | 8 +-
.../handler/component/HttpShardHandlerFactory.java | 13 +--
.../org/apache/solr/update/UpdateShardHandler.java | 14 +--
.../solr/update/UpdateShardHandlerConfig.java | 14 +--
.../apache/solr/cloud/RecoveryZkTestWithAuth.java | 4 +-
.../solr/cloud/TestMiniSolrCloudClusterSSL.java | 8 +-
.../solr/core/TestHttpSolrClientProvider.java | 4 +-
.../solr/filestore/TestDistribFileStore.java | 7 +-
.../handler/admin/api/ClusterPropsAPITest.java | 34 ++++--
.../solr/metrics/SolrMetricsIntegrationTest.java | 7 +-
.../src/test/org/apache/solr/pkg/TestPackages.java | 7 +-
.../solr/security/BasicAuthIntegrationTest.java | 4 +-
.../solr/security/BasicAuthStandaloneTest.java | 2 +-
.../apache/solr/security/MultiAuthPluginTest.java | 2 +-
.../security/jwt/JWTAuthPluginIntegrationTest.java | 3 +-
.../pages/major-changes-in-solr-9.adoc | 9 +-
.../solr/client/solrj/io/SolrClientCache.java | 6 +-
.../solrj/impl/ConcurrentUpdateSolrClient.java | 3 +-
.../solr/client/solrj/impl/Http2SolrClient.java | 4 +-
.../solrj/impl/HttpClientBuilderFactory.java | 2 +-
.../solr/client/solrj/impl/HttpClientUtil.java | 117 +++++++++++++--------
.../solr/client/solrj/impl/HttpSolrClient.java | 2 +-
.../solrj/impl/HttpSolrClientBuilderBase.java | 4 +-
.../PreemptiveBasicAuthClientBuilderFactory.java | 8 +-
.../solr/client/solrj/impl/SolrHttpConstants.java | 62 +++++++++++
.../java/org/apache/solr/common/util/Utils.java | 70 ------------
.../client/solrj/SolrSchemalessExampleTest.java | 3 +-
.../client/solrj/impl/Http2SolrClientTest.java | 6 +-
.../apache/solr/cloud/SolrCloudAuthTestCase.java | 3 +-
.../java/org/apache/solr/util/SSLTestConfig.java | 4 +-
32 files changed, 250 insertions(+), 197 deletions(-)
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index b7015ff004d..784507143b2 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -239,6 +239,9 @@ Improvements
* SOLR-17893: Speed up Remote Proxy for high QPS, utilizing ClusterState
caching. (Houston Putman)
+* SOLR-17884: SolrJ users not using deprecated SolrClients can safely exclude
Apache HttpClient dependencies.
+ (David Smiley)
+
Optimizations
---------------------
(No changes)
diff --git a/solr/core/src/java/org/apache/solr/core/SolrXmlConfig.java
b/solr/core/src/java/org/apache/solr/core/SolrXmlConfig.java
index 2c4479ce64b..1206dea0d3a 100644
--- a/solr/core/src/java/org/apache/solr/core/SolrXmlConfig.java
+++ b/solr/core/src/java/org/apache/solr/core/SolrXmlConfig.java
@@ -38,7 +38,7 @@ import java.util.function.Consumer;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import javax.management.MBeanServer;
-import org.apache.solr.client.solrj.impl.HttpClientUtil;
+import org.apache.solr.client.solrj.impl.SolrHttpConstants;
import org.apache.solr.cloud.ClusterSingleton;
import org.apache.solr.cluster.placement.PlacementPluginFactory;
import org.apache.solr.common.ConfigNode;
@@ -435,10 +435,10 @@ public class SolrXmlConfig {
boolean defined = false;
- int maxUpdateConnections = HttpClientUtil.DEFAULT_MAXCONNECTIONS;
- int maxUpdateConnectionsPerHost =
HttpClientUtil.DEFAULT_MAXCONNECTIONSPERHOST;
- int distributedSocketTimeout = HttpClientUtil.DEFAULT_SO_TIMEOUT;
- int distributedConnectionTimeout = HttpClientUtil.DEFAULT_CONNECT_TIMEOUT;
+ int maxUpdateConnections = SolrHttpConstants.DEFAULT_MAXCONNECTIONS;
+ int maxUpdateConnectionsPerHost =
SolrHttpConstants.DEFAULT_MAXCONNECTIONSPERHOST;
+ int distributedSocketTimeout = SolrHttpConstants.DEFAULT_SO_TIMEOUT;
+ int distributedConnectionTimeout =
SolrHttpConstants.DEFAULT_CONNECT_TIMEOUT;
String metricNameStrategy =
UpdateShardHandlerConfig.DEFAULT_METRICNAMESTRATEGY;
int maxRecoveryThreads =
UpdateShardHandlerConfig.DEFAULT_MAXRECOVERYTHREADS;
diff --git a/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java
b/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java
index eb5cf2f655f..a2cb129fedb 100644
--- a/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java
+++ b/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java
@@ -91,8 +91,8 @@ import org.apache.lucene.store.IndexOutput;
import org.apache.solr.client.api.model.FileMetaData;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.Http2SolrClient;
-import org.apache.solr.client.solrj.impl.HttpClientUtil;
import org.apache.solr.client.solrj.impl.InputStreamResponseParser;
+import org.apache.solr.client.solrj.impl.SolrHttpConstants;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.cloud.CloudDescriptor;
import org.apache.solr.cloud.ZkController;
@@ -284,10 +284,10 @@ public class IndexFetcher {
String compress = (String) initArgs.get(COMPRESSION);
useInternalCompression = ReplicationHandler.INTERNAL.equals(compress);
useExternalCompression = ReplicationHandler.EXTERNAL.equals(compress);
- soTimeout = getParameter(initArgs, HttpClientUtil.PROP_SO_TIMEOUT, 120000,
null);
+ soTimeout = getParameter(initArgs, SolrHttpConstants.PROP_SO_TIMEOUT,
120000, null);
- String httpBasicAuthUser = (String)
initArgs.get(HttpClientUtil.PROP_BASIC_AUTH_USER);
- String httpBasicAuthPassword = (String)
initArgs.get(HttpClientUtil.PROP_BASIC_AUTH_PASS);
+ String httpBasicAuthUser = (String)
initArgs.get(SolrHttpConstants.PROP_BASIC_AUTH_USER);
+ String httpBasicAuthPassword = (String)
initArgs.get(SolrHttpConstants.PROP_BASIC_AUTH_PASS);
solrClient =
createSolrClient(solrCore, httpBasicAuthUser, httpBasicAuthPassword,
leaderBaseUrl);
}
diff --git
a/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandlerFactory.java
b/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandlerFactory.java
index ac7dc0cf8e0..67b3e6e300b 100644
---
a/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandlerFactory.java
+++
b/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandlerFactory.java
@@ -31,9 +31,9 @@ import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.impl.Http2SolrClient;
-import org.apache.solr.client.solrj.impl.HttpClientUtil;
import org.apache.solr.client.solrj.impl.LBHttp2SolrClient;
import org.apache.solr.client.solrj.impl.LBSolrClient;
+import org.apache.solr.client.solrj.impl.SolrHttpConstants;
import org.apache.solr.client.solrj.request.QueryRequest;
import
org.apache.solr.client.solrj.routing.AffinityReplicaListTransformerFactory;
import org.apache.solr.client.solrj.routing.ReplicaListTransformer;
@@ -294,17 +294,18 @@ public class HttpShardHandlerFactory extends
ShardHandlerFactory
int connectionTimeout =
getParameter(
args,
- HttpClientUtil.PROP_CONNECTION_TIMEOUT,
- HttpClientUtil.DEFAULT_CONNECT_TIMEOUT,
+ SolrHttpConstants.PROP_CONNECTION_TIMEOUT,
+ SolrHttpConstants.DEFAULT_CONNECT_TIMEOUT,
sb);
int maxConnectionsPerHost =
getParameter(
args,
- HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST,
- HttpClientUtil.DEFAULT_MAXCONNECTIONSPERHOST,
+ SolrHttpConstants.PROP_MAX_CONNECTIONS_PER_HOST,
+ SolrHttpConstants.DEFAULT_MAXCONNECTIONSPERHOST,
sb);
int soTimeout =
- getParameter(args, HttpClientUtil.PROP_SO_TIMEOUT,
HttpClientUtil.DEFAULT_SO_TIMEOUT, sb);
+ getParameter(
+ args, SolrHttpConstants.PROP_SO_TIMEOUT,
SolrHttpConstants.DEFAULT_SO_TIMEOUT, sb);
this.defaultClient =
new Http2SolrClient.Builder()
diff --git a/solr/core/src/java/org/apache/solr/update/UpdateShardHandler.java
b/solr/core/src/java/org/apache/solr/update/UpdateShardHandler.java
index 04a529a4bdf..e214c0cc3a8 100644
--- a/solr/core/src/java/org/apache/solr/update/UpdateShardHandler.java
+++ b/solr/core/src/java/org/apache/solr/update/UpdateShardHandler.java
@@ -24,7 +24,7 @@ import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import org.apache.solr.client.solrj.impl.Http2SolrClient;
-import org.apache.solr.client.solrj.impl.HttpClientUtil;
+import org.apache.solr.client.solrj.impl.SolrHttpConstants;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.util.ExecutorUtil;
@@ -73,22 +73,22 @@ public class UpdateShardHandler implements SolrInfoBean {
private SolrMetricsContext solrMetricsContext;
- private int socketTimeout = HttpClientUtil.DEFAULT_SO_TIMEOUT;
- private int connectionTimeout = HttpClientUtil.DEFAULT_CONNECT_TIMEOUT;
+ private int socketTimeout = SolrHttpConstants.DEFAULT_SO_TIMEOUT;
+ private int connectionTimeout = SolrHttpConstants.DEFAULT_CONNECT_TIMEOUT;
public UpdateShardHandler(UpdateShardHandlerConfig cfg) {
ModifiableSolrParams clientParams = new ModifiableSolrParams();
if (cfg != null) {
- clientParams.set(HttpClientUtil.PROP_SO_TIMEOUT,
cfg.getDistributedSocketTimeout());
+ clientParams.set(SolrHttpConstants.PROP_SO_TIMEOUT,
cfg.getDistributedSocketTimeout());
clientParams.set(
- HttpClientUtil.PROP_CONNECTION_TIMEOUT,
cfg.getDistributedConnectionTimeout());
+ SolrHttpConstants.PROP_CONNECTION_TIMEOUT,
cfg.getDistributedConnectionTimeout());
// following is done only for logging complete configuration.
// The maxConnections and maxConnectionsPerHost have already been
specified on the connection
// manager
- clientParams.set(HttpClientUtil.PROP_MAX_CONNECTIONS,
cfg.getMaxUpdateConnections());
+ clientParams.set(SolrHttpConstants.PROP_MAX_CONNECTIONS,
cfg.getMaxUpdateConnections());
clientParams.set(
- HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST,
cfg.getMaxUpdateConnectionsPerHost());
+ SolrHttpConstants.PROP_MAX_CONNECTIONS_PER_HOST,
cfg.getMaxUpdateConnectionsPerHost());
socketTimeout = cfg.getDistributedSocketTimeout();
connectionTimeout = cfg.getDistributedConnectionTimeout();
}
diff --git
a/solr/core/src/java/org/apache/solr/update/UpdateShardHandlerConfig.java
b/solr/core/src/java/org/apache/solr/update/UpdateShardHandlerConfig.java
index 9913f86e397..46ffc19493b 100644
--- a/solr/core/src/java/org/apache/solr/update/UpdateShardHandlerConfig.java
+++ b/solr/core/src/java/org/apache/solr/update/UpdateShardHandlerConfig.java
@@ -16,7 +16,7 @@
*/
package org.apache.solr.update;
-import org.apache.solr.client.solrj.impl.HttpClientUtil;
+import org.apache.solr.client.solrj.impl.SolrHttpConstants;
public class UpdateShardHandlerConfig {
@@ -25,17 +25,17 @@ public class UpdateShardHandlerConfig {
public static final UpdateShardHandlerConfig DEFAULT =
new UpdateShardHandlerConfig(
- HttpClientUtil.DEFAULT_MAXCONNECTIONS,
- HttpClientUtil.DEFAULT_MAXCONNECTIONSPERHOST,
- HttpClientUtil.DEFAULT_SO_TIMEOUT,
- HttpClientUtil.DEFAULT_CONNECT_TIMEOUT,
+ SolrHttpConstants.DEFAULT_MAXCONNECTIONS,
+ SolrHttpConstants.DEFAULT_MAXCONNECTIONSPERHOST,
+ SolrHttpConstants.DEFAULT_SO_TIMEOUT,
+ SolrHttpConstants.DEFAULT_CONNECT_TIMEOUT,
DEFAULT_METRICNAMESTRATEGY,
DEFAULT_MAXRECOVERYTHREADS);
public static final UpdateShardHandlerConfig TEST_DEFAULT =
new UpdateShardHandlerConfig(
- HttpClientUtil.DEFAULT_MAXCONNECTIONS,
- HttpClientUtil.DEFAULT_MAXCONNECTIONSPERHOST,
+ SolrHttpConstants.DEFAULT_MAXCONNECTIONS,
+ SolrHttpConstants.DEFAULT_MAXCONNECTIONSPERHOST,
30000,
30000,
UpdateShardHandlerConfig.DEFAULT_METRICNAMESTRATEGY,
diff --git
a/solr/core/src/test/org/apache/solr/cloud/RecoveryZkTestWithAuth.java
b/solr/core/src/test/org/apache/solr/cloud/RecoveryZkTestWithAuth.java
index 600afb136af..05691b2c80c 100644
--- a/solr/core/src/test/org/apache/solr/cloud/RecoveryZkTestWithAuth.java
+++ b/solr/core/src/test/org/apache/solr/cloud/RecoveryZkTestWithAuth.java
@@ -27,8 +27,8 @@ import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrResponse;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.CloudLegacySolrClient;
-import org.apache.solr.client.solrj.impl.HttpClientUtil;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
+import org.apache.solr.client.solrj.impl.SolrHttpConstants;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.client.solrj.request.UpdateRequest;
@@ -48,7 +48,7 @@ public class RecoveryZkTestWithAuth extends SolrCloudTestCase
{
// for context)
if (rarely()) {
System.setProperty(
- HttpClientUtil.SYS_PROP_HTTP_CLIENT_BUILDER_FACTORY,
+ SolrHttpConstants.SYS_PROP_HTTP_CLIENT_BUILDER_FACTORY,
"org.apache.solr.client.solrj.impl.PreemptiveBasicAuthClientBuilderFactory");
System.setProperty("solr.security.auth.basicauth.credentials",
SecurityJson.USER_PASS);
}
diff --git
a/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudClusterSSL.java
b/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudClusterSSL.java
index 5602457c0c1..7b4dbb21a15 100644
--- a/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudClusterSSL.java
+++ b/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudClusterSSL.java
@@ -39,6 +39,7 @@ import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.impl.Http2SolrClient;
import org.apache.solr.client.solrj.impl.HttpClientUtil;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
+import org.apache.solr.client.solrj.impl.SolrHttpConstants;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.CoreAdminRequest;
import org.apache.solr.common.cloud.ZkStateReader;
@@ -81,7 +82,7 @@ public class TestMiniSolrCloudClusterSSL extends
SolrTestCaseJ4 {
@Rule
public TestRule syspropRestore =
- new
TestRuleRestoreSystemProperties(HttpClientUtil.SYS_PROP_CHECK_PEER_NAME);
+ new
TestRuleRestoreSystemProperties(SolrHttpConstants.SYS_PROP_CHECK_PEER_NAME);
@Before
public void before() {
@@ -177,7 +178,8 @@ public class TestMiniSolrCloudClusterSSL extends
SolrTestCaseJ4 {
SSLContext.setDefault(
sslConfig.isSSLMode() ? sslConfig.buildClientSSLContext() :
DEFAULT_SSL_CONTEXT);
System.setProperty(
- HttpClientUtil.SYS_PROP_CHECK_PEER_NAME,
Boolean.toString(sslConfig.getCheckPeerName()));
+ SolrHttpConstants.SYS_PROP_CHECK_PEER_NAME,
+ Boolean.toString(sslConfig.getCheckPeerName()));
HttpClientUtil.resetHttpClientBuilder();
Http2SolrClient.resetSslContextFactory();
@@ -206,7 +208,7 @@ public class TestMiniSolrCloudClusterSSL extends
SolrTestCaseJ4 {
// now initialize a client that still uses the existing
SSLContext/Provider, so it will accept
// our existing certificate, but *does* care about validating the peer
name
- System.setProperty(HttpClientUtil.SYS_PROP_CHECK_PEER_NAME, "true");
+ System.setProperty(SolrHttpConstants.SYS_PROP_CHECK_PEER_NAME, "true");
HttpClientUtil.resetHttpClientBuilder();
Http2SolrClient.resetSslContextFactory();
diff --git
a/solr/core/src/test/org/apache/solr/core/TestHttpSolrClientProvider.java
b/solr/core/src/test/org/apache/solr/core/TestHttpSolrClientProvider.java
index 14b5a504634..3c3105923bf 100644
--- a/solr/core/src/test/org/apache/solr/core/TestHttpSolrClientProvider.java
+++ b/solr/core/src/test/org/apache/solr/core/TestHttpSolrClientProvider.java
@@ -22,7 +22,7 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import org.apache.solr.SolrTestCase;
-import org.apache.solr.client.solrj.impl.HttpClientUtil;
+import org.apache.solr.client.solrj.impl.SolrHttpConstants;
import org.apache.solr.metrics.SolrMetricsContext;
import org.apache.solr.update.UpdateShardHandlerConfig;
import org.junit.Before;
@@ -46,7 +46,7 @@ public class TestHttpSolrClientProvider extends SolrTestCase {
try (var httpSolrClientProvider = new HttpSolrClientProvider(null,
parentSolrMetricCtx); ) {
assertEquals(
httpSolrClientProvider.getSolrClient().getIdleTimeout(),
- HttpClientUtil.DEFAULT_SO_TIMEOUT);
+ SolrHttpConstants.DEFAULT_SO_TIMEOUT);
}
}
diff --git
a/solr/core/src/test/org/apache/solr/filestore/TestDistribFileStore.java
b/solr/core/src/test/org/apache/solr/filestore/TestDistribFileStore.java
index f1cca81da47..5957ea93e63 100644
--- a/solr/core/src/test/org/apache/solr/filestore/TestDistribFileStore.java
+++ b/solr/core/src/test/org/apache/solr/filestore/TestDistribFileStore.java
@@ -38,6 +38,7 @@ import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrServerException;
import
org.apache.solr.client.solrj.impl.BaseHttpSolrClient.RemoteExecutionException;
+import org.apache.solr.client.solrj.impl.HttpClientUtil;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.request.FileStoreApi;
import org.apache.solr.client.solrj.request.V2Request;
@@ -182,7 +183,7 @@ public class TestDistribFileStore extends SolrCloudTestCase
{
j.getBaseURLV2() + "/cluster/filestore/files" +
"/package/mypkg/v1.0/runtimelibs.jar";
HttpDelete del = new HttpDelete(path);
try (HttpSolrClient cl = (HttpSolrClient) j.newClient()) {
- Utils.executeHttpMethod(cl.getHttpClient(), path, Utils.JSONCONSUMER,
del);
+ HttpClientUtil.executeHttpMethod(cl.getHttpClient(), path,
Utils.JSONCONSUMER, del);
}
expected =
Collections.singletonMap(":files:/package/mypkg/v1.0/runtimelibs.jar", null);
checkAllNodesForFile(cluster, "/package/mypkg/v1.0/runtimelibs.jar",
expected, false);
@@ -205,7 +206,7 @@ public class TestDistribFileStore extends SolrCloudTestCase
{
if (verifyContent) {
try (HttpSolrClient solrClient = (HttpSolrClient)
jettySolrRunner.newClient()) {
ByteBuffer buf =
- Utils.executeGET(
+ HttpClientUtil.executeGET(
solrClient.getHttpClient(),
baseUrl + "/cluster/filestore/files" + path,
Utils.newBytesConsumer(Integer.MAX_VALUE));
@@ -230,7 +231,7 @@ public class TestDistribFileStore extends SolrCloudTestCase
{
public NavigableObject call() throws Exception {
try (HttpSolrClient solrClient = (HttpSolrClient) jetty.newClient()) {
return (NavigableObject)
- Utils.executeGET(solrClient.getHttpClient(), this.url,
JAVABINCONSUMER);
+ HttpClientUtil.executeGET(solrClient.getHttpClient(), this.url,
JAVABINCONSUMER);
}
}
diff --git
a/solr/core/src/test/org/apache/solr/handler/admin/api/ClusterPropsAPITest.java
b/solr/core/src/test/org/apache/solr/handler/admin/api/ClusterPropsAPITest.java
index f690dbc1498..a3cbbd2b6dc 100644
---
a/solr/core/src/test/org/apache/solr/handler/admin/api/ClusterPropsAPITest.java
+++
b/solr/core/src/test/org/apache/solr/handler/admin/api/ClusterPropsAPITest.java
@@ -28,6 +28,7 @@ import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.StringEntity;
+import org.apache.solr.client.solrj.impl.HttpClientUtil;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.cloud.SolrCloudTestCase;
import org.apache.solr.common.util.Utils;
@@ -91,7 +92,8 @@ public class ClusterPropsAPITest extends SolrCloudTestCase {
// List Properties, confirm the test property does not exist
// This ignores eventually existing other properties
Object o =
- Utils.executeGET(client.getHttpClient(), baseUrlV2ClusterProps,
Utils.JSONCONSUMER);
+ HttpClientUtil.executeGET(
+ client.getHttpClient(), baseUrlV2ClusterProps,
Utils.JSONCONSUMER);
assertNotNull(o);
@SuppressWarnings("unchecked")
List<String> initProperties = (List<String>) getObjectByPath(o, true,
"clusterProperties");
@@ -102,11 +104,15 @@ public class ClusterPropsAPITest extends
SolrCloudTestCase {
HttpPut httpPut = new HttpPut(path);
httpPut.setHeader("Content-Type", "application/json");
httpPut.setEntity(new StringEntity("{\"value\":\"" +
testClusterPropertyValue + "\"}"));
- o = Utils.executeHttpMethod(client.getHttpClient(), path,
Utils.JSONCONSUMER, httpPut);
+ o =
+ HttpClientUtil.executeHttpMethod(
+ client.getHttpClient(), path, Utils.JSONCONSUMER, httpPut);
assertNotNull(o);
// List Properties, this time there should be the just added property
- o = Utils.executeGET(client.getHttpClient(), baseUrlV2ClusterProps,
Utils.JSONCONSUMER);
+ o =
+ HttpClientUtil.executeGET(
+ client.getHttpClient(), baseUrlV2ClusterProps,
Utils.JSONCONSUMER);
assertNotNull(o);
@SuppressWarnings("unchecked")
List<String> updatedProperties = (List<String>) getObjectByPath(o, true,
"clusterProperties");
@@ -114,7 +120,7 @@ public class ClusterPropsAPITest extends SolrCloudTestCase {
// Fetch Cluster Property
// Same path as used in the Create step above
- o = Utils.executeGET(client.getHttpClient(), path, Utils.JSONCONSUMER);
+ o = HttpClientUtil.executeGET(client.getHttpClient(), path,
Utils.JSONCONSUMER);
assertNotNull(o);
assertEquals(testClusterProperty, (String) getObjectByPath(o, true,
"clusterProperty/name"));
assertEquals(
@@ -123,11 +129,15 @@ public class ClusterPropsAPITest extends
SolrCloudTestCase {
// Delete Cluster Property
// Same path as used in the Create step above
HttpDelete httpDelete = new HttpDelete(path);
- o = Utils.executeHttpMethod(client.getHttpClient(), path,
Utils.JSONCONSUMER, httpDelete);
+ o =
+ HttpClientUtil.executeHttpMethod(
+ client.getHttpClient(), path, Utils.JSONCONSUMER, httpDelete);
assertNotNull(o);
// List Properties, the test property should be gone
- o = Utils.executeGET(client.getHttpClient(), baseUrlV2ClusterProps,
Utils.JSONCONSUMER);
+ o =
+ HttpClientUtil.executeGET(
+ client.getHttpClient(), baseUrlV2ClusterProps,
Utils.JSONCONSUMER);
assertNotNull(o);
@SuppressWarnings("unchecked")
List<String> clearedProperties = (List<String>) getObjectByPath(o, true,
"clusterProperties");
@@ -143,13 +153,13 @@ public class ClusterPropsAPITest extends
SolrCloudTestCase {
httpPut.setHeader("Content-Type", "application/json");
httpPut.setEntity(new
StringEntity(testClusterPropertyBulkAndNestedValues));
Object o =
- Utils.executeHttpMethod(
+ HttpClientUtil.executeHttpMethod(
client.getHttpClient(), baseUrlV2ClusterProps,
Utils.JSONCONSUMER, httpPut);
assertNotNull(o);
// Fetch Cluster Property checking the not-nested property set above
String path = baseUrlV2ClusterProps + "/" + testClusterProperty;
- o = Utils.executeGET(client.getHttpClient(), path, Utils.JSONCONSUMER);
+ o = HttpClientUtil.executeGET(client.getHttpClient(), path,
Utils.JSONCONSUMER);
assertNotNull(o);
assertEquals(testClusterProperty, (String) getObjectByPath(o, true,
"clusterProperty/name"));
assertEquals(
@@ -157,17 +167,19 @@ public class ClusterPropsAPITest extends
SolrCloudTestCase {
// Fetch Cluster Property checking the nested property set above
path = baseUrlV2ClusterProps + "/" + "defaults";
- o = Utils.executeGET(client.getHttpClient(), path, Utils.JSONCONSUMER);
+ o = HttpClientUtil.executeGET(client.getHttpClient(), path,
Utils.JSONCONSUMER);
assertNotNull(o);
assertEquals("defaults", (String) getObjectByPath(o, true,
"clusterProperty/name"));
assertEquals(4L, getObjectByPath(o, true,
"clusterProperty/value/collection/numShards"));
// Clean up to leave the state unchanged
HttpDelete httpDelete = new HttpDelete(path);
- Utils.executeHttpMethod(client.getHttpClient(), path,
Utils.JSONCONSUMER, httpDelete);
+ HttpClientUtil.executeHttpMethod(
+ client.getHttpClient(), path, Utils.JSONCONSUMER, httpDelete);
path = baseUrlV2ClusterProps + "/" + testClusterProperty;
httpDelete = new HttpDelete(path);
- Utils.executeHttpMethod(client.getHttpClient(), path,
Utils.JSONCONSUMER, httpDelete);
+ HttpClientUtil.executeHttpMethod(
+ client.getHttpClient(), path, Utils.JSONCONSUMER, httpDelete);
}
}
diff --git
a/solr/core/src/test/org/apache/solr/metrics/SolrMetricsIntegrationTest.java
b/solr/core/src/test/org/apache/solr/metrics/SolrMetricsIntegrationTest.java
index 9da5cfcaf7c..e1e178e0ae3 100644
--- a/solr/core/src/test/org/apache/solr/metrics/SolrMetricsIntegrationTest.java
+++ b/solr/core/src/test/org/apache/solr/metrics/SolrMetricsIntegrationTest.java
@@ -32,6 +32,7 @@ import org.apache.http.client.HttpClient;
import org.apache.lucene.tests.util.TestUtil;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.impl.HttpClientUtil;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.cloud.MiniSolrCloudCluster;
import org.apache.solr.common.util.Utils;
@@ -241,7 +242,7 @@ public class SolrMetricsIntegrationTest extends
SolrTestCaseJ4 {
Map<String, Object> zkMmetrics =
(Map<String, Object>)
Utils.getObjectByPath(
- Utils.executeGET(httpClient, url, Utils.JSONCONSUMER),
+ HttpClientUtil.executeGET(httpClient, url,
Utils.JSONCONSUMER),
false,
List.of("metrics", "solr.node:CONTAINER.zkClient"));
@@ -262,7 +263,7 @@ public class SolrMetricsIntegrationTest extends
SolrTestCaseJ4 {
for (String k : allKeys) {
assertNotNull(zkMmetrics.get(k));
}
- Utils.executeGET(
+ HttpClientUtil.executeGET(
httpClient,
j.getBaseURLV2() + "/cluster/zookeeper/children/live_nodes",
Utils.JSONCONSUMER);
@@ -270,7 +271,7 @@ public class SolrMetricsIntegrationTest extends
SolrTestCaseJ4 {
Map<String, Object> zkMmetricsNew =
(Map<String, Object>)
Utils.getObjectByPath(
- Utils.executeGET(httpClient, url, Utils.JSONCONSUMER),
+ HttpClientUtil.executeGET(httpClient, url,
Utils.JSONCONSUMER),
false,
List.of("metrics", "solr.node:CONTAINER.zkClient"));
diff --git a/solr/core/src/test/org/apache/solr/pkg/TestPackages.java
b/solr/core/src/test/org/apache/solr/pkg/TestPackages.java
index 69d1df37544..973a3e6dc52 100644
--- a/solr/core/src/test/org/apache/solr/pkg/TestPackages.java
+++ b/solr/core/src/test/org/apache/solr/pkg/TestPackages.java
@@ -47,6 +47,7 @@ import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.BaseHttpSolrClient;
+import org.apache.solr.client.solrj.impl.HttpClientUtil;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.GenericSolrRequest;
@@ -535,7 +536,8 @@ public class TestPackages extends SolrCloudTestCase {
10,
() ->
NavigableObject.wrap(
- Utils.executeGET(client.getHttpClient(), jetty.getBaseUrl()
+ uri, parser)),
+ HttpClientUtil.executeGET(
+ client.getHttpClient(), jetty.getBaseUrl() + uri,
parser)),
expected);
}
}
@@ -690,7 +692,8 @@ public class TestPackages extends SolrCloudTestCase {
public NavigableObject call() throws Exception {
try (HttpSolrClient solrClient = (HttpSolrClient)
jetty.newClient()) {
return (NavigableObject)
- Utils.executeGET(solrClient.getHttpClient(), path,
Utils.JAVABINCONSUMER);
+ HttpClientUtil.executeGET(
+ solrClient.getHttpClient(), path,
Utils.JAVABINCONSUMER);
}
}
},
diff --git
a/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java
b/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java
index 22f5f4a6857..4ac0ca904a7 100644
--- a/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java
+++ b/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java
@@ -173,7 +173,7 @@ public class BasicAuthIntegrationTest extends
SolrCloudAuthTestCase {
verifySecurityStatus(cl, baseUrl + authcPrefix,
"authentication.enabled", "true", 20);
HttpResponse r = cl.execute(httpPost);
int statusCode = r.getStatusLine().getStatusCode();
- Utils.consumeFully(r.getEntity());
+ HttpClientUtil.consumeFully(r.getEntity());
assertEquals("proper_cred sent, but access denied", 200, statusCode);
assertPkiAuthMetricsMinimums(0, 0, 0, 0, 0, 0);
assertAuthMetricsMinimums(4, 1, 3, 0, 0, 0);
@@ -463,7 +463,7 @@ public class BasicAuthIntegrationTest extends
SolrCloudAuthTestCase {
assertEquals(
"Non-200 response code. Response was " + response, 200,
r.getStatusLine().getStatusCode());
assertFalse("Response contained errors: " + response,
response.contains("errorMessages"));
- Utils.consumeFully(r.getEntity());
+ HttpClientUtil.consumeFully(r.getEntity());
// HACK (continued)...
final TimeOut timeout = new TimeOut(30, TimeUnit.SECONDS,
TimeSource.NANO_TIME);
diff --git
a/solr/core/src/test/org/apache/solr/security/BasicAuthStandaloneTest.java
b/solr/core/src/test/org/apache/solr/security/BasicAuthStandaloneTest.java
index bdd1df4b61a..c1ef9d05b67 100644
--- a/solr/core/src/test/org/apache/solr/security/BasicAuthStandaloneTest.java
+++ b/solr/core/src/test/org/apache/solr/security/BasicAuthStandaloneTest.java
@@ -179,7 +179,7 @@ public class BasicAuthStandaloneTest extends SolrTestCaseJ4
{
httpPost.addHeader("Content-Type", "application/json; charset=UTF-8");
HttpResponse r = cl.execute(httpPost);
int statusCode = r.getStatusLine().getStatusCode();
- Utils.consumeFully(r.getEntity());
+ HttpClientUtil.consumeFully(r.getEntity());
assertEquals("proper_cred sent, but access denied", expectStatusCode,
statusCode);
}
diff --git
a/solr/core/src/test/org/apache/solr/security/MultiAuthPluginTest.java
b/solr/core/src/test/org/apache/solr/security/MultiAuthPluginTest.java
index 9376be86397..d952569ee40 100644
--- a/solr/core/src/test/org/apache/solr/security/MultiAuthPluginTest.java
+++ b/solr/core/src/test/org/apache/solr/security/MultiAuthPluginTest.java
@@ -274,7 +274,7 @@ public class MultiAuthPluginTest extends SolrTestCaseJ4 {
HttpGet httpPost = new HttpGet(url);
HttpResponse r = cl.execute(httpPost);
int statusCode = r.getStatusLine().getStatusCode();
- Utils.consumeFully(r.getEntity());
+ HttpClientUtil.consumeFully(r.getEntity());
return statusCode;
}
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 ce73bf9d4a2..45e35d753fa 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
@@ -63,7 +63,6 @@ import org.apache.solr.cloud.SolrCloudAuthTestCase;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.util.Pair;
import org.apache.solr.common.util.TimeSource;
-import org.apache.solr.common.util.Utils;
import org.apache.solr.embedded.JettySolrRunner;
import org.apache.solr.util.CryptoKeys;
import org.apache.solr.util.RTimer;
@@ -530,7 +529,7 @@ public class JWTAuthPluginIntegrationTest extends
SolrCloudAuthTestCase {
assertEquals(
"Non-200 response code. Response was " + response, 200,
r.getStatusLine().getStatusCode());
assertFalse("Response contained errors: " + response,
response.contains("errorMessages"));
- Utils.consumeFully(r.getEntity());
+ HttpClientUtil.consumeFully(r.getEntity());
// HACK (continued)...
final TimeOut timeout = new TimeOut(30, TimeUnit.SECONDS,
TimeSource.NANO_TIME);
diff --git
a/solr/solr-ref-guide/modules/upgrade-notes/pages/major-changes-in-solr-9.adoc
b/solr/solr-ref-guide/modules/upgrade-notes/pages/major-changes-in-solr-9.adoc
index 52fe51678d1..4ccc70f2560 100644
---
a/solr/solr-ref-guide/modules/upgrade-notes/pages/major-changes-in-solr-9.adoc
+++
b/solr/solr-ref-guide/modules/upgrade-notes/pages/major-changes-in-solr-9.adoc
@@ -67,6 +67,13 @@ It is always strongly recommended that you fully reindex
your documents after a
In Solr 8, it was possible to add docValues to a schema without re-indexing
via `UninvertDocValuesMergePolicy`, an advanced/expert utility.
Due to changes in Lucene 9, that isn't possible any more.
+== Solr 9.10
+
+=== SolrJ
+
+SolrJ users not using SolrClients that use Apache HttpClient can safely
exclude those dependencies.
+SolrJ users not using SolrClients that use Jetty HttpClient can safely exclude
those dependencies.
+
== Solr 9.9
=== SolrJ
@@ -243,7 +250,7 @@ Use `solr.useExitableDirectoryReader` to use the previous
behavior.
Please share your experience with Solr developers!
The previous behavior should not be enabled if timeAllowed isn't used because
unfortunately its performance tax is now imposed on all queries, even those
without timeAllowed.
-=== v2 API
+=== v2 API
* Solr's experimental "v2" API has seen a number of improvements in the 9.3
release.
+
It is now approaching parity with the functionality offered by Solr's v1 API.
In particular 9.3 adds v2 "CRUD" endpoints for interacting with alias
properties and collection snapshots. Several lower-level "replication" APIs
now also offer v2 equivalents.
diff --git
a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/SolrClientCache.java
b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/SolrClientCache.java
index 5e2412de057..6b0bf7f77f2 100644
---
a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/SolrClientCache.java
+++
b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/SolrClientCache.java
@@ -29,7 +29,7 @@ import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.impl.CloudHttp2SolrClient;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.impl.Http2SolrClient;
-import org.apache.solr.client.solrj.impl.HttpClientUtil;
+import org.apache.solr.client.solrj.impl.SolrHttpConstants;
import org.apache.solr.common.AlreadyClosedException;
import org.apache.solr.common.util.IOUtils;
import org.apache.solr.common.util.URLUtil;
@@ -42,9 +42,9 @@ public class SolrClientCache implements Closeable {
private static final int MIN_TIMEOUT = 60000;
private static final int minConnTimeout =
Math.max(
- Integer.getInteger(HttpClientUtil.PROP_CONNECTION_TIMEOUT,
MIN_TIMEOUT), MIN_TIMEOUT);
+ Integer.getInteger(SolrHttpConstants.PROP_CONNECTION_TIMEOUT,
MIN_TIMEOUT), MIN_TIMEOUT);
private static final int minSocketTimeout =
- Math.max(Integer.getInteger(HttpClientUtil.PROP_SO_TIMEOUT,
MIN_TIMEOUT), MIN_TIMEOUT);
+ Math.max(Integer.getInteger(SolrHttpConstants.PROP_SO_TIMEOUT,
MIN_TIMEOUT), MIN_TIMEOUT);
private String basicAuthCredentials = null; // Only support with the
http2SolrClient
diff --git
a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java
b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java
index 98ef90980bd..0d8e79412b1 100644
---
a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java
+++
b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java
@@ -53,7 +53,6 @@ import org.apache.solr.common.util.IOUtils;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SolrNamedThreadFactory;
import org.apache.solr.common.util.URLUtil;
-import org.apache.solr.common.util.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
@@ -407,7 +406,7 @@ public class ConcurrentUpdateSolrClient extends SolrClient {
} finally {
try {
if (response != null) {
- Utils.consumeFully(response.getEntity());
+ HttpClientUtil.consumeFully(response.getEntity());
}
} catch (Exception e) {
log.error("Error consuming and closing http response stream.", e);
diff --git
a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java
b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java
index 6123fa5ea98..1fe2b91eb83 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java
@@ -184,7 +184,7 @@ public class Http2SolrClient extends HttpSolrClientBase {
private void applyHttpClientBuilderFactory() {
String factoryClassName =
-
System.getProperty(HttpClientUtil.SYS_PROP_HTTP_CLIENT_BUILDER_FACTORY);
+
System.getProperty(SolrHttpConstants.SYS_PROP_HTTP_CLIENT_BUILDER_FACTORY);
if (factoryClassName != null) {
log.debug("Using Http Builder Factory: {}", factoryClassName);
HttpClientBuilderFactory factory;
@@ -1135,7 +1135,7 @@ public class Http2SolrClient extends HttpSolrClientBase {
/* package-private for testing */
static SslContextFactory.Client getDefaultSslContextFactory() {
- String checkPeerNameStr =
System.getProperty(HttpClientUtil.SYS_PROP_CHECK_PEER_NAME);
+ String checkPeerNameStr =
System.getProperty(SolrHttpConstants.SYS_PROP_CHECK_PEER_NAME);
boolean sslCheckPeerName = !"false".equalsIgnoreCase(checkPeerNameStr);
SslContextFactory.Client sslContextFactory = new
SslContextFactory.Client(!sslCheckPeerName);
diff --git
a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpClientBuilderFactory.java
b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpClientBuilderFactory.java
index 7e8645ff6ea..2295360c9cc 100644
---
a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpClientBuilderFactory.java
+++
b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpClientBuilderFactory.java
@@ -21,7 +21,7 @@ import java.io.Closeable;
/**
* A config hook for post-configuration of a {@linkplain Http2SolrClient} by
its builder.
*
- * @see HttpClientUtil#SYS_PROP_HTTP_CLIENT_BUILDER_FACTORY
+ * @see SolrHttpConstants#SYS_PROP_HTTP_CLIENT_BUILDER_FACTORY
* @lucene.experimental
*/
public interface HttpClientBuilderFactory extends Closeable {
diff --git
a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpClientUtil.java
b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpClientUtil.java
index 6170375048d..feb1bdbf056 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpClientUtil.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpClientUtil.java
@@ -20,6 +20,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.InvocationTargetException;
+import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.TimeUnit;
@@ -40,6 +41,8 @@ import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.config.RequestConfig.Builder;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
@@ -57,6 +60,8 @@ import
org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpRequestExecutor;
import org.apache.http.ssl.SSLContexts;
+import org.apache.http.util.EntityUtils;
+import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.ObjectReleaseTracker;
@@ -65,50 +70,27 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * Utility class for creating/configuring httpclient instances.
+ * Utility class for creating/configuring Apache {@link HttpClient} instances.
*
* <p>This class can touch internal HttpClient details and is subject to
change.
*
* @lucene.experimental
- * @deprecated Used to configure the Apache HTTP client. Please use the Http2
client
+ * @deprecated Used to configure the Apache HTTP client. Please use another
client
*/
@Deprecated(since = "9.0")
-public class HttpClientUtil {
+public class HttpClientUtil implements SolrHttpConstants {
private static final Logger log =
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
- public static final int DEFAULT_CONNECT_TIMEOUT = 60000;
- public static final int DEFAULT_SO_TIMEOUT = 600000;
- public static final int DEFAULT_MAXCONNECTIONSPERHOST = 100000;
- public static final int DEFAULT_MAXCONNECTIONS = 100000;
-
private static final int VALIDATE_AFTER_INACTIVITY_DEFAULT = 3000;
private static final int EVICT_IDLE_CONNECTIONS_DEFAULT = 50000;
private static final String VALIDATE_AFTER_INACTIVITY =
"validateAfterInactivity";
private static final String EVICT_IDLE_CONNECTIONS = "evictIdleConnections";
- // Maximum connections allowed per host
- public static final String PROP_MAX_CONNECTIONS_PER_HOST =
"maxConnectionsPerHost";
- // Maximum total connections allowed
- public static final String PROP_MAX_CONNECTIONS = "maxConnections";
// Retry http requests on error
public static final String PROP_USE_RETRY = "retry";
// Allow compression (deflate,gzip) if server supports it
public static final String PROP_ALLOW_COMPRESSION = "allowCompression";
- // Basic auth username
- public static final String PROP_BASIC_AUTH_USER = "httpBasicAuthUser";
- // Basic auth password
- public static final String PROP_BASIC_AUTH_PASS = "httpBasicAuthPassword";
-
- /**
- * System property consulted to determine if the default {@link
SocketFactoryRegistryProvider}
- * will require hostname validation of SSL Certificates. The default
behavior is to enforce peer
- * name validation.
- *
- * <p>This property will have no effect if {@link
#setSocketFactoryRegistryProvider} is used to
- * override the default {@link SocketFactoryRegistryProvider}
- */
- public static final String SYS_PROP_CHECK_PEER_NAME =
"solr.ssl.checkPeerName";
// * NOTE* The following params configure the default request config and this
// is overridden by SolrJ clients. Use the setters on the SolrJ clients
@@ -117,22 +99,6 @@ public class HttpClientUtil {
// Follow redirects
public static final String PROP_FOLLOW_REDIRECTS = "followRedirects";
- // socket timeout measured in ms, closes a socket if read
- // takes longer than x ms to complete. throws
- // java.net.SocketTimeoutException: Read timed out exception
- public static final String PROP_SO_TIMEOUT = "socketTimeout";
- // connection timeout measures in ms, closes a socket if connection
- // cannot be established within x ms. with a
- // java.net.SocketTimeoutException: Connection timed out
- public static final String PROP_CONNECTION_TIMEOUT = "connTimeout";
-
- /**
- * A Java system property to select the {@linkplain
HttpClientBuilderFactory} used for configuring
- * the {@linkplain HttpClientBuilder} instance by default.
- */
- public static final String SYS_PROP_HTTP_CLIENT_BUILDER_FACTORY =
- "solr.httpclient.builder.factory";
-
/**
* A Java system property to select the {@linkplain
SocketFactoryRegistryProvider} used for
* configuring the Apache HTTP clients.
@@ -176,6 +142,73 @@ public class HttpClientUtil {
}
}
+ public static <T> T executeGET(
+ HttpClient client, String url, Utils.InputStreamConsumer<T> consumer)
throws SolrException {
+ return executeHttpMethod(client, url, consumer, new HttpGet(url));
+ }
+
+ public static <T> T executeHttpMethod(
+ HttpClient client,
+ String url,
+ Utils.InputStreamConsumer<T> consumer,
+ HttpRequestBase httpMethod) {
+ T result = null;
+ HttpResponse rsp;
+ try {
+ rsp = client.execute(httpMethod);
+ } catch (IOException e) {
+ log.error("Error in request to url : {}", url, e);
+ throw new SolrException(SolrException.ErrorCode.UNKNOWN, "Error sending
request");
+ }
+ int statusCode = rsp.getStatusLine().getStatusCode();
+ if (statusCode != 200) {
+ try {
+ log.error(
+ "Failed a request to: {}, status: {}, body: {}",
+ url,
+ rsp.getStatusLine(),
+ EntityUtils.toString(rsp.getEntity(), StandardCharsets.UTF_8)); //
nowarn
+ } catch (IOException e) {
+ log.error("could not print error", e);
+ }
+ throw new
SolrException(SolrException.ErrorCode.getErrorCode(statusCode), "Unknown
error");
+ }
+ HttpEntity entity = rsp.getEntity();
+ try {
+ InputStream is = entity.getContent();
+ if (consumer != null) {
+
+ result = consumer.accept(is);
+ }
+ } catch (IOException e) {
+ throw new SolrException(SolrException.ErrorCode.UNKNOWN, e);
+ } finally {
+ consumeFully(entity);
+ }
+ return result;
+ }
+
+ /**
+ * If the passed entity has content, make sure it is fully read and closed.
+ *
+ * @param entity to consume or null
+ */
+ public static void consumeFully(HttpEntity entity) {
+ if (entity != null) {
+ try {
+ // make sure the stream is full read
+ Utils.readFully(entity.getContent());
+ } catch (UnsupportedOperationException e) {
+ // nothing to do then
+ } catch (IOException e) {
+ // quiet
+ } finally {
+ // close the stream
+ EntityUtils.consumeQuietly(entity);
+ }
+ }
+ }
+
public abstract static class SocketFactoryRegistryProvider {
/** Must be non-null */
public abstract Registry<ConnectionSocketFactory>
getSocketFactoryRegistry();
diff --git
a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java
b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java
index 17754ea8cf5..3f6e5a28c85 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java
@@ -721,7 +721,7 @@ public class HttpSolrClient extends BaseHttpSolrClient {
"IOException occurred when talking to server at: " + getBaseURL(),
e);
} finally {
if (shouldClose) {
- Utils.consumeFully(entity);
+ HttpClientUtil.consumeFully(entity);
}
}
}
diff --git
a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClientBuilderBase.java
b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClientBuilderBase.java
index 1b4f70e62f8..b2b2d4a6900 100644
---
a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClientBuilderBase.java
+++
b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClientBuilderBase.java
@@ -130,7 +130,7 @@ public abstract class HttpSolrClientBuilderBase<
public long getIdleTimeoutMillis() {
return idleTimeoutMillis != null && idleTimeoutMillis > 0
? idleTimeoutMillis
- : HttpClientUtil.DEFAULT_SO_TIMEOUT;
+ : SolrHttpConstants.DEFAULT_SO_TIMEOUT;
}
/** The max time a connection can take to connect to destinations. */
@@ -143,7 +143,7 @@ public abstract class HttpSolrClientBuilderBase<
public long getConnectionTimeoutMillis() {
return connectionTimeoutMillis != null && connectionTimeoutMillis > 0
? connectionTimeoutMillis
- : HttpClientUtil.DEFAULT_CONNECT_TIMEOUT;
+ : SolrHttpConstants.DEFAULT_CONNECT_TIMEOUT;
}
/** Set a timeout for requests to receive a response. */
diff --git
a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/PreemptiveBasicAuthClientBuilderFactory.java
b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/PreemptiveBasicAuthClientBuilderFactory.java
index 0f7e58d3b7c..e0680be0874 100644
---
a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/PreemptiveBasicAuthClientBuilderFactory.java
+++
b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/PreemptiveBasicAuthClientBuilderFactory.java
@@ -71,9 +71,9 @@ public class PreemptiveBasicAuthClientBuilderFactory
implements HttpClientBuilde
@Override
public void setup(Http2SolrClient client) {
final String basicAuthUser =
-
CREDENTIAL_RESOLVER.defaultParams.get(HttpClientUtil.PROP_BASIC_AUTH_USER);
+
CREDENTIAL_RESOLVER.defaultParams.get(SolrHttpConstants.PROP_BASIC_AUTH_USER);
final String basicAuthPass =
-
CREDENTIAL_RESOLVER.defaultParams.get(HttpClientUtil.PROP_BASIC_AUTH_PASS);
+
CREDENTIAL_RESOLVER.defaultParams.get(SolrHttpConstants.PROP_BASIC_AUTH_PASS);
this.setup(client, basicAuthUser, basicAuthPass);
}
@@ -120,9 +120,9 @@ public class PreemptiveBasicAuthClientBuilderFactory
implements HttpClientBuilde
defaultParams =
new MapSolrParams(
Map.of(
- HttpClientUtil.PROP_BASIC_AUTH_USER,
+ SolrHttpConstants.PROP_BASIC_AUTH_USER,
ss.get(0),
- HttpClientUtil.PROP_BASIC_AUTH_PASS,
+ SolrHttpConstants.PROP_BASIC_AUTH_PASS,
ss.get(1)));
} else if (configFile != null) {
Properties defaultProps = new Properties();
diff --git
a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrHttpConstants.java
b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrHttpConstants.java
new file mode 100644
index 00000000000..8c207364594
--- /dev/null
+++
b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrHttpConstants.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.client.solrj.impl;
+
+/** Constants for HTTP Solr interaction. */
+public interface SolrHttpConstants {
+ int DEFAULT_CONNECT_TIMEOUT = 60000;
+ int DEFAULT_SO_TIMEOUT = 600000;
+ int DEFAULT_MAXCONNECTIONSPERHOST = 100000;
+ int DEFAULT_MAXCONNECTIONS = 100000;
+
+ /**
+ * Socket timeout measured in ms, closes a socket if read takes longer than
x ms to complete.
+ * throws {@link java.net.SocketTimeoutException}: Read timed out exception
+ */
+ String PROP_SO_TIMEOUT = "socketTimeout";
+
+ /**
+ * connection timeout measures in ms, closes a socket if connection cannot
be established within x
+ * ms. with a {@link java.net.SocketTimeoutException}: Connection timed out
+ */
+ String PROP_CONNECTION_TIMEOUT = "connTimeout";
+
+ /** Maximum connections allowed per host */
+ String PROP_MAX_CONNECTIONS_PER_HOST = "maxConnectionsPerHost";
+
+ /** Maximum total connections allowed */
+ String PROP_MAX_CONNECTIONS = "maxConnections";
+
+ /**
+ * A Java system property to select the {@linkplain
HttpClientBuilderFactory} used for configuring
+ * HTTP based SolrClients.
+ */
+ String SYS_PROP_HTTP_CLIENT_BUILDER_FACTORY =
"solr.httpclient.builder.factory";
+
+ /**
+ * System property consulted to determine if HTTP based SolrClients will
require hostname
+ * validation of SSL Certificates. The default behavior is to enforce peer
name validation.
+ */
+ String SYS_PROP_CHECK_PEER_NAME = "solr.ssl.checkPeerName";
+
+ /** Basic auth username */
+ String PROP_BASIC_AUTH_USER = "httpBasicAuthUser";
+
+ /** Basic auth password */
+ String PROP_BASIC_AUTH_PASS = "httpBasicAuthPassword";
+}
diff --git a/solr/solrj/src/java/org/apache/solr/common/util/Utils.java
b/solr/solrj/src/java/org/apache/solr/common/util/Utils.java
index ee7823eb6d6..1e2f69da972 100644
--- a/solr/solrj/src/java/org/apache/solr/common/util/Utils.java
+++ b/solr/solrj/src/java/org/apache/solr/common/util/Utils.java
@@ -72,12 +72,6 @@ import java.util.function.Function;
import java.util.function.Predicate;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.methods.HttpRequestBase;
-import org.apache.http.util.EntityUtils;
import org.apache.solr.common.IteratorWriter;
import org.apache.solr.common.LinkedHashMapWriter;
import org.apache.solr.common.MapWriter;
@@ -643,27 +637,6 @@ public class Utils {
} else throw new RuntimeException("must be a NamedList or Map");
}
- /**
- * If the passed entity has content, make sure it is fully read and closed.
- *
- * @param entity to consume or null
- */
- public static void consumeFully(HttpEntity entity) {
- if (entity != null) {
- try {
- // make sure the stream is full read
- readFully(entity.getContent());
- } catch (UnsupportedOperationException e) {
- // nothing to do then
- } catch (IOException e) {
- // quiet
- } finally {
- // close the stream
- EntityUtils.consumeQuietly(entity);
- }
- }
- }
-
/**
* Make sure the InputStream is fully read.
*
@@ -838,49 +811,6 @@ public class Utils {
};
}
- public static <T> T executeGET(HttpClient client, String url,
InputStreamConsumer<T> consumer)
- throws SolrException {
- return executeHttpMethod(client, url, consumer, new HttpGet(url));
- }
-
- public static <T> T executeHttpMethod(
- HttpClient client, String url, InputStreamConsumer<T> consumer,
HttpRequestBase httpMethod) {
- T result = null;
- HttpResponse rsp = null;
- try {
- rsp = client.execute(httpMethod);
- } catch (IOException e) {
- log.error("Error in request to url : {}", url, e);
- throw new SolrException(SolrException.ErrorCode.UNKNOWN, "Error sending
request");
- }
- int statusCode = rsp.getStatusLine().getStatusCode();
- if (statusCode != 200) {
- try {
- log.error(
- "Failed a request to: {}, status: {}, body: {}",
- url,
- rsp.getStatusLine(),
- EntityUtils.toString(rsp.getEntity(), StandardCharsets.UTF_8)); //
nowarn
- } catch (IOException e) {
- log.error("could not print error", e);
- }
- throw new
SolrException(SolrException.ErrorCode.getErrorCode(statusCode), "Unknown
error");
- }
- HttpEntity entity = rsp.getEntity();
- try {
- InputStream is = entity.getContent();
- if (consumer != null) {
-
- result = consumer.accept(is);
- }
- } catch (IOException e) {
- throw new SolrException(SolrException.ErrorCode.UNKNOWN, e);
- } finally {
- Utils.consumeFully(entity);
- }
- return result;
- }
-
/**
* Convert the input object to a map, writing only those fields annotated
with a {@link
* JsonProperty} annotation
diff --git
a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrSchemalessExampleTest.java
b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrSchemalessExampleTest.java
index 2978a7d947f..26ed8939696 100644
---
a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrSchemalessExampleTest.java
+++
b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrSchemalessExampleTest.java
@@ -36,7 +36,6 @@ import org.apache.solr.client.solrj.impl.JavaBinRequestWriter;
import org.apache.solr.client.solrj.impl.JavaBinResponseParser;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
-import org.apache.solr.common.util.Utils;
import org.apache.solr.util.ExternalPaths;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -91,7 +90,7 @@ public class SolrSchemalessExampleTest extends
SolrExampleTestsBase {
new InputStreamEntity(new
ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8)), -1));
HttpResponse response =
httpClient.execute(post,
HttpClientUtil.createNewHttpClientRequestContext());
- Utils.consumeFully(response.getEntity());
+ HttpClientUtil.consumeFully(response.getEntity());
assertEquals(200, response.getStatusLine().getStatusCode());
client.commit();
assertNumFound("*:*", 2);
diff --git
a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/Http2SolrClientTest.java
b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/Http2SolrClientTest.java
index 59ca9e173c8..c66bd436985 100644
---
a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/Http2SolrClientTest.java
+++
b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/Http2SolrClientTest.java
@@ -489,7 +489,7 @@ public class Http2SolrClientTest extends
HttpSolrClientTestBase {
System.setProperty(
PreemptiveBasicAuthClientBuilderFactory.SYS_PROP_BASIC_AUTH_CREDENTIALS,
"foo:bar");
System.setProperty(
- HttpClientUtil.SYS_PROP_HTTP_CLIENT_BUILDER_FACTORY,
+ SolrHttpConstants.SYS_PROP_HTTP_CLIENT_BUILDER_FACTORY,
PreemptiveBasicAuthClientBuilderFactory.class.getName());
// Hack to ensure we get a new set of parameters for this test
PreemptiveBasicAuthClientBuilderFactory.setDefaultSolrParams(
@@ -517,7 +517,7 @@ public class Http2SolrClientTest extends
HttpSolrClientTestBase {
authorizationHeader);
} finally {
System.clearProperty(PreemptiveBasicAuthClientBuilderFactory.SYS_PROP_BASIC_AUTH_CREDENTIALS);
-
System.clearProperty(HttpClientUtil.SYS_PROP_HTTP_CLIENT_BUILDER_FACTORY);
+
System.clearProperty(SolrHttpConstants.SYS_PROP_HTTP_CLIENT_BUILDER_FACTORY);
PreemptiveBasicAuthClientBuilderFactory.setDefaultSolrParams(SolrParams.of());
}
}
@@ -594,7 +594,7 @@ public class Http2SolrClientTest extends
HttpSolrClientTestBase {
@Test
public void testBadHttpFactory() {
- System.setProperty(HttpClientUtil.SYS_PROP_HTTP_CLIENT_BUILDER_FACTORY,
"FakeClassName");
+ System.setProperty(SolrHttpConstants.SYS_PROP_HTTP_CLIENT_BUILDER_FACTORY,
"FakeClassName");
try {
SolrClient client =
new Http2SolrClient.Builder(getBaseUrl() + DEBUG_SERVLET_PATH)
diff --git
a/solr/test-framework/src/java/org/apache/solr/cloud/SolrCloudAuthTestCase.java
b/solr/test-framework/src/java/org/apache/solr/cloud/SolrCloudAuthTestCase.java
index dab2b845a86..99085837700 100644
---
a/solr/test-framework/src/java/org/apache/solr/cloud/SolrCloudAuthTestCase.java
+++
b/solr/test-framework/src/java/org/apache/solr/cloud/SolrCloudAuthTestCase.java
@@ -41,6 +41,7 @@ import org.apache.http.client.methods.HttpGet;
import org.apache.http.message.AbstractHttpMessage;
import org.apache.http.message.BasicHeader;
import org.apache.http.util.EntityUtils;
+import org.apache.solr.client.solrj.impl.HttpClientUtil;
import org.apache.solr.common.util.StrUtils;
import org.apache.solr.common.util.Utils;
import org.apache.solr.embedded.JettySolrRunner;
@@ -303,7 +304,7 @@ public class SolrCloudAuthTestCase extends
SolrCloudTestCase {
} catch (Exception e) {
fail("Invalid json " + s);
}
- Utils.consumeFully(rsp.getEntity());
+ HttpClientUtil.consumeFully(rsp.getEntity());
Object actual = Utils.getObjectByPath(m, true, hierarchy);
if (expected instanceof Predicate predicate) {
if (predicate.test(actual)) {
diff --git
a/solr/test-framework/src/java/org/apache/solr/util/SSLTestConfig.java
b/solr/test-framework/src/java/org/apache/solr/util/SSLTestConfig.java
index ce3cf4c0315..6f58d3c39fc 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/SSLTestConfig.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/SSLTestConfig.java
@@ -37,8 +37,8 @@ import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
import org.apache.http.ssl.SSLContextBuilder;
import org.apache.http.ssl.SSLContexts;
import org.apache.solr.client.solrj.embedded.SSLConfig;
-import org.apache.solr.client.solrj.impl.HttpClientUtil;
import
org.apache.solr.client.solrj.impl.HttpClientUtil.SocketFactoryRegistryProvider;
+import org.apache.solr.client.solrj.impl.SolrHttpConstants;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.resource.ResourceFactory;
import org.eclipse.jetty.util.security.CertificateUtils;
@@ -99,7 +99,7 @@ public class SSLTestConfig {
* @param clientAuth - whether client authentication should be required.
* @param checkPeerName - whether the client should validate the 'peer name'
of the SSL
* Certificate (and which testing Cert should be used)
- * @see HttpClientUtil#SYS_PROP_CHECK_PEER_NAME
+ * @see SolrHttpConstants#SYS_PROP_CHECK_PEER_NAME
*/
@SuppressWarnings("removal")
public SSLTestConfig(boolean useSsl, boolean clientAuth, boolean
checkPeerName) {