org.apache.solr.client.solrj.impl

## Class HttpSolrClient

- java.lang.Object
- - org.apache.solr.client.solrj.SolrClient
  - - org.apache.solr.client.solrj.impl.HttpSolrClient

- All Implemented Interfaces:
    Closeable, Serializable, AutoCloseable
  Direct Known Subclasses:
    DelegationTokenHttpSolrClient

      public class HttpSolrClient
      extends SolrClient

  A SolrClient implementation that talks directly to a Solr server via HTTP There are two ways to use an HttpSolrClient: 1) Pass a URL to the constructor that points directly at a particular core

         SolrClient client = new HttpSolrClient("http://my-solr-server:8983/solr/core1");
         QueryResponse resp = client.query(new SolrQuery("*:*"));

  In this case, you can query the given core directly, but you cannot query any other cores or issue CoreAdmin requests with this client. 2) Pass the base URL of the node to the constructor

         SolrClient client = new HttpSolrClient("http://my-solr-server:8983/solr");
         QueryResponse resp = client.query("core1", new SolrQuery("*:*"));

  In this case, you must pass the name of the required core for all queries and updates, but you may use the same client for all cores, and for CoreAdmin requests.
  See Also:
    Serialized Form

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `HttpSolrClient.Builder` Constructs `HttpSolrClient` instances from provided configuration.
    `static class` | `HttpSolrClient.HttpUriRequestResponse`
    `static class` | `HttpSolrClient.RemoteSolrException` Subclass of SolrException that allows us to capture an arbitrary HTTP status code that may have been returned by the remote server or a proxy along the way.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `AGENT` User-Agent String.
    `protected String` | `baseUrl` The URL of the Solr server.
    `protected ModifiableSolrParams` | `invariantParams` Default value: null / empty.
    `protected ResponseParser` | `parser` Default response parser is BinaryResponseParser
    `protected RequestWriter` | `requestWriter` The RequestWriter used to write all requests to Solr

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `HttpSolrClient(String baseURL)` Deprecated. use `HttpSolrClient.Builder` instead.
    `HttpSolrClient(String baseURL, org.apache.http.client.HttpClient client)` Deprecated. use `HttpSolrClient.Builder` instead.
    `HttpSolrClient(String baseURL, org.apache.http.client.HttpClient client, ResponseParser parser)` Deprecated. use `HttpSolrClient.Builder` instead.
    `HttpSolrClient(String baseURL, org.apache.http.client.HttpClient client, ResponseParser parser, boolean allowCompression)` Deprecated. use `HttpSolrClient.Builder` instead. This will soon be a 'protected' method, and will only be available for use in implementing subclasses.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected ModifiableSolrParams` | `calculateQueryParams(Set<String> queryParamNames, ModifiableSolrParams wparams)`
    `void` | `close()` Close the `ClientConnectionManager` from the internal client.
    `protected org.apache.http.client.methods.HttpRequestBase` | `createMethod(SolrRequest request, String collection)`
    `protected NamedList<Object>` | `executeMethod(org.apache.http.client.methods.HttpRequestBase method, ResponseParser processor)`
    `String` | `getBaseURL()`
    `org.apache.http.client.HttpClient` | `getHttpClient()` Return the HttpClient this instance uses.
    `ModifiableSolrParams` | `getInvariantParams()` Retrieve the default list of parameters are added to every request regardless.
    `ResponseParser` | `getParser()`
    `Set<String>` | `getQueryParams()`
    `HttpSolrClient.HttpUriRequestResponse` | `httpUriRequest(SolrRequest request)`
    `HttpSolrClient.HttpUriRequestResponse` | `httpUriRequest(SolrRequest request, ResponseParser processor)`
    `boolean` | `isUseMultiPartPost()`
    `NamedList<Object>` | `request(SolrRequest request, ResponseParser processor)`
    `NamedList<Object>` | `request(SolrRequest request, ResponseParser processor, String collection)`
    `NamedList<Object>` | `request(SolrRequest request, String collection)` Process the request.
    `void` | `setAllowCompression(boolean allowCompression)` Allow server->client communication to be compressed.
    `void` | `setBaseURL(String baseURL)`
    `void` | `setConnectionTimeout(int timeout)` HttpConnectionParams.setConnectionTimeout
    `void` | `setDefaultMaxConnectionsPerHost(int max)` Set the maximum number of connections that can be open to a single host at any given time.
    `void` | `setFollowRedirects(boolean followRedirects)` Configure whether the client should follow redirects or not.
    `void` | `setMaxTotalConnections(int max)` Set the maximum number of connections that can be open at any given time.
    `void` | `setParser(ResponseParser processor)` Note: This setter method is not thread-safe.
    `void` | `setQueryParams(Set<String> queryParams)` Expert Method
    `void` | `setRequestWriter(RequestWriter requestWriter)`
    `void` | `setSoTimeout(int timeout)` Set SoTimeout (read timeout).
    `void` | `setUseMultiPartPost(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, request, rollback, rollback`

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

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

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

      This 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
          public HttpSolrClient(String baseURL)

      Deprecated. use `HttpSolrClient.Builder` instead.
      Parameters:
        `baseURL` - The URL of the Solr server. For example, " `http://localhost:8983/solr/`" if you are using the standard distribution Solr webapp on your local machine.

    - #### HttpSolrClient

          @Deprecated
          public HttpSolrClient(String baseURL,
                                            org.apache.http.client.HttpClient client)

      Deprecated. use `HttpSolrClient.Builder` instead.

    - #### HttpSolrClient

          @Deprecated
          public HttpSolrClient(String baseURL,
                                            org.apache.http.client.HttpClient client,
                                            ResponseParser parser)

      Deprecated. use `HttpSolrClient.Builder` instead.

    - #### HttpSolrClient

          @Deprecated
          public HttpSolrClient(String baseURL,
                                            org.apache.http.client.HttpClient client,
                                            ResponseParser parser,
                                            boolean allowCompression)

      Deprecated. use `HttpSolrClient.Builder` instead. This will soon be a 'protected' method, and will only be available for use in implementing subclasses.

  - ### Method Detail

    - #### getQueryParams

          public Set<String> getQueryParams()

    - #### 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. If `SolrRequest.getResponseParser()` is null, then use `getParser()`
      Specified by:
        `request` in class `SolrClient`
      Parameters:
        `request` - The `SolrRequest` to process
        `collection` - the collection to execute the request against
      Returns:
        The `NamedList` result
      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:
        `SolrServerException`
        `IOException`

    - #### request

          public NamedList<Object> request(SolrRequest request,
                                           ResponseParser processor,
                                           String collection)
                                    throws SolrServerException,
                                           IOException

      Throws:
        `SolrServerException`
        `IOException`

    - #### httpUriRequest

          public HttpSolrClient.HttpUriRequestResponse httpUriRequest(SolrRequest request)
                                                               throws SolrServerException,
                                                                      IOException

      Throws:
        `SolrServerException`
        `IOException`
      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:
        `SolrServerException`
        `IOException`
      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:
        `IOException`
        `SolrServerException`

    - #### executeMethod

          protected NamedList<Object> executeMethod(org.apache.http.client.methods.HttpRequestBase method,
                                                    ResponseParser processor)
                                             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)

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

          public void setConnectionTimeout(int timeout)

      HttpConnectionParams.setConnectionTimeout
      Parameters:
        `timeout` - Timeout in milliseconds

    - #### setSoTimeout

          public void setSoTimeout(int timeout)

      Set SoTimeout (read timeout). This is desirable for queries, but probably not for indexing.
      Parameters:
        `timeout` - Timeout in milliseconds

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

    - #### setAllowCompression

          public void setAllowCompression(boolean allowCompression)

      Allow server->client communication to be compressed. Currently gzip and deflate are supported. If the server supports compression the response will be compressed. This method is only allowed if the http client is of type DefatulHttpClient.

    - #### setRequestWriter

          public void setRequestWriter(RequestWriter requestWriter)

    - #### close

          public void close()
                     throws IOException

      Close the `ClientConnectionManager` from the internal client.
      Throws:
        `IOException`

    - #### setDefaultMaxConnectionsPerHost

          public void setDefaultMaxConnectionsPerHost(int max)

      Set the maximum number of connections that can be open to a single host at any given time. If http client was created outside the operation is not allowed.

    - #### setMaxTotalConnections

          public void setMaxTotalConnections(int max)

      Set the maximum number of connections that can be open at any given time. If http client was created outside the operation is not allowed.

    - #### isUseMultiPartPost

          public boolean isUseMultiPartPost()

    - #### setUseMultiPartPost

          public void setUseMultiPartPost(boolean useMultiPartPost)

      Set the multipart connection properties

Copyright © 2000-2016 Apache Software Foundation. All Rights Reserved.