Reputation: 819
I am trying to use a basic Solr tutorial and I am getting an error I have neither seen before nor can find details about online.
My code is:
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.common.SolrInputDocument;
import java.io.IOException;
public class SolrjPopulator {
public static void main(String[] args) throws IOException, SolrServerException {
HttpSolrServer server = new HttpSolrServer("http://localhost:8983/solr");
for(int i=0;i<1000;++i) {
SolrInputDocument doc = new SolrInputDocument();
doc.addField("cat", "book");
doc.addField("id", "book-" + i);
doc.addField("name", "The Legend of the Hobbit part " + i);
server.add(doc);
if(i%100==0) server.commit(); // periodically flush
}
server.commit();
}
}
and the console error I am getting is:
Exception in thread "main" java.lang.VerifyError: Bad return type
Exception Details:
Location:
org/apache/solr/client/solrj/impl/HttpClientUtil.createClient(Lorg/apache/solr/common/params/SolrParams;Lorg/apache/http/conn/ClientConnectionManager;)Lorg/apache/http/impl/client/CloseableHttpClient; @62: areturn
Reason:
Type 'org/apache/http/impl/client/DefaultHttpClient' (current frame, stack[0]) is not assignable to 'org/apache/http/impl/client/CloseableHttpClient' (from method signature)
Current Frame:
bci: @62
flags: { }
locals: { 'org/apache/solr/common/params/SolrParams', 'org/apache/http/conn/ClientConnectionManager', 'org/apache/solr/common/params/ModifiableSolrParams', 'org/apache/http/impl/client/DefaultHttpClient' }
stack: { 'org/apache/http/impl/client/DefaultHttpClient' }
Bytecode:
0x0000000: bb00 0359 2ab7 0004 4db2 0005 b900 0601
0x0000010: 0099 001e b200 05bb 0007 59b7 0008 1209
0x0000020: b600 0a2c b600 0bb6 000c b900 0d02 00bb
0x0000030: 0011 592b b700 124e 2d2c b800 102d b0
Stackmap Table:
append_frame(@47,Object[#127])
at org.apache.solr.client.solrj.impl.HttpSolrClient.<init>(HttpSolrClient.java:186)
at org.apache.solr.client.solrj.impl.HttpSolrClient.<init>(HttpSolrClient.java:159)
at org.apache.solr.client.solrj.impl.HttpSolrServer.<init>(HttpSolrServer.java:30)
at com.coba.efx.news.server.SolrPopulator.main(SolrPopulator.java:14)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Process finished with exit code 1
In addition, the class HttpSolrServer
seems to be "deprecated". I don't know what that means exactly, but can someone tell me what the problem is and if it's possible to fix it? Thanks.
Upvotes: 3
Views: 5566
Reputation: 565
In case any one else is having this error it may be due to how your application is setup, especially if you have multiple referenced projects.
For me, I was receiving this issue every time I started the main project and couldn't figure out why. (View jar files on build path):
These jar files were also being deployed as part of the Deployment Assembly. I also have a referenced project being deployed. The issue was that this referenced project was also deploying the same solr-6.6.1 jar files, thus causing error to appear.
This is a bit of a edge case, but hopefully it may help someone.
Upvotes: 0
Reputation: 5250
It's definitely problem with more versions of httpclient in classpath. I had the same issue with SolrJ version 6.6.0, so I switched to version 7.0.1 and got another "version" exception:
Error: INSTANCE
INFO mapreduce.Job: Task Id attempt_xzy, Status : FAILED
Error: INSTANCE
in yarn logs:
ERROR [main] org.apache.hadoop.mapred.YarnChild:
Error running child : java.lang.NoSuchMethodError:
org.apache.solr.client.solrj.impl.CloudSolrClient$Builder.withHttpClient(Lorg/shaded/apache/http/client/HttpClient;)Lorg/apache/solr/client/solrj/impl/SolrClientBuilder;
If you are using Maven the solution is to use shade plugin and make fat jar like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>${main.class.full.name}</Main-Class>
<Build-Number>1.0</Build-Number>
</manifestEntries>
</transformer>
</transformers>
<relocations>
<relocation>
<pattern>org.apache.http</pattern>
<shadedPattern>org.shaded.apache.http</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
NOTES:
1. Make all other dependencies provided by cluster classpath provided
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client</artifactId>
<version>2.7.1</version>
<scope>provided</scope>
</dependency>
How to find version issues:
yarn classpath
orfind /usr/hdp/current -type f -name "*httpclient*"
You will see something like this:
./hadoop/lib/httpclient-4.2.5.jar
./hadoop/lib/commons-httpclient-3.1.jar
./hadoop/lib/ranger-hdfs-plugin-impl/httpclient-4.5.2.jar
./ranger-hdfs-plugin/lib/ranger-hdfs-plugin-impl/httpclient-4.5.2.jar
./hadoop-yarn/lib/httpclient-4.2.5.jar
./hadoop-yarn/lib/commons-httpclient-3.1.jar
Upvotes: 0
Reputation: 496
HttpSolrClient has a constructor that accepts an HttpClient. When not passed, it creates an internalClient that is a CloseableHttpClient.
So you can create a Default client and pass it as follows..
SystemDefaultHttpClient httpClient = new SystemDefaultHttpClient();
HttpSolrClient client = new HttpSolrClient(url, httpClient);
Upvotes: 7
Reputation: 20885
It's somewhat difficult to understand exactly what the problem is without being able to reproduce it. Anyway, it seems that a Solr method returns a DefaultHttpClient
that is not a CloseableHttpClient
, which is really weird because a quick look at the sources tells that in fact Default***
is a grandchild of Closeable***
.
However this trace is all we have: I guess your project has a (direct or indirect) dependency on some version of Apache httpclient that is incompatible with the one Solr was compiled against. You should dump the full dependency tree and ensure there's only one version.
Upvotes: 3