使用http请求连接到Solr服务器非常简单。但是当我尝试使用https请求进行连接时,我遇到了错误。
Solr服务器:https://localhost:8443/solr/#/
我尝试在java中使用solr api连接到服务器,代码如下:
SolrServer server = new HttpSolrServer("https://localhost:8443/solr/#/");
但我有以下例外情况:
Exception in thread "main" org.apache.solr.client.solrj.SolrServerException: IOException occured when talking to server at: https://localhost:8443/solr/#
at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:413)
at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:181)
at org.apache.solr.client.solrj.request.QueryRequest.process(QueryRequest.java:90)
at org.apache.solr.client.solrj.SolrServer.query(SolrServer.java:301)
at app.SolrQuerying.main(SolrQuerying.java:45)
Caused by: javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
at com.sun.net.ssl.internal.ssl.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:352)
at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:128)
at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:397)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:148)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:150)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:121)
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:575)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:425)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
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:352)
... 4 more
如果有人对此有任何解决方案,请分享。
答案 0 :(得分:1)
您的错误显示在此处的日志中:
引起:javax.net.ssl.SSLPeerUnverifiedException
这是说您的SSL证书未经证书颁发机构验证,我猜您创建了自签名证书?默认情况下,Java将检查由证书颁发机构验证的证书,否则将报告错误。原因是安全性。
查找如何将自签名证书与Java连接一起使用。