You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by "Johnson, Jaya" <Ja...@moodys.com> on 2017/10/16 19:45:55 UTC
JAr errors with SoLr 6.6.1 and http client and core
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)
Current Frame:
bci: @57
flags: { }
locals: { 'org/apache/solr/common/params/SolrParams', 'org/apache/solr/common/params/ModifiableSolrParams', 'org/apache/http/impl/client/SystemDefaultHttpClient' }
stack: { 'org/apache/http/impl/client/SystemDefaultHttpClient' }
Bytecode:
0x0000000: bb00 0959 2ab7 000a 4cb2 000b b900 0c01
0x0000010: 0099 001e b200 0bbb 000d 59b7 000e 120f
0x0000020: b600 102b b600 11b6 0012 b900 1302 00b8
0x0000030: 0014 4d2c 2bb8 0015 2cb0
Stackmap Table:
append_frame(@47,Object[#172])
at org.apache.solr.client.solrj.impl.HttpSolrClient.executeMethod(HttpSolrClient.java:514)
at org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:279)
at org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:268)
at org.apache.solr.client.solrj.SolrRequest.process(SolrRequest.java:160)
at org.apache.solr.client.solrj.SolrClient.deleteByQuery(SolrClient.java:895)
at org.apache.solr.client.solrj.SolrClient.deleteByQuery(SolrClient.java:858)
at org.apache.solr.client.solrj.SolrClient.deleteByQuery(SolrClient.java:873)
at com.moodys.poc.tika.test.PocApacheTikaSecFilings.initSolrServer(PocApacheTikaSecFilings.java:35)
at com.moodys.poc.tika.test.PocApacheTikaSecFilings.main(PocApacheTikaSecFilings.java:41)
-----------------------------------------
Moody's monitors email communications through its networks for regulatory compliance purposes and to protect its customers, employees and business and where allowed to do so by applicable law. The information contained in this e-mail message, and any attachment thereto, is confidential and may not be disclosed without our express permission. If you are not the intended recipient or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that you have received this message in error and that any review, dissemination, distribution or copying of this message, or any attachment thereto, in whole or in part, is strictly prohibited. If you have received this message in error, please immediately notify us by telephone, fax or e-mail and delete the message and all of its attachments. Every effort is made to keep our network free from viruses. You should, however, review this e-mail message, as well as any attachment thereto, for viruses. We take no responsibility and have no liability for any computer virus which may be transferred via this e-mail message.
-----------------------------------------
Re: JAr errors with SoLr 6.6.1 and http client and core
Posted by Shawn Heisey <ap...@elyograg.org>.
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