我尝试使用此类https://subversion.jfrog.org/jfrog/build-info/trunk/build-info-client/src/main/java/org/jfrog/build/为 Basic Auth 保护的 Solr 进行 PreEmptive Authentication client/PreemptiveHttpClient.java和 Solr ,但这些方法已被弃用,所以我不知道这是否是一个问题。情况是在 Solr 中查询很好,但是对于索引,我在与服务器交谈时发生 IOException:example.com:8983/solr/core1。
HttpSolrClient 构造函数需要一个 httpClient 作为参数来进行抢先授权,因此对于上面的类,因为 httpClient 存储在一个私有变量中,所以我在该变量上使用了一个 getter 来获取 httpClient 并传递给 HttpSolrClient 构造函数。也不确定我是否做对了。
PreemptiveAuthenticate preemp = new PreemptiveAuthenticate("username", "password", 1);
DefaultHttpClient httpClient = preemp.getHttpClient();
System.out.println("Made it to connectSolr after set Authentication");
SolrClient solr = new HttpSolrClient(urlString, httpClient);
我知道像http://hc.apache.org/httpcomponents-client-ga/tutorial/html/authentication.html Example 4.6 用 HttpClient 4.3 做抢先授权的例子,但这是一个测试用例,我没有看到一种传递 HttpClient 的方法,以便我可以进行抢先身份验证。