Re: Solr6.3.0 SolrJ API for Basic Authentication

2017-02-16 Thread Hrishikesh Gadre
Hey,

The other alternative would be to implement a HttpClientConfigurer which
can perform preemptive basic authentication (just the same way SolrRequest
is sending the credentials). The code is available in the branch_6x here,

https://github.com/apache/lucene-solr/blob/1bfa057d5c9d89b116031baa7493ee422b4cbabb/solr/solrj/src/java/org/apache/solr/client/solrj/impl/PreemptiveBasicAuthConfigurer.java

For the 6.3.x installation, you can copy this code and include it as a
custom jar on the client side. As part of the client initialization, just
configure this implementation of client configurer. Here is a sample code
snippet you can use as a reference.

https://github.com/apache/lucene-solr/blob/a986368fd0670840177a8c19fb15dcd1f0e69797/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpClientUtil.java#L111-L123

Let me know if you have any questions.

Thanks
Hrishikesh


On Thu, Feb 16, 2017 at 6:39 AM, Bryan Bende  wrote:

> Hello,
>
> The QueryRequest was just an example, it will work with any request
> that extends SolrRequest.
>
> How are you indexing your documents?
>
> I am going to assume you are doing something like this:
>
> SolrClient client = ...
> client.add(solrInputDocument);
>
> Behind the scenes this will do something like the following:
>
> UpdateRequest req = new UpdateRequest();
> req.add(doc);
> req.setCommitWithin(commitWithinMs);
> req.process(client, collection);
>
> So you can do that your self and first set the basic auth credentials
> on the UpdateRequest which extends SolrRequest.
>
> Thanks,
>
> Bryan
>
> On Thu, Feb 16, 2017 at 5:45 AM, vrindavda  wrote:
> > Hi Bryan,
> >
> > Thanks for your quick response.
> >
> > I am trying to ingest data into SolrCloud,  Hence I will not have any
> solr
> > query. Will it be right approach to use QueryRequest to index data ? Do I
> > need to put any dummy solrQuery instead ?
> >
> >
> >
> > --
> > View this message in context: http://lucene.472066.n3.
> nabble.com/Solr6-3-0-SolrJ-API-for-Basic-Authentication-
> tp4320238p4320675.html
> > Sent from the Solr - User mailing list archive at Nabble.com.
>


Re: Solr6.3.0 SolrJ API for Basic Authentication

2017-02-16 Thread Bryan Bende
Hello,

The QueryRequest was just an example, it will work with any request
that extends SolrRequest.

How are you indexing your documents?

I am going to assume you are doing something like this:

SolrClient client = ...
client.add(solrInputDocument);

Behind the scenes this will do something like the following:

UpdateRequest req = new UpdateRequest();
req.add(doc);
req.setCommitWithin(commitWithinMs);
req.process(client, collection);

So you can do that your self and first set the basic auth credentials
on the UpdateRequest which extends SolrRequest.

Thanks,

Bryan

On Thu, Feb 16, 2017 at 5:45 AM, vrindavda  wrote:
> Hi Bryan,
>
> Thanks for your quick response.
>
> I am trying to ingest data into SolrCloud,  Hence I will not have any solr
> query. Will it be right approach to use QueryRequest to index data ? Do I
> need to put any dummy solrQuery instead ?
>
>
>
> --
> View this message in context: 
> http://lucene.472066.n3.nabble.com/Solr6-3-0-SolrJ-API-for-Basic-Authentication-tp4320238p4320675.html
> Sent from the Solr - User mailing list archive at Nabble.com.


Re: Solr6.3.0 SolrJ API for Basic Authentication

2017-02-16 Thread vrindavda
Hi Bryan,

Thanks for your quick response.

I am trying to ingest data into SolrCloud,  Hence I will not have any solr
query. Will it be right approach to use QueryRequest to index data ? Do I
need to put any dummy solrQuery instead ?



--
View this message in context: 
http://lucene.472066.n3.nabble.com/Solr6-3-0-SolrJ-API-for-Basic-Authentication-tp4320238p4320675.html
Sent from the Solr - User mailing list archive at Nabble.com.


Re: Solr6.3.0 SolrJ API for Basic Authentication

2017-02-14 Thread Bryan Bende
Hello,

The exception you are getting looks more like you can't connect to the
IP address from where your SolrJ code is running, but not sure.

For the basic credentials, rather than trying to do something with the
http client, you can provide them on the request like this:

QueryRequest req = new QueryRequest(solrQuery);
req.setBasicAuthCredentials(username, password);

The setBasicAuthCredentials method is part of SolrRequest, so any
request that extends it should allow the credentials to be set.

-Bryan


On Tue, Feb 14, 2017 at 6:27 AM, vrindavda  wrote:
> Hello ,
>
> I am trying to connect SolrCloud using SolrJ API using following code :
>
>   String zkHostString = "localhost:9983";
>   String USER = "solr";
>   String PASSWORD = "SolrRocks";
>
>
>   CredentialsProvider credentialsProvider = new
> BasicCredentialsProvider();
>   credentialsProvider.setCredentials(AuthScope.ANY, new
> UsernamePasswordCredentials(USER, PASSWORD));
>   CloseableHttpClient httpClient =
> HttpClientBuilder.create().setDefaultCredentialsProvider(credentialsProvider).build();
>
>   CloudSolrClient solr = new
> CloudSolrClient.Builder().withZkHost(zkHostString).withHttpClient(httpClient).build();
>   ((CloudSolrClient)solr).setDefaultCollection("gettingstarted");
>
>
>
>
> But getting Error As :
>
>
> Exception in thread "main"
> org.apache.solr.client.solrj.impl.CloudSolrClient$RouteException:
> IOException occured when talking to server at:
> http://192.168.0.104:8983/solr/gettingstarted_shard2_replica1
> at
> org.apache.solr.client.solrj.impl.CloudSolrClient.directUpdate(CloudSolrClient.java:767)
> at
> org.apache.solr.client.solrj.impl.CloudSolrClient.sendRequest(CloudSolrClient.java:1173)
> at
> org.apache.solr.client.solrj.impl.CloudSolrClient.requestWithRetryOnStaleState(CloudSolrClient.java:1062)
> at
> org.apache.solr.client.solrj.impl.CloudSolrClient.request(CloudSolrClient.java:1004)
> at 
> org.apache.solr.client.solrj.SolrRequest.process(SolrRequest.java:149)
> at org.apache.solr.client.solrj.SolrClient.add(SolrClient.java:173)
> at org.apache.solr.client.solrj.SolrClient.add(SolrClient.java:190)
> at com.app.graphiti.TextParser.main(TextParser.java:92)
> Caused by: org.apache.solr.client.solrj.SolrServerException: IOException
> occured when talking to server at:
> http://192.168.0.104:8983/solr/gettingstarted_shard2_replica1
> at
> org.apache.solr.client.solrj.impl.HttpSolrClient.executeMethod(HttpSolrClient.java:607)
> at
> org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:262)
> at
> org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:251)
> at
> org.apache.solr.client.solrj.impl.LBHttpSolrClient.doRequest(LBHttpSolrClient.java:435)
> at
> org.apache.solr.client.solrj.impl.LBHttpSolrClient.request(LBHttpSolrClient.java:387)
> at
> org.apache.solr.client.solrj.impl.CloudSolrClient.lambda$directUpdate$0(CloudSolrClient.java:742)
> at java.util.concurrent.FutureTask.run(Unknown Source)
> at
> org.apache.solr.common.util.ExecutorUtil$MDCAwareThreadPoolExecutor.lambda$execute$0(ExecutorUtil.java:229)
> at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
> at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
> at java.lang.Thread.run(Unknown Source)
> Caused by: org.apache.http.client.ClientProtocolException
> at
> org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186)
> at
> org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
> at
> org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
> at
> org.apache.solr.client.solrj.impl.HttpSolrClient.executeMethod(HttpSolrClient.java:498)
> ... 10 more
> Caused by: org.apache.http.client.NonRepeatableRequestException: Cannot
> retry request with a non-repeatable request entity.
> at
> org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:225)
> at
> org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
> at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
> at
> org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
> at
> org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
> ... 13 more
> 16:55:40.289 [main-SendThread(0:0:0:0:0:0:0:1:9983)] DEBUG
> org.apache.zookeeper.ClientCnxn - Got ping response for sessionid:
> 0x15a3bc76e1f000e after 1ms
> 16:55:43.624 [main-SendThread(0:0:0:0:0:0:0:1:9983)] DEBUG
> org.apache.zookeeper.ClientCnxn - Got ping response for sessionid:
> 0x15a3bc76e1f000e after 1ms
> 16:55:46.958 [main-SendThread(0:0:0:0:0:0:0:1:9983)] DEBUG
> org.apache.zookeeper.ClientCnxn -