can u paste the stacktrace here On Tue, Apr 11, 2017 at 1:19 PM, Zheng Lin Edwin Yeo <edwinye...@gmail.com> wrote: > I found from StackOverflow that we should declare it this way: > http://stackoverflow.com/questions/43335419/using-basicauth-with-solrj-code > > > SolrRequest req = new QueryRequest(new SolrQuery("*:*"));//create a new > request object > req.setBasicAuthCredentials(userName, password); > solrClient.request(req); > > Is that correct? > > For this, the NullPointerException is not coming out, but the SolrJ is > still not able to get authenticated. I'm still getting Error Code 401 even > after putting in this code. > > Any advice on which part of the SolrJ code should we place this code in? > > Regards, > Edwin > > > On 10 April 2017 at 23:50, Zheng Lin Edwin Yeo <edwinye...@gmail.com> wrote: > >> Hi, >> >> 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. >> >> I tried using the following code from the Solr Documentation >> 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. >> >> 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 >> >>
-- ----------------------------------------------------- Noble Paul