Class HttpJdkSolrClient
- java.lang.Object
- 
- org.apache.solr.client.solrj.SolrClient
- 
- org.apache.solr.client.solrj.impl.HttpSolrClientBase
- 
- org.apache.solr.client.solrj.impl.HttpJdkSolrClient
 
 
 
- 
- All Implemented Interfaces:
- Closeable,- Serializable,- AutoCloseable
 
 public class HttpJdkSolrClient extends HttpSolrClientBase 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.- See Also:
- Serialized Form
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classHttpJdkSolrClient.Builderprotected static classHttpJdkSolrClient.HttpSolrClientCancellable
 - 
Field SummaryFields Modifier and Type Field Description protected ExecutorServiceexecutorprotected booleanheadRequestedprotected HttpClienthttpClient- 
Fields inherited from class org.apache.solr.client.solrj.impl.HttpSolrClientBasebasicAuthAuthorizationStr, DEFAULT_PATH, defaultParserMimeTypes, FALLBACK_CHARSET, parser, requestTimeoutMillis, requestWriter, serverBaseUrl, urlParamNames
 - 
Fields inherited from class org.apache.solr.client.solrj.SolrClientdefaultCollection
 
- 
 - 
Constructor SummaryConstructors Modifier Constructor Description protectedHttpJdkSolrClient(String serverBaseUrl, HttpJdkSolrClient.Builder builder)
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description protected StringallProcessorSupportedContentTypesCommaDelimited(Collection<String> processorSupportedContentTypes)CancellableasyncRequest(SolrRequest<?> solrRequest, String collection, AsyncListener<NamedList<Object>> asyncListener)voidclose()protected StringcontentTypeToEncoding(String contentType)protected booleanisFollowRedirects()protected booleanmaybeTryHeadRequest(String url)This is a workaround for the case where:protected booleanprocessorAcceptsMimeType(Collection<String> processorSupportedContentTypes, String mimeType)NamedList<Object>request(SolrRequest<?> solrRequest, String collection)Execute a request against a Solr server for a given collectionCompletableFuture<NamedList<Object>>requestAsync(SolrRequest<?> solrRequest, String collection)Execute an asynchronous request against a Solr server for a given collection.protected voidupdateDefaultMimeTypeForParser()- 
Methods inherited from class org.apache.solr.client.solrj.impl.HttpSolrClientBasebasicAuthCredentialsToAuthorizationString, calculateQueryParams, getBaseURL, getParser, getRequestUrl, getUrlParamNames, initalizeSolrParams, initializeSolrParams, isMultipart, isV2ApiRequest, processErrorsAndResponse, requestAsync, responseParser, setParser, validateGetRequest, wantStream
 - 
Methods inherited from class org.apache.solr.client.solrj.SolrClientadd, 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, getBinder, 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 Detail- 
httpClientprotected HttpClient httpClient 
 - 
executorprotected ExecutorService executor 
 - 
headRequestedprotected volatile boolean headRequested 
 
- 
 - 
Constructor Detail- 
HttpJdkSolrClientprotected HttpJdkSolrClient(String serverBaseUrl, HttpJdkSolrClient.Builder builder) 
 
- 
 - 
Method Detail- 
asyncRequestpublic Cancellable asyncRequest(SolrRequest<?> solrRequest, String collection, AsyncListener<NamedList<Object>> asyncListener) - Specified by:
- asyncRequestin class- HttpSolrClientBase
- Parameters:
- solrRequest- the request to perform
- collection- if null the default collection is used
- asyncListener- callers should provide an implementation to handle events: start, success, exception
- Returns:
- Cancellable allowing the caller to attempt cancellation
 
 - 
requestAsyncpublic CompletableFuture<NamedList<Object>> requestAsync(SolrRequest<?> solrRequest, String collection) Description copied from class:HttpSolrClientBaseExecute an asynchronous request against a Solr server for a given collection.- Specified by:
- requestAsyncin class- HttpSolrClientBase
- Parameters:
- solrRequest- the request to execute
- collection- 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.
 
 - 
requestpublic 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 class- SolrClient
- Parameters:
- solrRequest- the request to execute
- collection- the collection to execute the request against
- Returns:
- a NamedListcontaining the response from the server
- Throws:
- SolrServerException- if there is an error on the server
- IOException- If there is a low-level I/O error.
 
 - 
maybeTryHeadRequestprotected boolean maybeTryHeadRequest(String url) 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
 
 - 
closepublic void close() throws IOException- Throws:
- IOException
 
 - 
isFollowRedirectsprotected boolean isFollowRedirects() - Specified by:
- isFollowRedirectsin class- HttpSolrClientBase
 
 - 
processorAcceptsMimeTypeprotected boolean processorAcceptsMimeType(Collection<String> processorSupportedContentTypes, String mimeType) - Specified by:
- processorAcceptsMimeTypein class- HttpSolrClientBase
 
 - 
updateDefaultMimeTypeForParserprotected void updateDefaultMimeTypeForParser() - Specified by:
- updateDefaultMimeTypeForParserin class- HttpSolrClientBase
 
 - 
allProcessorSupportedContentTypesCommaDelimitedprotected String allProcessorSupportedContentTypesCommaDelimited(Collection<String> processorSupportedContentTypes) - Specified by:
- allProcessorSupportedContentTypesCommaDelimitedin class- HttpSolrClientBase
 
 
- 
 
-