On 10/16/2017 1:45 PM, Johnson, Jaya wrote:
> Hi I have the following code.
> System.out.println("Initializing server");
> SystemDefaultHttpClient cl = new SystemDefaultHttpClient();
> client = new 
> HttpSolrClient("http://localhost:8983/solr/#/prosp_poc_collection",cl);
> System.out.println("Completed initializing the server");
> client.deleteByQuery( "*:*" );
>
> Version of solr 6.6.1 and http client is 4.5.3 and 4.4.8 for http core.
> I get the following exception please advise.
>
> Exception Details:
>   Location:
>     
> org/apache/solr/client/solrj/impl/HttpClientUtil.createClient(Lorg/apache/solr/common/params/SolrParams;)Lorg/apache/http/impl/client/CloseableHttpClient;
>  @57: areturn
>   Reason:
>     Type 'org/apache/http/impl/client/SystemDefaultHttpClient' (current 
> frame, stack[0]) is not assignable to 
> 'org/apache/http/impl/client/CloseableHttpClient' (from method signature)
There are two problems here.  The first problem, which is causing the
exception, is that you used SystemDefaultHttpClient when you initialized
the SolrJ client.  SolrJ has used CloseableHttpClient for quite a while
now.  Since you aren't customizing the HttpClient when you create it,
you don't need to even worry about that part in your code.  Just remove
the parameter entirely.  SolrJ will create the HttpClient internally. 
If you *do* decide in the future that you want to customize the
HttpClient, which is a good idea if the code is multi-threaded, then you
should use the Builder paradigm provided by the HttpClient project to
handle that.  The SystemDefaultHttpClient class was deprecated in
HttpClient version 4.3 and is gone in the 5.0 alpha releases.

The second problem will manifest itself after you fix the problem with
the HttpClient object.  In the HttpSolrClient constructor, you are using
a URL that isn't going to work.  The URL you've provided is from your
browser in the admin UI -- it has the "#" character in it.  Solr URLS
with "#" in them *only* work in an actual full-blown browser with
Javascript.  In the code examples below, I will indicate the correct URL
that you should be using.

You have two choices about how to fix the URL problem.  One is to
provide the correct base URL for the collection, the other is to NOT
provide a collection in the URL, and to give it the collection on every
request.  I prefer the second option, but there is nothing wrong with
the first.

//========
client = new
HttpSolrClient("http://localhost:8983/solr/prosp_poc_collection";);
client.deleteByQuery("*:*");
//========

or

//========
client = new HttpSolrClient("http://localhost:8983/solr";);
client.deleteByQuery("prosp_poc_collection", "*:*");
//========

Note that if your servers are running in cloud mode, you should use
CloudSolrClient, not HttpSolrClient.  The initialization of this class
uses the same ZooKeeper connection string used when starting Solr itself:

//========
client = new
CloudSolrClient("zk1.example.com:2181,zk2.example.com:2181,zk3.example.com:2181/chroot");
client.deleteByQuery("prosp_poc_collection", "*:*");
//========

Thanks,
Shawn

Reply via email to