Class HttpJdkSolrClient
java.lang.Object
org.apache.solr.client.solrj.SolrClient
org.apache.solr.client.solrj.impl.HttpSolrClient
org.apache.solr.client.solrj.impl.HttpJdkSolrClient
- All Implemented Interfaces:
Closeable,Serializable,AutoCloseable
A SolrClient implementation that communicates to a Solr server using the built-in Java 11+ Http
Client. This client is targeted for those users who wish to minimize application dependencies.
This client will connect to solr using Http/2 but can seamlessly downgrade to Http/1.1 when
connecting to Solr hosts running on older versions. Uses two
ThreadPoolExecutor, one for HttpClient (consumer) and one for
writing request bodies (producer). Both are unbounded cached thread pools (maximumPoolSize =
Integer.MAX_VALUE).- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classprotected static classNested classes/interfaces inherited from class org.apache.solr.client.solrj.impl.HttpSolrClient
HttpSolrClient.BuilderBase<B extends HttpSolrClient.BuilderBase<?,?>, C extends HttpSolrClient> Nested classes/interfaces inherited from class org.apache.solr.client.solrj.SolrClient
SolrClient.SolrClientFunction<C extends SolrClient,R> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ExecutorServiceDedicated executor handed to the JDK HttpClientprotected HttpClientprotected ExecutorServiceExecutor used to stream (produce) request bodies into the pipe consumed by the JDK HttpClient.Fields inherited from class org.apache.solr.client.solrj.impl.HttpSolrClient
baseUrl, basicAuthAuthorizationStr, DEFAULT_URL_PARAM_NAMES, FALLBACK_CHARSET, parser, requestTimeoutMillis, requestWriter, urlParamNamesFields inherited from class org.apache.solr.client.solrj.SolrClient
defaultCollection -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedHttpJdkSolrClient(String serverBaseUrl, HttpJdkSolrClient.Builder builder) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()protected StringcontentTypeToEncoding(String contentType) protected LBSolrClientprotected booleanprotected booleanThis is a workaround for the case where:protected HttpJdkSolrClient.PreparedRequestprepareRequest(String overrideBaseUrl, SolrRequest<?> solrRequest, String collection) request(SolrRequest<?> solrRequest, String collection) Execute a request against a Solr server for a given collectionrequestAsync(SolrRequest<?> solrRequest, String collection) Execute an asynchronous request against a Solr server for a given collection.protected CompletableFuture<HttpResponse<InputStream>> requestInputStreamAsync(String baseUrl, SolrRequest<?> solrRequest, String collection) requestWithBaseUrl(String baseUrl, SolrRequest<?> solrRequest, String collection) Executes a SolrRequest using the provided URL to temporarily override any "base URL" currently used by this clientprotected HttpSolrClient.BuilderBase<?, ?> Methods inherited from class org.apache.solr.client.solrj.impl.HttpSolrClient
basicAuthCredentialsToAuthorizationString, builder, calculateQueryParams, getBaseURL, getParser, getRequestUrl, getRequestWriter, getUrlParamNames, initializeSolrParams, isMultipart, isV2ApiRequest, processErrorsAndResponse, requestAsync, responseParser, setParser, validateGetRequest, wantStreamMethods inherited from class org.apache.solr.client.solrj.SolrClient
add, add, add, add, add, add, add, add, add, add, addBean, addBean, addBean, addBean, addBeans, addBeans, addBeans, addBeans, addBeans, addBeans, commit, commit, commit, commit, commit, commit, deleteById, deleteById, deleteById, deleteById, deleteById, deleteById, deleteById, deleteById, deleteByQuery, deleteByQuery, deleteByQuery, deleteByQuery, getById, getById, getById, getById, getById, getById, getById, getById, getContext, getDefaultCollection, optimize, optimize, optimize, optimize, optimize, optimize, ping, ping, query, query, query, query, queryAndStreamResponse, queryAndStreamResponse, queryAndStreamResponse, request, rollback, rollback
-
Field Details
-
httpClient
-
requestBodyExecutor
Executor used to stream (produce) request bodies into the pipe consumed by the JDK HttpClient. -
executor
Dedicated executor handed to the JDK HttpClient -
headSucceededByBaseUri
-
-
Constructor Details
-
HttpJdkSolrClient
-
-
Method Details
-
requestInputStreamAsync
protected CompletableFuture<HttpResponse<InputStream>> requestInputStreamAsync(String baseUrl, SolrRequest<?> solrRequest, String collection) -
requestAsync
public CompletableFuture<NamedList<Object>> requestAsync(SolrRequest<?> solrRequest, String collection) Description copied from class:HttpSolrClientExecute an asynchronous request against a Solr server for a given collection.- Specified by:
requestAsyncin classHttpSolrClient- Parameters:
solrRequest- the request to executecollection- the collection to execute the request against- Returns:
- a
CompletableFuturethat tracks the progress of the async request. Supports cancelling requests viaCompletableFuture.cancel(boolean), adding callbacks/error handling usingCompletableFuture.whenComplete(BiConsumer)andCompletableFuture.exceptionally(Function)methods, and other CompletableFuture functionality. Will complete exceptionally in case of either anIOExceptionorSolrServerExceptionduring the request. Once completed, the CompletableFuture will contain aNamedListwith the response from the server.
-
requestWithBaseUrl
public NamedList<Object> requestWithBaseUrl(String baseUrl, SolrRequest<?> solrRequest, String collection) throws SolrServerException, IOException Description copied from class:HttpSolrClientExecutes a SolrRequest using the provided URL to temporarily override any "base URL" currently used by this client- Specified by:
requestWithBaseUrlin classHttpSolrClient- Parameters:
baseUrl- a URL to a root Solr path (i.e. "/solr") that should be used for this requestsolrRequest- the SolrRequest to sendcollection- an optional collection or core name used to override the client's "default collection". May be 'null' for any requests that don't require a collection or wish to rely on the client's default- Throws:
SolrServerExceptionIOException- See Also:
-
request
public NamedList<Object> request(SolrRequest<?> solrRequest, String collection) throws SolrServerException, IOException Description copied from class:SolrClientExecute a request against a Solr server for a given collection- Specified by:
requestin classSolrClient- Parameters:
solrRequest- the request to executecollection- the collection to execute the request against- Returns:
- a
NamedListcontaining the response from the server - Throws:
SolrServerException- if there is an error on the serverIOException- If there is a low-level I/O error.
-
prepareRequest
protected HttpJdkSolrClient.PreparedRequest prepareRequest(String overrideBaseUrl, SolrRequest<?> solrRequest, String collection) throws SolrServerException, IOException - Throws:
SolrServerExceptionIOException
-
maybeTryHeadRequest
This is a workaround for the case where:(1) no SSL/TLS (2) using POST with stream and (3) using Http/2
The JDK Http Client will send an upgrade request over Http/1 along with request content in the same request. However, the Jetty Server underpinning Solr does not accept this.
We send a HEAD request first, then the client knows if Solr can accept Http/2, and no additional upgrade requests will be sent.
See https://bugs.openjdk.org/browse/JDK-8287589 See https://github.com/jetty/jetty.project/issues/9998#issuecomment-1614216870
We only try once, and if it fails, we downgrade to Http/1
- Parameters:
url- the url with no request parameters- Returns:
- true if success
-
contentTypeToEncoding
-
close
- Throws:
IOException
-
isFollowRedirects
protected boolean isFollowRedirects()- Specified by:
isFollowRedirectsin classHttpSolrClient
-
toBuilder
- Specified by:
toBuilderin classHttpSolrClient
-
createLBSolrClient
- Specified by:
createLBSolrClientin classHttpSolrClient
-