【问题标题】:Solr - instantiate HttpSolrServer with HttpclientSolr - 使用 Httpclient 实例化 HttpSolrServer
【发布时间】:2012-10-09 14:39:22
【问题描述】:

我需要连接到代理(?)后面的 solr 服务器。 以下我尝试了(没什么特别的):

SolrServer server = new HttpSolrServer("https://urltosolr/solr");
try {
    SolrPingResponse pingResponse = server.ping();
} catch (SolrServerException e) {
    ....
}

堆栈跟踪:

 org.apache.solr.client.solrj.SolrServerException: IOException occured when talking to server at: https://urltosolr/solr
 ...
 Caused by: javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated

之后我尝试了 HttpSolrServer 的其他构造函数,但我不知道如何将用户名和密码正确设置到 HttpClient 中。有人可以帮忙吗?

【问题讨论】:

标签: java solr httpclient


【解决方案1】:

我没有看到您在代码中尝试通过代理连接的位置,您只在创建 HttpSolrServer 时提供了 solr url。您可以提供自己的 HttpClient 实例,而 creating 您的 HttpSolrServer 实例。您的HttpClient 实例可以包含有关代理的信息。需要的代码如下,可以在http-components examples找到:

DefaultHttpClient httpclient = new DefaultHttpClient();
HttpHost proxy = new HttpHost(proxyHost, proxyPort, "http");
httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
httpclient.getCredentialsProvider().setCredentials(
                    AuthScope.ANY,
                    new UsernamePasswordCredentials(username, password));
SolrServer solrServer = new HttpSolrServer(solrUrl, httpclient);

更多地查看您的问题,我认为您不需要使用代理进行连接。您的错误与https有关。看看this 其他问题和答案,看看你需要做什么。你需要看的httpclient版本是4.x。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多