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) {
....
}
stacktrace:
stacktrace:
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。您可以提供自己的 HttpClient
实例,而创建你的 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屋!