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

The following examples show how to use org.springframework.cloud.commons.util.InetUtils.HostInfo. 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
Source File: EurekaConfigurationListener.java    From summerframework with Apache License 2.0 5 votes vote down vote up
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
Source File: HostInfoEnvironmentPostProcessor.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
@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
Source File: HostInfoEnvironmentPostProcessor.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
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 File: InetUtilsTests.java    From spring-cloud-commons with 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
Source File: EurekaInstanceConfigBean.java    From spring-cloud-netflix with Apache License 2.0 4 votes vote down vote up
private HostInfo getHostInfo() {
	return hostInfo;
}
 
Example #6
Source File: EurekaInstanceConfigBean.java    From spring-cloud-netflix with Apache License 2.0 4 votes vote down vote up
private void setHostInfo(HostInfo hostInfo) {
	this.hostInfo = hostInfo;
}
 
Example #7
Source File: ConsulDiscoveryProperties.java    From spring-cloud-consul with Apache License 2.0 4 votes vote down vote up
private HostInfo getHostInfo() {
	return this.hostInfo;
}
 
Example #8
Source File: ConsulDiscoveryProperties.java    From spring-cloud-consul with Apache License 2.0 4 votes vote down vote up
private void setHostInfo(HostInfo hostInfo) {
	this.hostInfo = hostInfo;
}