package de.otto.edison.status.configuration;

import de.otto.edison.status.domain.SystemInfo;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.net.InetAddress;
import java.net.UnknownHostException;

@Configuration
public class SystemInfoConfiguration {

    private static final String defaultHostname;

    static {
        String localHost = null;
        try {
            localHost = InetAddress.getLocalHost().getHostName();
        } catch (final UnknownHostException ignored) { }
        defaultHostname = localHost;
    }

    @Value("${HOSTNAME:}")
    private String hostname;
    @Value("${server.hostname:}")
    private String envhostname;
    @Value("${server.port:}")
    private int port;

    @Bean
    @ConditionalOnMissingBean(SystemInfo.class)
    public SystemInfo systemInfo() {
        return SystemInfo.systemInfo(hostname(), port);
    }

    private String hostname() {
        if (envhostname != null && !envhostname.isEmpty()) {
            return envhostname;
        }
        if(hostname != null && !hostname.isEmpty()) {
            return hostname;
        }
        return defaultHostname;
    }
}

@@ -332,32 +332,77 @@
 n.Configuration;
+%0Aimport org.springframework.util.StringUtils;
 %0A%0Aimport java.ne
@@ -740,16 +740,24 @@
 nored) %7B
+%0A       
  %7D%0A     
@@ -943,16 +943,20 @@
 er.port:
+8080
 %7D%22)%0A    
@@ -1180,32 +1180,29 @@
 if (
-envhostname != null && !
+!StringUtils.isEmpty(
 envh
@@ -1204,33 +1204,24 @@
 (envhostname
-.isEmpty(
 )) %7B%0A       
@@ -1269,38 +1269,22 @@
   if
-(hostname != null && !hostname
+ (!StringUtils
 .isE
@@ -1288,16 +1288,24 @@
 isEmpty(
+hostname
 )) %7B%0A   

Set default for server port.