Package org.apache.solr.client.solrj.impl

# 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 Summary

Nested Classes
Modifier and Type
Class
Description
`static class`
`HttpJdkSolrClient.Builder`
`protected static class`
`HttpJdkSolrClient.PreparedRequest`

## Nested classes/interfaces inherited from class org.apache.solr.client.solrj.SolrClient

`SolrClient.SolrClientFunction<C extends SolrClient,R>`

## Field Summary

Fields
Modifier and Type
Field
Description
`protected ExecutorService`
`executor`
`protected final Map<URI,Boolean>`
`headSucceededByBaseUri`
`protected HttpClient`
`httpClient`

### Fields inherited from class org.apache.solr.client.solrj.impl.HttpSolrClientBase

`basicAuthAuthorizationStr, DEFAULT_PATH, defaultParserMimeTypes, FALLBACK_CHARSET, parser, requestTimeoutMillis, requestWriter, serverBaseUrl, urlParamNames`

### Fields inherited from class org.apache.solr.client.solrj.SolrClient

`defaultCollection`

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`HttpJdkSolrClient(String serverBaseUrl, HttpJdkSolrClient.Builder builder)`

## Method Summary

Modifier and Type
Method
Description
`protected String`
`allProcessorSupportedContentTypesCommaDelimited(Collection<String> processorSupportedContentTypes)`
`HttpSolrClientBuilderBase<?,?>`
`builder()`
`void`
`close()`
`protected String`
`contentTypeToEncoding(String contentType)`
`protected LBSolrClient`
`createLBSolrClient()`
`protected boolean`
`isFollowRedirects()`
`protected boolean`
`maybeTryHeadRequest(String url)`
This is a workaround for the case where:
`protected HttpJdkSolrClient.PreparedRequest`
`prepareRequest(SolrRequest<?> solrRequest, String collection, String overrideBaseUrl)`
`protected boolean`
`processorAcceptsMimeType(Collection<String> processorSupportedContentTypes, String mimeType)`
`NamedList<Object>`
`request(SolrRequest<?> solrRequest, String collection)`
Execute a request against a Solr server for a given collection
`CompletableFuture<NamedList<Object>>`
`requestAsync(SolrRequest<?> solrRequest, String collection)`
Execute an asynchronous request against a Solr server for a given collection.
`NamedList<Object>`
`requestWithBaseUrl(String baseUrl, SolrRequest<?> solrRequest, String collection)`
Executes a SolrRequest using the provided URL to temporarily override any "base URL" currently used by this client
`protected void`
`updateDefaultMimeTypeForParser()`

### Methods inherited from class org.apache.solr.client.solrj.impl.HttpSolrClientBase

`basicAuthCredentialsToAuthorizationString, calculateQueryParams, getBaseURL, getParser, getRequestUrl, getRequestWriter, getUrlParamNames, initializeSolrParams, isMultipart, isV2ApiRequest, processErrorsAndResponse, requestAsync, responseParser, setParser, validateGetRequest, wantStream`

### Methods 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`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### httpClient

protected HttpClient httpClient

### executor

protected ExecutorService executor

### headSucceededByBaseUri

protected final Map<URI,Boolean> headSucceededByBaseUri

## Constructor Details

### HttpJdkSolrClient

protected HttpJdkSolrClient(String serverBaseUrl, HttpJdkSolrClient.Builder builder)

## Method Details

### requestAsync

public CompletableFuture<NamedList<Object>> requestAsync(SolrRequest<?> solrRequest, String collection)
Description copied from class: `HttpSolrClientBase`
Execute an asynchronous request against a Solr server for a given collection.

Specified by:
  `requestAsync` in class `HttpSolrClientBase`
Parameters:
  `solrRequest` - the request to execute
  `collection` - the collection to execute the request against
Returns:
  a `CompletableFuture` that tracks the progress of the async request. Supports cancelling requests via `CompletableFuture.cancel(boolean)`, adding callbacks/error handling using `CompletableFuture.whenComplete(BiConsumer)` and `CompletableFuture.exceptionally(Function)` methods, and other CompletableFuture functionality. Will complete exceptionally in case of either an `IOException` or `SolrServerException` during the request. Once completed, the CompletableFuture will contain a `NamedList` with the response from the server.

### requestWithBaseUrl

public NamedList<Object> requestWithBaseUrl(String baseUrl, SolrRequest<?> solrRequest, String collection) throws SolrServerException, IOException
Description copied from class: `HttpSolrClientBase`
Executes a SolrRequest using the provided URL to temporarily override any "base URL" currently used by this client

Specified by:
  `requestWithBaseUrl` in class `HttpSolrClientBase`
Parameters:
  `baseUrl` - a URL to a root Solr path (i.e. "/solr") that should be used for this request
  `solrRequest` - the SolrRequest to send
  `collection` - 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:
  `SolrServerException`
  `IOException`
See Also:
  - `SolrRequest.processWithBaseUrl(HttpSolrClientBase, String, String)`

### request

public NamedList<Object> request(SolrRequest<?> solrRequest, String collection) throws SolrServerException, IOException
Description copied from class: `SolrClient`
Execute a request against a Solr server for a given collection

Specified by:
  `request` in class `SolrClient`
Parameters:
  `solrRequest` - the request to execute
  `collection` - the collection to execute the request against
Returns:
  a `NamedList` containing 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.

### prepareRequest

protected HttpJdkSolrClient.PreparedRequest prepareRequest(SolrRequest<?> solrRequest, String collection, String overrideBaseUrl) throws SolrServerException, IOException

Throws:
  `SolrServerException`
  `IOException`

### maybeTryHeadRequest

protected 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

### contentTypeToEncoding

protected String contentTypeToEncoding(String contentType)

### close

public void close() throws IOException

Throws:
  `IOException`

### isFollowRedirects

protected boolean isFollowRedirects()

Specified by:
  `isFollowRedirects` in class `HttpSolrClientBase`

### processorAcceptsMimeType

protected boolean processorAcceptsMimeType(Collection<String> processorSupportedContentTypes, String mimeType)

Specified by:
  `processorAcceptsMimeType` in class `HttpSolrClientBase`

### updateDefaultMimeTypeForParser

protected void updateDefaultMimeTypeForParser()

Specified by:
  `updateDefaultMimeTypeForParser` in class `HttpSolrClientBase`

### allProcessorSupportedContentTypesCommaDelimited

protected String allProcessorSupportedContentTypesCommaDelimited(Collection<String> processorSupportedContentTypes)

Specified by:
  `allProcessorSupportedContentTypesCommaDelimited` in class `HttpSolrClientBase`

### builder

public HttpSolrClientBuilderBase<?,?> builder()

Specified by:
  `builder` in class `HttpSolrClientBase`

### createLBSolrClient

protected LBSolrClient createLBSolrClient()

Specified by:
  `createLBSolrClient` in class `HttpSolrClientBase`