连接到远程Solr实例的异常(407错误)

时间:2013-07-29 12:01:08

标签: java apache search solrj solrcloud

我写了下面提到的代码。

HttpSolrServer solrServer = new HttpSolrServer("http://10.40.4.171/solr/prime-core");
List<UserSolr> userList=null;
        SolrQuery q = new SolrQuery();
        q.setQuery("*:*");
        q.setStart(0);
        q.setRows(10);
        //SolrDocumentList results = null;
        try {
            QueryResponse response = solrServer.query(q);
            userList=response.getBeans(UserSolr.class);
        } catch (Exception e) {
            // TODO: handle exception
            System.out.println(e);
        }

但对于上述情况,我收到以下错误: -

org.apache.solr.client.solrj.impl.HttpSolrServer$RemoteSolrException: Server at http://10.40.4.171/solr/prime-core returned non ok status:407, message:Proxy Authorization Required

我无法解决此问题。相同的代码与网址http://localhost:8080/solr/prime-core正常工作。请让我知道如何修改以连接到服务器而不会出错。

感谢。

注意: prime-core是我的Solr Core 我正在使用Solr 4.3

1 个答案:

答案 0 :(得分:0)

HTTP代码407隐含Proxy Authentication Required,您需要在通过HttpClient与服务器建立连接时设置身份验证信息:

httpclient.getCredentialsProvider().setCredentials(
                    AuthScope.ANY,
                    new UsernamePasswordCredentials(username, password));
solrServer = new HttpSolrServer(solrUrl, httpclient);//with credentials

您可以查看类似的讨论:

  

Solr - instantiate HttpSolrServer with Httpclient

     

Solr 4 with basic authentication