Solr - 使用 Httpclient 实例化 HttpSolrServer [英] Solr - instantiate HttpSolrServer with Httpclient
问题描述
我需要连接到我们位于代理(?)后面的 solr 服务器.以下我尝试过(没什么特别的):
I need to connect to our solr server which is behind a proxy(?). Following I tried (nothing special):
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 中.有人可以帮忙吗?
After that I tried the other constructor for HttpSolrServer but I don't know how to set username and password correctly into HttpClient. Can anyone help?
推荐答案
我没有看到您在代码中尝试通过代理连接的位置,您在创建 HttpSolrServer<时仅提供了 solr url/代码>.您可以在 创建你的
HttpSolrServer
实例.您的 HttpClient
实例可以包含有关代理的信息.需要的代码如下,你可以在 http-components 示例中找到:
I don't see where you're trying to connect through a proxy in your code, you only provided the solr url while creating the HttpSolrServer
. You can provide your own HttpClient
instance while creating your HttpSolrServer
instance. Your HttpClient
instance can contain the information about the proxy. The needed code should be the following, which you can find in the 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.查看这个其他问题和答案,了解您需要做什么.你需要看的httpclient版本是4.x.
Looking more at your question, I don't think you need to connect using a proxy. You error is about https. Have a look at this other question and answers to see what you need to do. The version of httpclient you need to look at is 4.x.
这篇关于Solr - 使用 Httpclient 实例化 HttpSolrServer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!