This is what I get when I run the code. org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException: Error from server at http://localhost:8983/solr/testing: Expected mime type application/octet-stream but got text/html. <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> <title>Error 401 require authentication</title> </head> <body><h2>HTTP ERROR 401</h2> <p>Problem accessing /solr/testing/update. Reason: <pre> require authentication</pre></p> </body> </html>
at org.apache.solr.client.solrj.impl.HttpSolrClient.executeMethod(HttpSolrClient.java:578) at org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:279) at org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:268) at org.apache.solr.client.solrj.SolrRequest.process(SolrRequest.java:149) at org.apache.solr.client.solrj.SolrClient.add(SolrClient.java:106) at org.apache.solr.client.solrj.SolrClient.add(SolrClient.java:71) at org.apache.solr.client.solrj.SolrClient.add(SolrClient.java:85) at testing.indexing(testing.java:2939) at testing.main(testing.java:329) Exception in thread "main" org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException: Error from server at http://localhost:8983/solr/testing: Expected mime type application/octet-stream but got text/html. <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> <title>Error 401 require authentication</title> </head> <body><h2>HTTP ERROR 401</h2> <p>Problem accessing /solr/testing/update. Reason: <pre> require authentication</pre></p> </body> </html> at org.apache.solr.client.solrj.impl.HttpSolrClient.executeMethod(HttpSolrClient.java:578) at org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:279) at org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:268) at org.apache.solr.client.solrj.SolrRequest.process(SolrRequest.java:149) at org.apache.solr.client.solrj.SolrClient.commit(SolrClient.java:484) at org.apache.solr.client.solrj.SolrClient.commit(SolrClient.java:463) at testing.indexing(testing.java:3063) at testing.main(testing.java:329) Regards, Edwin On 12 April 2017 at 14:28, Noble Paul <noble.p...@gmail.com> wrote: > 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 >