Hi Jason,

Thanks for replying.

I am adding a document, not querying. I am using 7.3 apis. Adding a
document is done via solrclient.add(....). How to set authentication in
this case? Seems I can't use SolrRequest.

Thx, bye
RAVION

On Fri, Aug 10, 2018, 10:46 AM Jason Gerlowski <gerlowsk...@gmail.com>
wrote:

> I'd tried to type my previous SolrJ example snippet from memory.  That
> didn't work out so great.  I've corrected it below:
>
> final List<String> zkUrls = new ArrayList<>();
> zkUrls.add("localhost:9983");
> final SolrClient client = new CloudSolrClient.Builder(zkUrls,
> Optional.empty()).build();
>
> final Map<String, String> queryParamMap = new HashMap<String, String>();
> queryParamMap.put("q", "*:*");
> final QueryRequest query = new QueryRequest(new
> MapSolrParams(queryParamMap));
> query.setBasicAuthCredentials("solr", "solrRocks");
>
> query.process(client, "techproducts"); // or, client.request(query)
> On Fri, Aug 10, 2018 at 10:12 AM Jason Gerlowski <gerlowsk...@gmail.com>
> wrote:
> >
> > I would also recommend removing the username/password from your Solr
> > base URL.  You might be able to get things working that way, but it's
> > definitely less common, and it wouldn't surprise me if some parts of
> > SolrJ mishandle a URL in that format.  Though that's just a hunch on
> > my part.
> > On Fri, Aug 10, 2018 at 10:09 AM Jason Gerlowski <gerlowsk...@gmail.com>
> wrote:
> > >
> > > Hi Ravion,
> > >
> > > (Note: I'm not sure what Solr version you're using.  My answer below
> > > assumes Solr 7 APIs.  These APIs don't change often, but you might
> > > find them under slightly different names in your version of Solr.)
> > >
> > > SolrJ provides 2 ways (that I know of) to provide basic auth
> credentials.
> > >
> > > The first (and IMO simplest) way is to use the setBasicAuthCredentials
> > > method on each individual SolrRequest.  You can see what this looks
> > > like in the example below:
> > >
> > > final SolrClient client = new
> > > CloudSolrCLient.Builder(solrURLs).withHttpClient(myHttpClient).build();
> > > client.setDefaultCollection("collection1");
> > > SolrQuery req = new SolrQuery("*:*");
> > > req.setBasicAuthCredentials("yourUsername", "yourPassword);
> > > client.query(req);
> > >
> > > SolrJ also has a PreemptiveBasicAuthClientBuilderFactory, which reads
> > > the username/password from Java system properties, and is used to
> > > configure the HttpClient that SolrJ creates internally for sending
> > > requests.  I find this second method a little more complex, and it
> > > looks like you're providing your own HttpClient anyways, so for both
> > > those reasons I'd recommend sticking with the first approach (at least
> > > while you're getting things up and running).
> > >
> > > Hope that helps.
> > >
> > > Best,
> > >
> > > Jason
> > >
> > > On Thu, Aug 9, 2018 at 5:47 PM ☼ R Nair <ravishankar.n...@gmail.com>
> wrote:
> > > >
> > > > Dear all,
> > > >
> > > > I have tried my best to do it - searched all Google. But I an=m
> > > > unsuccessful. Kindly help.
> > > >
> > > > We have a solo environment. Its secured with userid and password.
> > > >
> > > > I used
> > > >
> CloudSolrClient.Builder(solrURLs).withHttpClient(mycloseablehttpclient)
> > > > method to access it. The url is of the form http:/userid:password@/
> > > > passionbytes.com/solr. I set defaultCollectionName later.
> > > > In mycloseablehttpclient, I set Basic Authentication with
> > > > CredentialProvider and gave url, port, userid and password.
> > > > I have changed HTTPCLIENT to 4.4.1 version, even tried 4.5.3.
> > > >
> > > > Still, I get the JSON response from server, saying the URL did not
> return
> > > > the state information from SOLR. It says HTTP 401 , Authentication
> Required.
> > > >
> > > > This is fourth day on this problem. Any help is appreciated. I have
> done
> > > > whatever is available through documentation and/or Google.
> > > >
> > > > Best,
> > > > Ravion
>

Reply via email to