Question

I have written the code mentioned below.

HttpSolrServer solrServer = new HttpSolrServer("http://10.40.4.171/solr/prime-core");
List<UserSolr> userList=null;
        SolrQuery q = new SolrQuery();
        q.setQuery("*:*");
        q.setStart(0);
        q.setRows(10);
        //SolrDocumentList results = null;
        try {
            QueryResponse response = solrServer.query(q);
            userList=response.getBeans(UserSolr.class);
        } catch (Exception e) {
            // TODO: handle exception
            System.out.println(e);
        }

But for the above I get the following error :-

org.apache.solr.client.solrj.impl.HttpSolrServer$RemoteSolrException: Server at http://10.40.4.171/solr/prime-core returned non ok status:407, message:Proxy Authorization Required

I am not able to resolve this problem. Same code is working fine with the url http://localhost:8080/solr/prime-core Please let me know how to modify to connect to the server without error.

Thanks.

Note: prime-core is my Solr Core I am using Solr 4.3

Was it helpful?

Solution

HTTP code 407 implies Proxy Authentication Required, you need to set authentication information while making connection to server via HttpClient:

httpclient.getCredentialsProvider().setCredentials(
                    AuthScope.ANY,
                    new UsernamePasswordCredentials(username, password));
solrServer = new HttpSolrServer(solrUrl, httpclient);//with credentials

you may like to check similar discussions:

Solr - instantiate HttpSolrServer with Httpclient

Solr 4 with basic authentication

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top