2

我正在使用基本身份验证。我的 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();

我究竟做错了什么?

4

1 回答 1

1

诀窍是使用抢先式身份验证,以避免在发送“未授权”响应后需要重复查询。这是 使用 Apache HttpClient 4 的抢先式基本身份验证示例

于 2013-07-26T10:49:56.817 回答