Recently the company relocation, all the services are stopped, I am responsible for the Elasticsearch do not know how to go, has been unable to run it, so I have been responsible for debugging work. After two days of debugging work, I found that the new server added the httpclient authentication mechanism, after several studies, found that the server has the following additions:
Http.basic.log:false
Http.basic.user: "Hett"
Http.basic.password: "* * * *"
Therefore, each time the IK split Word will be prompted when the message is: HTTP does not have authentication, therefore, the loading of HTTP links between the pre-authentication mechanism, in the initialization of the bean when the authentication begins, the code to do the following changes:
public class Elasticsearchserviceimpl implements Ielasticsearchservice, Initializingbean
The class inherits the authentication of the initialization bean.
To implement a method of the parent class:
@Override
public void Afterpropertiesset () throws Exception {
try {
Properties props = Propertiesloaderutils
. Loadallproperties ("********");
String Authuser = Stringutil
. NULL2STR (Props.getproperty ("username"));
String authpwd = Stringutil.null2str (Props.getproperty ("password"));
Credentialcontext = Httpclientcontext.create ();
Certification provider
Credentialsprovider Credsprovider = new Basiccredentialsprovider ();
Credsprovider.setcredentials (Authscope.any,
New Usernamepasswordcredentials (Authuser, authpwd));
Authcache Authcache = new Basicauthcache ();
Pre-populated authentication information is cached in the context so that the method executed in this context uses preemptive authentication. May be wrong
Credentialcontext.setauthcache (Authcache);
Credentialcontext.setcredentialsprovider (Credsprovider);
} catch (Exception ex) {
Logger.warn ("Read Elasticsearch credential Error", ex);
}
}
When you visit again, you will be prompted as follows:
The information that debug throws is authenticated through
After a few days of tossing and finishing finally completed the search tags such as services
So happy.
Elasticsearch httpclient authentication Mechanism