Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8604061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:28:35+00:00 2026-06-12T02:28:35+00:00

How do I connect to Solr 1.4 search server configured with Basic Auth using

  • 0

How do I connect to Solr 1.4 search server configured with Basic Auth using the SolrJ 3.6 connector?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:28:36+00:00Added an answer on June 12, 2026 at 2:28 am

    Based on the instructions on using SolrJ :

    Fetch relevant dependencies for e.g. using maven:

        <dependency>
            <groupId>org.apache.solr</groupId>
            <artifactId>solr-solrj</artifactId>
            <version>3.6.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpcore</artifactId>
            <version>4.2.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.2.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpmime</artifactId>
            <version>4.1.2</version>
        </dependency>
    

    A sample application connecting to Solr 1.4 using SolrJ 3.6 with the latest Apache Http Components http client to negotiate Basic Auth:

    import java.io.IOException;
    import java.util.Iterator;
    
    import org.apache.http.HttpException;
    import org.apache.http.HttpRequest;
    import org.apache.http.HttpRequestInterceptor;
    import org.apache.http.auth.UsernamePasswordCredentials;
    import org.apache.http.client.HttpClient;
    import org.apache.http.impl.auth.BasicScheme;
    import org.apache.http.impl.client.AbstractHttpClient;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.apache.http.protocol.HttpContext;
    import org.apache.solr.client.solrj.SolrQuery;
    import org.apache.solr.client.solrj.SolrServer;
    import org.apache.solr.client.solrj.SolrServerException;
    import org.apache.solr.client.solrj.impl.HttpSolrServer;
    import org.apache.solr.client.solrj.impl.XMLResponseParser;
    import org.apache.solr.client.solrj.response.QueryResponse;
    import org.apache.solr.client.solrj.response.UpdateResponse;
    import org.apache.solr.common.SolrDocument;
    import org.apache.solr.common.SolrDocumentList;
    import org.apache.solr.common.SolrInputDocument;
    
    /**
     * Sample app
     *
     */
    public class App 
    {
        public static void main( String[] args ) throws SolrServerException, IOException
        {
            String url = "https://localhost:8080/solr/";
            String httpAuthUser = "solr_admin";
            String httpAuthPass= "somePassword";
                // Configure latests Apache Http Components http client
            HttpClient httpClient = new DefaultHttpClient();
            if (httpAuthUser != null && httpAuthPass != null) {
                AbstractHttpClient client = (AbstractHttpClient) httpClient;
                App a = new App();
                client.addRequestInterceptor(a.new PreEmptiveBasicAuthenticator(httpAuthUser, httpAuthPass));
              }
            // Configure XMLResponseParser as standard javabin parser does not work with 1.4
            SolrServer solr = new HttpSolrServer(url, httpClient, new XMLResponseParser());
            // Test adding some data 
            SolrInputDocument document = new SolrInputDocument();
            document.addField("id", "552199");
            document.addField("name", "Gouda cheese wheel");
            document.addField("price", "49.99");
            UpdateResponse uresponse = solr.add(document);
            System.out.println("UpdateResponse"+uresponse.getStatus());
            solr.commit();
    
            // Query for the data just added
            SolrQuery parameters = new SolrQuery();
            parameters.set("q", "*");
            QueryResponse response = solr.query(parameters);
            SolrDocumentList list = response.getResults();
            Iterator<SolrDocument> si = list.iterator();
            System.out.println("Solr document"+list.getNumFound());
            while(si.hasNext()){
                System.out.println("Solr document"+si.next().toString());
            }
        }
    
    
        protected class PreEmptiveBasicAuthenticator implements HttpRequestInterceptor {
              private final UsernamePasswordCredentials credentials;
    
              public PreEmptiveBasicAuthenticator(String user, String pass) {
                credentials = new UsernamePasswordCredentials(user, pass);
              }
    
              public void process(HttpRequest request, HttpContext context)
                  throws HttpException, IOException {
                request.addHeader(BasicScheme.authenticate(credentials,"US-ASCII",false));
              }
            }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Solrj to connect to solr indexes. Used jar solr-solrj-3.6.1.jar which I got by
I connect to our Ubuntu production server using PuTTy. I want to reindex a
I'm planning to use Solr as search server, and will develop own spider or
I have a database application (or search engine) which is called Solr. I connect
I cannot connect to my local sql server using the following line conn =
I have an IIS server which serves a search page using SolrNet. The search
I connect to SQL Server database and grab a DataSet of the result with
I connect to a mysql database using pymysql and after executing a request I
To connect my server with the APN server I use the following code. //
I'm using Facebook Connect along with the Facebook Graph API to fetch user's email

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.