Class HttpSolrClient
- java.lang.Object
-
- org.apache.solr.client.solrj.SolrClient
-
- org.apache.solr.client.solrj.impl.BaseHttpSolrClient
-
- org.apache.solr.client.solrj.impl.HttpSolrClient
-
- All Implemented Interfaces:
Closeable,Serializable,AutoCloseable
- Direct Known Subclasses:
DelegationTokenHttpSolrClient
public class HttpSolrClient extends BaseHttpSolrClient
A SolrClient implementation that talks directly to a Solr server via HTTP- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classHttpSolrClient.BuilderConstructsHttpSolrClientinstances from provided configuration.static classHttpSolrClient.HttpUriRequestResponsestatic classHttpSolrClient.RemoteExecutionExceptionDeprecated.since 8.0, catchBaseHttpSolrClient.RemoteExecutionExceptioninsteadstatic classHttpSolrClient.RemoteSolrExceptionDeprecated.since 8.0, catchBaseHttpSolrClient.RemoteSolrExceptioninstead
-
Field Summary
Fields Modifier and Type Field Description static StringAGENTUser-Agent String.protected StringbaseUrlThe URL of the Solr server.protected ModifiableSolrParamsinvariantParamsDefault value: null / empty.protected ResponseParserparserDefault response parser is BinaryResponseParserprotected RequestWriterrequestWriterThe RequestWriter used to write all requests to Solr
-
Constructor Summary
Constructors Modifier Constructor Description protectedHttpSolrClient(String baseURL, org.apache.http.client.HttpClient client, ResponseParser parser, boolean allowCompression)Deprecated.useHttpSolrClient(Builder)instead, as it is a more extension/subclassing-friendly alternativeprotectedHttpSolrClient(String baseURL, org.apache.http.client.HttpClient client, ResponseParser parser, boolean allowCompression, ModifiableSolrParams invariantParams)Deprecated.useHttpSolrClient(Builder)instead, as it is a more extension/subclassing-friendly alternativeprotectedHttpSolrClient(HttpSolrClient.Builder builder)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected ModifiableSolrParamscalculateQueryParams(Set<String> queryParamNames, ModifiableSolrParams wparams)voidclose()Close theHttpClientConnectionManagerfrom the internal client.protected org.apache.http.client.methods.HttpRequestBasecreateMethod(SolrRequest request, String collection)protected NamedList<Object>executeMethod(org.apache.http.client.methods.HttpRequestBase method, Principal userPrincipal, ResponseParser processor, boolean isV2Api)StringgetBaseURL()org.apache.http.client.HttpClientgetHttpClient()Return the HttpClient this instance uses.ModifiableSolrParamsgetInvariantParams()Retrieve the default list of parameters are added to every request regardless.ResponseParsergetParser()Set<String>getQueryParams()HttpSolrClient.HttpUriRequestResponsehttpUriRequest(SolrRequest request)HttpSolrClient.HttpUriRequestResponsehttpUriRequest(SolrRequest request, ResponseParser processor)booleanisUseMultiPartPost()NamedList<Object>request(SolrRequest request, String collection)Process the request.NamedList<Object>request(SolrRequest request, ResponseParser processor)NamedList<Object>request(SolrRequest request, ResponseParser processor, String collection)voidsetBaseURL(String baseURL)Change the base-url used when sending requests to Solr.voidsetConnectionTimeout(int timeout)Deprecated.since 7.0 UseHttpSolrClient.Buildermethods instead.voidsetFollowRedirects(boolean followRedirects)Configure whether the client should follow redirects or not.voidsetParser(ResponseParser processor)Note: This setter method is not thread-safe.voidsetQueryParams(Set<String> queryParams)Expert MethodvoidsetRequestWriter(RequestWriter requestWriter)voidsetSoTimeout(int timeout)Deprecated.voidsetUseMultiPartPost(boolean useMultiPartPost)Set the multipart connection properties-
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, getBinder, getById, getById, getById, getById, getById, getById, getById, getById, optimize, optimize, optimize, optimize, optimize, optimize, ping, query, query, query, query, queryAndStreamResponse, queryAndStreamResponse, queryAndStreamResponse, request, rollback, rollback
-
-
-
-
Field Detail
-
AGENT
public static final String AGENT
User-Agent String.
-
baseUrl
protected volatile String baseUrl
The URL of the Solr server.
-
invariantParams
protected ModifiableSolrParams invariantParams
Default value: null / empty.Parameters that are added to every request regardless. This may be a place to add something like an authentication token.
-
parser
protected volatile ResponseParser parser
Default response parser is BinaryResponseParserThis parser represents the default Response Parser chosen to parse the response if the parser were not specified as part of the request.
- See Also:
BinaryResponseParser
-
requestWriter
protected volatile RequestWriter requestWriter
The RequestWriter used to write all requests to Solr- See Also:
RequestWriter
-
-
Constructor Detail
-
HttpSolrClient
@Deprecated protected HttpSolrClient(String baseURL, org.apache.http.client.HttpClient client, ResponseParser parser, boolean allowCompression)
Deprecated.useHttpSolrClient(Builder)instead, as it is a more extension/subclassing-friendly alternative
-
HttpSolrClient
@Deprecated protected HttpSolrClient(String baseURL, org.apache.http.client.HttpClient client, ResponseParser parser, boolean allowCompression, ModifiableSolrParams invariantParams)
Deprecated.useHttpSolrClient(Builder)instead, as it is a more extension/subclassing-friendly alternativeThe constructor.- Parameters:
baseURL- The base url to communicate with the Solr serverclient- Http client instance to use for communicationparser- Response parser instance to use to decode response from Solr serverallowCompression- Should compression be allowed ?invariantParams- The parameters which should be included with every request.
-
HttpSolrClient
protected HttpSolrClient(HttpSolrClient.Builder builder)
-
-
Method Detail
-
setQueryParams
public void setQueryParams(Set<String> queryParams)
Expert Method- Parameters:
queryParams- set of param keys to only send via the query string Note that the param will be sent as a query string if the key is part of this Set or the SolrRequest's query params.- See Also:
SolrRequest.getQueryParams()
-
request
public NamedList<Object> request(SolrRequest request, String collection) throws SolrServerException, IOException
Process the request. IfSolrRequest.getResponseParser()is null, then usegetParser()- Specified by:
requestin classSolrClient- Parameters:
request- TheSolrRequestto processcollection- the collection to execute the request against- Returns:
- The
NamedListresult - Throws:
IOException- If there is a low-level I/O error.SolrServerException- if there is an error on the server- See Also:
request(org.apache.solr.client.solrj.SolrRequest, org.apache.solr.client.solrj.ResponseParser)
-
request
public NamedList<Object> request(SolrRequest request, ResponseParser processor) throws SolrServerException, IOException
- Throws:
SolrServerExceptionIOException
-
request
public NamedList<Object> request(SolrRequest request, ResponseParser processor, String collection) throws SolrServerException, IOException
- Throws:
SolrServerExceptionIOException
-
httpUriRequest
public HttpSolrClient.HttpUriRequestResponse httpUriRequest(SolrRequest request) throws SolrServerException, IOException
- Throws:
SolrServerExceptionIOException- WARNING: This API is experimental and might change in incompatible ways in the next release.
-
httpUriRequest
public HttpSolrClient.HttpUriRequestResponse httpUriRequest(SolrRequest request, ResponseParser processor) throws SolrServerException, IOException
- Throws:
SolrServerExceptionIOException- WARNING: This API is experimental and might change in incompatible ways in the next release.
-
calculateQueryParams
protected ModifiableSolrParams calculateQueryParams(Set<String> queryParamNames, ModifiableSolrParams wparams)
-
createMethod
protected org.apache.http.client.methods.HttpRequestBase createMethod(SolrRequest request, String collection) throws IOException, SolrServerException
- Throws:
IOExceptionSolrServerException
-
executeMethod
protected NamedList<Object> executeMethod(org.apache.http.client.methods.HttpRequestBase method, Principal userPrincipal, ResponseParser processor, boolean isV2Api) throws SolrServerException
- Throws:
SolrServerException
-
getInvariantParams
public ModifiableSolrParams getInvariantParams()
Retrieve the default list of parameters are added to every request regardless.- See Also:
invariantParams
-
getBaseURL
public String getBaseURL()
-
setBaseURL
public void setBaseURL(String baseURL)
Change the base-url used when sending requests to Solr. Two different paths can be specified as a part of this URL: 1) A path pointing directly at a particular corehttpSolrClient.setBaseURL("http://my-solr-server:8983/solr/core1"); QueryResponse resp = httpSolrClient.query(new SolrQuery("*:*"));Note that when a core is provided in the base URL, queries and other requests can be made without mentioning the core explicitly. However, the client can only send requests to that core. 2) The path of the root Solr path ("/solr")httpSolrClient.setBaseURL("http://my-solr-server:8983/solr"); QueryResponse resp = httpSolrClient.query("core1", new SolrQuery("*:*"));In this case the client is more flexible and can be used to send requests to any cores. The cost of this is that the core must be specified on each request.
-
getParser
public ResponseParser getParser()
-
setParser
public void setParser(ResponseParser processor)
Note: This setter method is not thread-safe.- Parameters:
processor- Default Response Parser chosen to parse the response if the parser were not specified as part of the request.- See Also:
SolrRequest.getResponseParser()
-
getHttpClient
public org.apache.http.client.HttpClient getHttpClient()
Return the HttpClient this instance uses.
-
setConnectionTimeout
@Deprecated public void setConnectionTimeout(int timeout)
Deprecated.since 7.0 UseHttpSolrClient.Buildermethods instead.HttpConnectionParams.setConnectionTimeout- Parameters:
timeout- Timeout in milliseconds
-
setSoTimeout
@Deprecated public void setSoTimeout(int timeout)
Deprecated.Set SoTimeout (read timeout). This is desirable for queries, but probably not for indexing.- Parameters:
timeout- Timeout in milliseconds s * @deprecated since 7.0 UseHttpSolrClient.Buildermethods instead.
-
setFollowRedirects
public void setFollowRedirects(boolean followRedirects)
Configure whether the client should follow redirects or not.This defaults to false under the assumption that if you are following a redirect to get to a Solr installation, something is misconfigured somewhere.
-
setRequestWriter
public void setRequestWriter(RequestWriter requestWriter)
-
close
public void close() throws IOExceptionClose theHttpClientConnectionManagerfrom the internal client.- Throws:
IOException
-
isUseMultiPartPost
public boolean isUseMultiPartPost()
-
setUseMultiPartPost
public void setUseMultiPartPost(boolean useMultiPartPost)
Set the multipart connection properties
-
-