private void collectHostAddresses() throws Exception {
// Try to get framework config for the host name and port.
// Fetch the host addresses(IPs) of the framework server, and the set
// the recommended one as first.
FwkRuntime fwkRuntime = FwkRuntime.getInstance();
List<String> hostAddrs = new ArrayList<String>();
// This default host addr should be a String type, but we do a type
// check.
Object defaultHostAddr = fwkRuntime
.getFrameworkAttribute(IFwkEnvConstants.ATTR_WEB_APP_HOST);
if (defaultHostAddr instanceof String
&& !"localhost".equals(defaultHostAddr)
&& !"127.0.0.1".equals(defaultHostAddr)) {
// Set the default host address to the first recommened one.
hostAddrs.add((String) defaultHostAddr);
}
// Recursive for all Internet Protocol address(IP).
String hostName = InetAddress.getLocalHost().getHostName();
InetAddress[] addressese = InetAddress.getAllByName(hostName);
for (InetAddress ad : addressese) {
String addr = ad.getHostAddress();
if (!hostAddrs.contains(addr))
hostAddrs.add(addr);
}
fwkRuntime.setFrameworkAttribute(ATTR_WEB_APP_HOSTS, hostAddrs);
}