Search code examples
solrsolrj

Solr Change CommonsHttpSolrServer To HttpSolrServer


For Basic Authentication in solr 3.5 I am using the following code,

String url = "http://192.168.192.11:8080/solr/FormResponses";
CommonsHttpSolrServer server = new CommonsHttpSolrServer( url );
String username = "user";
String password = "user123";
Credentials defaultcreds = new UsernamePasswordCredentials(username, password);
server.getHttpClient().getState().setCredentials(AuthScope.ANY, defaultcreds);
server.getHttpClient().getParams().setAuthenticationPreemptive(true);

In solr 4.0 CommonsHttpSolrServer is not available, so I want to replace it with HttpSolrServer. Can anyone help me to fix this?


Solution

  • Finally I find the answer my self,

    String url = "http://192.168.192.11:8080/solr/FormResponses";
    DefaultHttpClient httpclient = new DefaultHttpClient();
        httpclient.getCredentialsProvider().setCredentials(
        AuthScope.ANY, new UsernamePasswordCredentials("user", "user123"));
    SolrServer solrServer = new HttpSolrServer(url, httpclient);