由于Apache Solr在对外网访问时候暴露端口可能会造成的安全问题,所以对登录solr控制台加了一个基本认证来实现对用户身份的辨识。但是由于solr的定时任务的jar中发送http请求并没有添加基本认证,所以日志中一直会有401 未认证的记录(solr.log)。这里做一个记录:
源代码:
protected void sendHttpPost(String completeUrl, String coreName) {
DateFormat df = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss SSS");
Date startTime = new Date();
String core = "[" + coreName + "] ";
logger.info(core + "<index update process> Process started at .............. " + df
.format(startTime));
try {
URL url = new URL(completeUrl);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("type", "submit");
conn.setDoOutput(true);
conn.connect();
logger.info(core + "<index update process> Full URL\t\t\t\t" + conn
.getURL());
logger.info(core + "<index update process> Response message\t\t\t" + conn
.getResponseMessage());
logger