Skip to content

Commit d794181

Browse files
authored
SOLR-17994: SolrClientCustomizer (#3876)
* Rename HttpClientBuilderFactory to SolrClientCustomizer, generalizing it. * Rename property solr.httpclient.builder.factory to solr.solrj.http.jetty.customizer * Rename PreemptiveBasicAuthClientBuilderFactory to PreemptiveBasicAuthClientCustomizer
1 parent fbec447 commit d794181

File tree

15 files changed

+92
-85
lines changed

15 files changed

+92
-85
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# See https://github.com/apache/solr/blob/main/dev-docs/changelog.adoc
2+
title: Rename HttpClientBuilderFactory to SolrClientCustomizer, and property solr.httpclient.builder.factory to solr.solrj.http.jetty.customizer
3+
type: other # added, changed, fixed, deprecated, removed, dependency_update, security, other
4+
authors:
5+
- name: David Smiley
6+
links:
7+
- name: SOLR-17994
8+
url: https://issues.apache.org/jira/browse/SOLR-17994

solr/bin/solr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ fi
342342
if [ -n "${SOLR_AUTH_TYPE:-}" ]; then
343343
case "$(echo "$SOLR_AUTH_TYPE" | awk '{print tolower($0)}')" in
344344
basic)
345-
SOLR_AUTHENTICATION_CLIENT_BUILDER="org.apache.solr.client.solrj.jetty.PreemptiveBasicAuthClientBuilderFactory"
345+
SOLR_AUTHENTICATION_CLIENT_BUILDER="org.apache.solr.client.solrj.jetty.PreemptiveBasicAuthClientCustomizer"
346346
;;
347347
*)
348348
echo "ERROR: Value specified for SOLR_AUTH_TYPE environment variable is invalid."
@@ -355,7 +355,7 @@ if [ -n "${SOLR_AUTHENTICATION_CLIENT_CONFIGURER:-}" ]; then
355355
echo " Please start using SOLR_AUTH_TYPE instead"
356356
fi
357357
if [ -n "${SOLR_AUTHENTICATION_CLIENT_BUILDER:-}" ]; then
358-
AUTHC_CLIENT_BUILDER_ARG="-Dsolr.httpclient.builder.factory=$SOLR_AUTHENTICATION_CLIENT_BUILDER"
358+
AUTHC_CLIENT_BUILDER_ARG="-Dsolr.solrj.http.jetty.customizer=$SOLR_AUTHENTICATION_CLIENT_BUILDER"
359359
AUTHC_OPTS="${AUTHC_CLIENT_BUILDER_ARG:-}"
360360
fi
361361
# This looks strange, but it is to avoid extra spaces when we have only one of the values set

solr/bin/solr.cmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ IF DEFINED SOLR_AUTH_TYPE (
227227

228228
IF DEFINED SOLR_AUTH_TYPE (
229229
IF /I "%SOLR_AUTH_TYPE%" == "basic" (
230-
set SOLR_AUTHENTICATION_CLIENT_BUILDER="org.apache.solr.client.solrj.jetty.PreemptiveBasicAuthClientBuilderFactory"
230+
set SOLR_AUTHENTICATION_CLIENT_BUILDER="org.apache.solr.client.solrj.jetty.PreemptiveBasicAuthClientCustomizer"
231231
) ELSE (
232232
echo ERROR: Value specified for SOLR_AUTH_TYPE configuration variable is invalid.
233233
goto err
@@ -239,7 +239,7 @@ IF DEFINED SOLR_AUTHENTICATION_CLIENT_CONFIGURER (
239239
echo Please start using SOLR_AUTH_TYPE instead
240240
)
241241
IF DEFINED SOLR_AUTHENTICATION_CLIENT_BUILDER (
242-
set AUTHC_CLIENT_BUILDER_ARG="-Dsolr.httpclient.builder.factory=%SOLR_AUTHENTICATION_CLIENT_BUILDER%"
242+
set AUTHC_CLIENT_BUILDER_ARG="-Dsolr.solrj.http.jetty.customizer=%SOLR_AUTHENTICATION_CLIENT_BUILDER%"
243243
)
244244
set "AUTHC_OPTS=%AUTHC_CLIENT_BUILDER_ARG% %SOLR_AUTHENTICATION_OPTS%"
245245

solr/bin/solr.in.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ REM set SOLR_SSL_CLIENT_TRUST_STORE_TYPE=
173173

174174
REM Settings for authentication
175175
REM Please configure only one of SOLR_AUTHENTICATION_CLIENT_BUILDER or SOLR_AUTH_TYPE parameters
176-
REM set SOLR_AUTHENTICATION_CLIENT_BUILDER=org.apache.solr.client.solrj.jetty.PreemptiveBasicAuthClientBuilderFactory
176+
REM set SOLR_AUTHENTICATION_CLIENT_BUILDER=org.apache.solr.client.solrj.jetty.PreemptiveBasicAuthClientCustomizer
177177
REM set SOLR_AUTH_TYPE=basic
178178
REM set SOLR_AUTHENTICATION_OPTS=-Dsolr.security.auth.basicauth.credentials=solr:SolrRocks
179179

solr/core/src/test/org/apache/solr/cloud/RecoveryZkTestWithAuth.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
import org.apache.solr.client.solrj.SolrServerException;
2828
import org.apache.solr.client.solrj.apache.CloudLegacySolrClient;
2929
import org.apache.solr.client.solrj.apache.HttpSolrClient;
30-
import org.apache.solr.client.solrj.impl.SolrHttpConstants;
31-
import org.apache.solr.client.solrj.jetty.PreemptiveBasicAuthClientBuilderFactory;
30+
import org.apache.solr.client.solrj.jetty.HttpJettySolrClient;
31+
import org.apache.solr.client.solrj.jetty.PreemptiveBasicAuthClientCustomizer;
3232
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
3333
import org.apache.solr.client.solrj.request.QueryRequest;
3434
import org.apache.solr.client.solrj.request.SolrQuery;
@@ -49,8 +49,8 @@ public static void setupCluster() throws Exception {
4949
// for context)
5050
if (rarely()) {
5151
System.setProperty(
52-
SolrHttpConstants.SYS_PROP_HTTP_CLIENT_BUILDER_FACTORY,
53-
PreemptiveBasicAuthClientBuilderFactory.class.getName());
52+
HttpJettySolrClient.CLIENT_CUSTOMIZER_SYSPROP,
53+
PreemptiveBasicAuthClientCustomizer.class.getName());
5454
System.setProperty("solr.security.auth.basicauth.credentials", SecurityJson.USER_PASS);
5555
}
5656

solr/solr-ref-guide/modules/configuration-guide/pages/solr-properties.adoc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,16 @@ NOTE: Properties marked with "!" indicate inverted meaning between pre Solr 10 a
102102

103103
|solr.security.allow.urls|solr.allowUrls||A comma seperated list of urls for reading from.
104104

105-
|solr.security.allow.urls.enabled|!solr.disable.allow.urls|false|If using an allow list of accessible urls is enabled.
105+
|solr.security.allow.urls.enabled|!solr.disable.allow.urls|false|If using an allow list of accessible urls is enabled.
106106

107107
|solr.security.auth.plugin|authenticationPlugin||Specifies the authentication plugin to use.
108108

109109
|solr.solrj.cloud.max.stale.retries|cloudSolrClientMaxStaleRetries|5|Sets the maximum number of retries for stale connection attempts in SolrJ cloud client.
110110

111111
|solr.solrj.http.cookies.enabled|!solr.http.disableCookies| false |If Http2SolrClient should support cookies.
112112

113+
|solr.solrj.http.jetty.customizer|solr.httpclient.builder.factory||A class loaded to customize HttpJettySolrClient upon creation.
114+
113115
|solr.streamingexpressions.facet.tiered.enabled|solr.facet.stream.tiered|true|Controls whether tiered faceting is enabled for streaming expressions.
114116

115117
|solr.streamingexpressions.macros.enabled|StreamingExpressionMacros|false|Controls whether to expand URL parameters inside of the `expr` parameter.
@@ -163,8 +165,8 @@ System properties can be set in several ways:
163165
2. In `solr.in.sh` (Unix) or `solr.in.cmd` (Windows) using environment variables
164166
3. Through environment variables (with appropriate naming conventions)
165167

166-
Environment variables can also be used to set these properties.
167-
You may find this useful in environments such as Docker.
168+
Environment variables can also be used to set these properties.
169+
You may find this useful in environments such as Docker.
168170
Environment variables should be uppercase with dot notations equivalents, e.g. `SOLR_API_V2_ENABLED` for the property `solr.api.v2.enabled`.
169171

170172
== See Also

solr/solr-ref-guide/modules/deployment-guide/pages/basic-authentication-plugin.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,9 @@ QueryResponse rsp = req.process(client);
358358

359359
=== Global (JVM) Basic Auth Credentials
360360

361-
Alternatively, users can use SolrJ's `PreemptiveBasicAuthClientBuilderFactory` to add basic authentication credentials to _all_ requests automatically.
362-
To enable this feature, users should set the following system property `-Dsolr.httpclient.builder.factory=org.apache.solr.client.solrj.jetty.PreemptiveBasicAuthClientBuilderFactory`.
363-
`PreemptiveBasicAuthClientBuilderFactory` allows applications to provide credentials in two different ways:
361+
Alternatively, users can use SolrJ's `PreemptiveBasicAuthClientCustomizer` to add basic authentication credentials to _all_ requests automatically.
362+
To enable this feature, users should set the following system property `-Dsolr.solrj.http.jetty.customizer=org.apache.solr.client.solrj.jetty.PreemptiveBasicAuthClientCustomizer`.
363+
`PreemptiveBasicAuthClientCustomizer` allows applications to provide credentials in two different ways:
364364

365365
. The `solr.security.auth.basicauth.credentials` system property can be passed, containing the credentials directly (e.g., `-Dsolr.security.auth.basicauth.credentials=username:password`).
366366
This option is straightforward, but may expose the credentials in the command line, depending on how they're set.

solr/solr-ref-guide/modules/upgrade-notes/pages/major-changes-in-solr-10.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ The following classes were renamed with some refactorings: `Http2SolrClient` to
7878
`CloudHttp2SolrClient.Builder` has moved to `CloudSolrClient`; users should generally have no need to refer to `CloudHttp2SolrClient` or any class/member with "http2" in it.
7979
The builder will check if Jetty `HttpClient` is available and use that, otherwise fallback on a JDK based `HttpClient`.
8080
`CloudJettySolrClient` is new, proving an explicit option.
81+
The system property `solr.solrj.http.jetty.customizer` (formerly `solr.httpclient.builder.factory`) can configure a `HttpJettySolrClient`.
82+
The only built-in implementation is `org.apache.solr.client.solrj.jetty.PreemptiveBasicAuthClientCustomizer`, renamed from `PreemptiveBasicAuthClientCustomizer`.
8183

8284
* `SolrClient` implementations that rely on "base URL" strings now only accept "root" URL paths (i.e. URLs that end in "/solr").
8385
Users who previously relied on collection-specific URLs to avoid including the collection name with each request can instead achieve this by specifying a "default collection" using the `withDefaultCollection` method available on most `SolrClient` Builders.
@@ -90,7 +92,6 @@ Users who previously relied on collection-specific URLs to avoid including the c
9092
This makes it clear that they pertain specifically to “JavaBin” rather than binary in general.
9193

9294
* The deprecated SolrClient implementations based on Apache HttpClient are removed from Solrj, thus the related dependencies are no longer present.
93-
The system property `solr.httpclient.builder.factory` now only configures SolrClients using a Jetty based HttpClient.
9495

9596
* A number of classes moved to different packages to be better organized:
9697
ShardTerms, DelegatingClusterStateProvider, JavaBinRequestWriter, RoutedAliasTypes, SolrQuery, XMLRequestWriter, JacksonContentWriter, FastStreamingDocsCallback, InputStreamResponse, InputStreamResponseParser, JavaBinResponseParser, ResponseParser, StreamingJavaBinResponseParser, StreamingResponseCallback, XMLResponseParser, JacksonDataBindResponseParser, JsonMapResponseParser, SocketProxy

solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpClientBuilderFactory.java renamed to solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientCustomizer.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@
1616
*/
1717
package org.apache.solr.client.solrj.impl;
1818

19-
import java.io.Closeable;
20-
import org.apache.solr.client.solrj.jetty.HttpJettySolrClient;
19+
import org.apache.solr.client.solrj.SolrClient;
2120

2221
/**
23-
* A config hook for post-configuration of a {@linkplain HttpJettySolrClient} by its builder.
22+
* A config hook for post-configuration of a {@linkplain SolrClient} by its builder. It is not
23+
* supported by all builders.
2424
*
25-
* @see SolrHttpConstants#SYS_PROP_HTTP_CLIENT_BUILDER_FACTORY
25+
* @param <T> type of SolrClient this customizer targets
26+
* @see org.apache.solr.client.solrj.jetty.HttpJettySolrClient#CLIENT_CUSTOMIZER_SYSPROP
2627
* @lucene.experimental
2728
*/
28-
public interface HttpClientBuilderFactory extends Closeable {
29-
default void setup(HttpJettySolrClient client) {}
29+
public interface SolrClientCustomizer<T extends SolrClient> {
30+
31+
void setup(T client);
3032
}

solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrHttpConstants.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ public interface SolrHttpConstants {
4242
/** Maximum total connections allowed */
4343
String PROP_MAX_CONNECTIONS = "maxConnections";
4444

45-
/**
46-
* A Java system property to select the {@linkplain HttpClientBuilderFactory} used for configuring
47-
* HTTP based SolrClients.
48-
*/
49-
String SYS_PROP_HTTP_CLIENT_BUILDER_FACTORY = "solr.httpclient.builder.factory";
50-
5145
/**
5246
* System property consulted to determine if HTTP based SolrClients will require hostname
5347
* validation of SSL Certificates. The default behavior is to enforce peer name validation.

0 commit comments

Comments
 (0)