Hi,

I have an issue when using http2 solr client with SOLR (v9.0.0 and 9.2.0) 
cluster s configured with basic authentication.

Legacy solr cluster client is working fine.

Client creation code snippet:

CloudHttp2SolrClient.Builder builder = new 
CloudHttp2SolrClient.Builder(solrUrls);

 Http2SolrClient.Builder http2ClientBuilder = new Http2SolrClient.Builder();
 http2ClientBuilder.withBasicAuthCredentials("user", "password");

builder = builder.withHttpClient(http2ClientBuilder.build());

SolrClient solrClient = builder.build();

Is it correct way to create http2 solr client?


Error thrown when initiating connection to solr cluster:

 Caused by: 
org.apache.solr.client.solrj.impl.BaseHttpSolrClient$RemoteSolrException: Error 
from server at http://solr3:8983/solr: Expected mime type in 
[application/octet-stream, application/vnd.apache.solr.javabin] but got 
text/html. <html>
 <head>
 <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/>
 <title>Error 401 require authentication</title>
 </head>
 <body><h2>HTTP ERROR 401 require authentication</h2>
 <table>
 <tr><th>URI:</th><td>/solr/admin/collections</td></tr>
 <tr><th>STATUS:</th><td>401</td></tr>
 <tr><th>MESSAGE:</th><td>require authentication</td></tr>
 <tr><th>SERVLET:</th><td>default</td></tr>
 </table>

 </body>
 </html>

      at 
org.apache.solr.client.solrj.impl.Http2SolrClient.processErrorsAndResponse(Http2SolrClient.java:835)
      at 
org.apache.solr.client.solrj.impl.Http2SolrClient.processErrorsAndResponse(Http2SolrClient.java:548)
      at 
org.apache.solr.client.solrj.impl.Http2SolrClient.request(Http2SolrClient.java:507)
      at org.apache.solr.client.solrj.SolrClient.request(SolrClient.java:1193)
      at 
org.apache.solr.client.solrj.impl.BaseHttpClusterStateProvider.fetchLiveNodes(BaseHttpClusterStateProvider.java:227)
      at 
org.apache.solr.client.solrj.impl.BaseHttpClusterStateProvider.init(BaseHttpClusterStateProvider.java:63)
      at 
org.apache.solr.client.solrj.impl.Http2ClusterStateProvider.<init>(Http2ClusterStateProvider.java:32)
      at 
org.apache.solr.client.solrj.impl.CloudHttp2SolrClient$Builder.build(CloudHttp2SolrClient.java:392)
      ... 113 common frames omitted

Here is my findings:

org.apache.solr.client.solrj.impl.BaseHttpClusterStateProvider method void 
init(List<String> solrUrls)
creates initialClient to get live nodes list:

public abstract class BaseHttpClusterStateProvider implements 
ClusterStateProvider {

public void init(List<String> solrUrls) throws Exception {
    for (String solrUrl : solrUrls) {
      urlScheme = solrUrl.startsWith("https") ? "https" : "http";
      try (SolrClient initialClient = getSolrClient(solrUrl)) {
        this.liveNodes = fetchLiveNodes(initialClient);

org.apache.solr.client.solrj.impl.Http2ClusterStateProvider class method 
getSolrClient rmethod returnes new instance of Http2SolrClient with 
basicAuthAuthorizationStr = null while this.httpClient instance has not null 
value basicAuthAuthorizationStr:

public class Http2ClusterStateProvider extends BaseHttpClusterStateProvider {

  @Override
  protected SolrClient getSolrClient(String baseUrl) {
    return new 
Http2SolrClient.Builder(baseUrl).withHttpClient(httpClient).build();
  }
}

Http2SolrClient.Builder class build() method ignores basicAuthAuthorizationStr 
fiekd value provided in httpClient instance in withHttpClient() method - basic 
authentication string taken from new Http2SolrClient.Builder(baseUrl). builder 
instance with blank credentials.

 As result, initialClient instance has null basic credentials string and 
connection to solr cluster fails (401 error).


Kind regards.


Andrei Minin | Principal Developer

Intellective

ami...@intellective.com

www.intellective.com<http://www.intellective.com/>

Follow us on LinkedIn<https://www.linkedin.com/company/intellectiv/> | 
Twitter<https://twitter.com/intellectiv> | 
Facebook<https://www.facebook.com/intellectiveglobal>

Reply via email to