Java Code Examples for org.springframework.cloud.commons.util.InetUtils.HostInfo

The following examples show how to use org.springframework.cloud.commons.util.InetUtils.HostInfo. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private HostInfo getFirstNonLoopbackHostInfo(ConfigurableEnvironment environment) {
    InetUtilsProperties target = new InetUtilsProperties();
    ConfigurationPropertySources.attach(environment);
    Binder.get(environment).bind(InetUtilsProperties.PREFIX, Bindable.ofInstance(target));
    try (InetUtils utils = new InetUtils(target)) {
        return utils.findFirstNonLoopbackHostInfo();
    }
}
 
Example 2
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment,
		SpringApplication application) {
	InetUtils.HostInfo hostInfo = getFirstNonLoopbackHostInfo(environment);
	LinkedHashMap<String, Object> map = new LinkedHashMap<>();
	map.put("spring.cloud.client.hostname", hostInfo.getHostname());
	map.put("spring.cloud.client.ip-address", hostInfo.getIpAddress());
	MapPropertySource propertySource = new MapPropertySource(
			"springCloudClientHostInfo", map);
	environment.getPropertySources().addLast(propertySource);
}
 
Example 3
private HostInfo getFirstNonLoopbackHostInfo(ConfigurableEnvironment environment) {
	InetUtilsProperties target = new InetUtilsProperties();
	ConfigurationPropertySources.attach(environment);
	Binder.get(environment).bind(InetUtilsProperties.PREFIX,
			Bindable.ofInstance(target));
	try (InetUtils utils = new InetUtils(target)) {
		return utils.findFirstNonLoopbackHostInfo();
	}
}
 
Example 4
Source Project: spring-cloud-commons   Source File: InetUtilsTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testHostInfo() {
	try (InetUtils utils = new InetUtils(new InetUtilsProperties())) {
		HostInfo info = utils.findFirstNonLoopbackHostInfo();
		then(info.getIpAddressAsInt()).isNotNull();
	}
}
 
Example 5
private HostInfo getHostInfo() {
	return hostInfo;
}
 
Example 6
private void setHostInfo(HostInfo hostInfo) {
	this.hostInfo = hostInfo;
}
 
Example 7
private HostInfo getHostInfo() {
	return this.hostInfo;
}
 
Example 8
private void setHostInfo(HostInfo hostInfo) {
	this.hostInfo = hostInfo;
}