Hi, I'm looking into the option of adding basic authentication using Solrj API. Currently, I'm using the following code for querying Solr.
SolrClient client = new CloudSolrClient("127.0.0.1:9983"); ((CloudSolrClient)client).setDefaultCollection("gettingstarted"); ModifiableSolrParams param = getSearchSolrQuery(); try{ QueryResponse res = client.query(param); //facets List<FacetField> fieldFacets = solrResp.getFacetFields(); // results SolrDocumentList docs = solrResp.getResults(); // Spelling SpellCheckResponse spellCheckResponse = solrResp.getSpellCheckResponse(); }catch(Exception ex){ ex.printStackTrace(); }finally{ try { client.close(); } catch (IOException e) { e.printStackTrace(); } } The QueryReponse object is well-constructed and provides clean APIs to parse the result. Now, to use the basic authentication, we need to use a SolrRequest object instead. SolrClient client = new CloudSolrClient("127.0.0.1:9983"); ((CloudSolrClient)client).setDefaultCollection("gettingstarted"); ModifiableSolrParams param = getSearchSolrQuery(); SolrRequest solrRequest = new QueryRequest(param); solrRequest.setBasicAuthCredentials(USER, PASSWORD); try{ NamedList<Object> results = client.request(solrRequest); for (int i = 0; i < results.size(); i++) { System.out.println("RESULTS: " + i + " " + results.getName(i) + " : " + results.getVal(i)); } }catch(Exception ex){ ex.printStackTrace(); }finally{ try { client.close(); } catch (IOException e) { e.printStackTrace(); } } Since my existing APIs use QueryResponse res = client.query(param) , moving to NamedList<Object> results = client.request(solrRequest) translates to a bunch of code change. Moreover, by using SolrRequest, I lose the option of delete, getById methods which doesn't accept solr request object. Just wondering if there's another way to use Basic Authentication , perhaps setting at the ModifiableSolrParams level. Ideally, i would like to retain QueryResponse or UpdateResponse objects instead. Any pointers will be appreciated. -Thanks, Shamik