modify hostname handling

This commit is contained in:
Shinsuke Sugaya 2016-01-20 06:41:40 +09:00
parent 955c7d04f2
commit ed7cee3f04
2 changed files with 11 additions and 10 deletions

View file

@ -18,7 +18,6 @@ package org.codelibs.fess.exec;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.net.InetAddress;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
@ -278,15 +277,7 @@ public class Crawler implements Serializable {
dataMap.put(StringUtil.decapitalize(entry.getKey()), entry.getValue());
}
try {
dataMap.put("hostname", InetAddress.getLocalHost().toString());
} catch (final Exception e1) {
try {
dataMap.put("hostname", InetAddress.getLocalHost().getHostAddress());
} catch (final Exception e2) {
dataMap.put("hostname", "Unknown");
}
}
dataMap.put("hostname", ComponentUtil.getSystemHelper().getHostname());
logger.debug("\ninfoMap: {}\ndataMap: {}", infoMap, dataMap);

View file

@ -281,4 +281,14 @@ public class SystemHelper implements Serializable {
shutdownHookList.add(hook);
}
public String getHostname() {
Map<String, String> env = System.getenv();
if (env.containsKey("COMPUTERNAME"))
return env.get("COMPUTERNAME");
else if (env.containsKey("HOSTNAME"))
return env.get("HOSTNAME");
else
return "Unknown";
}
}