简体   繁体   English

将BasicAuth与SolrJ代码一起使用

[英]Using BasicAuth with SolrJ Code

I have just set up the Basic Authentication Plugin in Solr 6.4.2 on SolrCloud, and I am trying to modify my SolrJ code so that the code can go through the authentication and do the indexing. 我刚刚在SolrCloud上的Solr 6.4.2中设置了基本身份验证插件,并且尝试修改SolrJ代码,以便该代码可以通过身份验证并进行索引。

I tried using the following code from the Solr Documentation https://cwiki.apache.org/confluence/display/solr/Basic+Authentication+Plugin . 我尝试使用Solr文档https://cwiki.apache.org/confluence/display/solr/Basic+Authentication+Plugin中的以下代码。

SolrRequest req ;//create a new request object 
req.setBasicAuthCredentials(userName, password); 
solrClient.request(req);

However, the code complains that the req is not initialized. 但是,代码抱怨未对请求进行初始化。

If I initialized it, it will be initialize as null. 如果我将其初始化,它将被初始化为null。

SolrRequest req = null;//create a new request object 
req.setBasicAuthCredentials(userName, password); 
solrClient.request(req);

This will caused a null pointer exception: 这将导致空指针异常:

Exception in thread "main" java.lang.NullPointerException

How should we go about putting these codes, so that the error can be prevented? 我们应该如何放置这些代码,以防止错误发生?

Regards, 问候,
Edwin 埃德温

You declared the variable req with null value which is the result of NPE. 您用NPE的结果将变量req声明为空值。

SolrRequest req = null;//create a new request object 
req.setBasicAuthCredentials(userName, password); 

which should be like this 应该是这样的

SolrRequest req = new SolrRequest( method, path );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM