public static String resolveCloudHost(UtilityHttpClient httpClient) {
        // cached so we only attempt it once
        if (cachedCloudHost == null) {
            String value = null;
            // AWS
            LOGGER.debug("Attempting to get AWS host information");

            try {
                String response = httpClient.performGetRequest("http://169.254.169.254/2014-02-25/meta-data/public-hostname");
                // confirm it has a aws hostname
                if (response != null && response.contains("amazonaws.com")) {
                    value = response;
                    LOGGER.debug(format("Found AWS hostname: %s", value));
                } else if (response != null && "".equals(response)) {
                    // sometimes aws does not get a hostname, so we fallback to use
                    // the public ip
                    response = httpClient.performGetRequest("http://169.254.169.254/2014-02-25/meta-data/public-ipv4");
                    if (response != null) {
                        value = response;
                        LOGGER.debug(format(
                                "Couldn't find AWS hostname, but did find AWS public ip: %s",
                                value));
                    }
                }

            } catch (Exception e) {
                // NOOP try next supported cloud provider if it exists
                LOGGER.debug(format("failed to get value due to exception with message: %s ", e.getMessage()));
            }
            // TODO: Add more as we support cloud platforms
            cachedCloudHost = value;
        }
        return cachedCloudHost;
    }
public static String resolveCloudHost ( UtilityHttpClient httpClient ) { if ( cachedCloudHost == null ) { String value = null ; LOGGER . debug ( "Attempting to get AWS host information" ) ; try { String response = httpClient . performGetRequest ( "http://169.254.169.254/2014-02-25/meta-data/public-hostname" ) ; if ( response != null && response . contains ( "amazonaws.com" ) ) { value = response ; LOGGER . debug ( format ( "Found AWS hostname: %s" , value ) ) ; } else if ( response != null && "" . equals ( response ) ) { response = httpClient . performGetRequest ( "http://169.254.169.254/2014-02-25/meta-data/public-ipv4" ) ; if ( response != null ) { value = response ; LOGGER . debug ( format ( "Couldn't find AWS hostname, but did find AWS public ip: %s" , value ) ) ; } } } catch ( Exception e ) { LOGGER . debug ( format ( "failed to get value due to exception with message: %s " , e . getMessage ( ) ) ) ; } cachedCloudHost = value ; } return cachedCloudHost ; }
public with UtilityHttpClient is for testing