与服务器通信时发生Solrj IOException

时间:2013-05-18 17:46:41

标签: solr solrj solr4

我正在使用基本身份验证。我的solr版本是4.1。我可以获得查询结果,但当我尝试索引文档时,我收到以下错误消息:

org.apache.solr.client.solrj.SolrServerException: IOException occured when talking to server at: http://192.168.0.1:8983/solr/my_core
    at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:416)
    at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:181)
    at org.apache.solr.client.solrj.request.AbstractUpdateRequest.process(AbstractUpdateRequest.java:117)
    at org.apache.solr.client.solrj.SolrServer.add(SolrServer.java:116)
    at org.apache.solr.client.solrj.SolrServer.add(SolrServer.java:102)
    at warningletter.Process.run(Process.java:128)
    at warningletter.WarningLetter.parseListPage(WarningLetter.java:81)
    at warningletter.WarningLetter.init(WarningLetter.java:47)
    at warningletter.WarningLetter.main(WarningLetter.java:21)
Caused by: org.apache.http.client.ClientProtocolException
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:822)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:732)
    at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:353)
    ... 8 more
Caused by: org.apache.http.client.NonRepeatableRequestException: Cannot retry request with a non-repeatable request entity.
    at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:625)
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:464)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
    ... 11 more

这是我的代码:

DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("user", "password"));
HttpSolrServer server = new HttpSolrServer("http://192.168.0.1:8983/solr/warning_letter/", httpclient);
SolrInputDocument solrDoc = new SolrInputDocument();
solrDoc.addField("id", "id1");
solrDoc.addField("letter", "letter");
server.add(solrDoc);
server.commit();

我做错了什么?

1 个答案:

答案 0 :(得分:1)

诀窍是使用抢先身份验证,以避免在发送“未授权”响应后重复查询。 这是一个例子 Preemptive Basic authentication with Apache HttpClient 4