You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by vilo <vi...@pobox.sk> on 2012/08/08 17:08:01 UTC

HTTP Basic Authentication with HttpSolrServer

I have protected my solr server with basic authentication. Now I want to
connect to it using SOLRJ. CommonsHttpSolrServer is now deprecated, so I try
to use HttpSolrServer, but I fail to send credentials. If I put them to the
url, I get 401 (http://user:password@example.com/solr). I tried this:

  HttpSolrServer solr = new HttpSolrServer(urlString);
  DefaultHttpClient httpClient = (DefaultHttpClient) solr.getHttpClient();
  httpClient.getCredentialsProvider().setCredentials(
      new AuthScope(url.getHost(), url.getPort()),
      new UsernamePasswordCredentials(username, password));

but I get "org.apache.http.client.NonRepeatableRequestException: Cannot
retry request with a non-repeatable request entity". Here is complete call
stack:

Caused by: org.apache.solr.client.solrj.SolrServerException: IOException
occured when talking to server at: http://devel1.kios.sk:8280/solr
	at
org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:439)
	at
org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:221)
	at
org.apache.solr.client.solrj.request.AbstractUpdateRequest.process(AbstractUpdateRequest.java:105)
	at org.apache.solr.client.solrj.SolrServer.add(SolrServer.java:121)
	at org.apache.solr.client.solrj.SolrServer.add(SolrServer.java:106)
	at
kinet.common.fulltext.FullTextQueueProcessor.processEntry(FullTextQueueProcessor.java:181)
	... 3 more
Caused by: org.apache.http.client.ClientProtocolException
	at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:822)
	at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)
	at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:732)
	at
org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:383)
	... 8 more
Caused by: org.apache.http.client.NonRepeatableRequestException: Cannot
retry request with a non-repeatable request entity.
	at
org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:625)
	at
org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:464)
	at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
	... 11 more

Has someone succeeded with basic authentication in combination with the
HttpSolrServer?

Thanks, Viliam



--
View this message in context: http://lucene.472066.n3.nabble.com/HTTP-Basic-Authentication-with-HttpSolrServer-tp3999829.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: HTTP Basic Authentication with HttpSolrServer [solved]

Posted by vilo <vi...@pobox.sk>.
You're partly right. The solution in the link was for CommonsHttpSolrServer,
it does work for HttpSolrServer, but the principle is the same.

Actually, I found solution for the new HttpClient here:
http://stackoverflow.com/questions/2014700/preemptive-basic-authentication-with-apache-httpclient-4/11868040#11868040
(this is my modification of some other answer)





--
View this message in context: http://lucene.472066.n3.nabble.com/HTTP-Basic-Authentication-with-HttpSolrServer-tp3999829p3999849.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: HTTP Basic Authentication with HttpSolrServer

Posted by Paul Libbrecht <pa...@hoplahup.net>.
Villam,

this is a question for httpclient, I think you want to enable preemptive authentication so as to avoid the need to repeat the query after the "unauthorized" response is sent.
	http://hc.apache.org/httpclient-3.x/authentication.html#Preemptive_Authentication

paul


Le 8 août 2012 à 17:08, vilo a écrit :

> I have protected my solr server with basic authentication. Now I want to
> connect to it using SOLRJ. CommonsHttpSolrServer is now deprecated, so I try
> to use HttpSolrServer, but I fail to send credentials. If I put them to the
> url, I get 401 (http://user:password@example.com/solr). I tried this:
> 
>  HttpSolrServer solr = new HttpSolrServer(urlString);
>  DefaultHttpClient httpClient = (DefaultHttpClient) solr.getHttpClient();
>  httpClient.getCredentialsProvider().setCredentials(
>      new AuthScope(url.getHost(), url.getPort()),
>      new UsernamePasswordCredentials(username, password));
> 
> but I get "org.apache.http.client.NonRepeatableRequestException: Cannot
> retry request with a non-repeatable request entity". Here is complete call
> stack:
> 
> Caused by: org.apache.solr.client.solrj.SolrServerException: IOException
> occured when talking to server at: http://devel1.kios.sk:8280/solr
> 	at
> org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:439)
> 	at
> org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:221)
> 	at
> org.apache.solr.client.solrj.request.AbstractUpdateRequest.process(AbstractUpdateRequest.java:105)
> 	at org.apache.solr.client.solrj.SolrServer.add(SolrServer.java:121)
> 	at org.apache.solr.client.solrj.SolrServer.add(SolrServer.java:106)
> 	at
> kinet.common.fulltext.FullTextQueueProcessor.processEntry(FullTextQueueProcessor.java:181)
> 	... 3 more
> Caused by: org.apache.http.client.ClientProtocolException
> 	at
> org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:822)
> 	at
> org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)
> 	at
> org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:732)
> 	at
> org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:383)
> 	... 8 more
> Caused by: org.apache.http.client.NonRepeatableRequestException: Cannot
> retry request with a non-repeatable request entity.
> 	at
> org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:625)
> 	at
> org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:464)
> 	at
> org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
> 	... 11 more
> 
> Has someone succeeded with basic authentication in combination with the
> HttpSolrServer?
> 
> Thanks, Viliam
> 
> 
> 
> --
> View this message in context: http://lucene.472066.n3.nabble.com/HTTP-Basic-Authentication-with-HttpSolrServer-tp3999829.html
> Sent from the Solr - User mailing list archive at Nabble.com.