Example usage for java.net UnknownHostException getMessage

List of usage examples for java.net UnknownHostException getMessage

Introduction

In this page you can find the example usage for java.net UnknownHostException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.cisco.cta.taxii.adapter.smoketest.SmokeTestLifecycle.java

void validateTaxiiConnectivity() {
    URL endpoint = settingsConfig.taxiiServiceSettings().getPollEndpoint();
    log.info("Contacting TAXII poll service {} ...", endpoint);
    try {//from w  w  w.  ja v  a 2  s  . c  om
        Feed feed = new TaxiiStatus.Feed();
        feed.setName(settingsConfig.taxiiServiceSettings().getFeeds().iterator().next());
        ClientHttpResponse resp = requestFactory.createPollRequest("smoke-test", feed).execute();

        switch (resp.getRawStatusCode()) {
        case 200:
            log.info("Succesfully connected to {}", endpoint);
            return;
        case 401:
        case 403:
            log.error("Authentication or authorization problem, verify your credentials in application.yml");
            return;
        default:
            log.error("{} returned {} HTTP status code, check your configuration", endpoint,
                    resp.getRawStatusCode());
        }

    } catch (UnknownHostException e) {
        log.error("Unable to resolve host name {}, verify your application.yml and your DNS settings",
                e.getMessage());
    } catch (Exception e) {
        log.error("Error connecting to " + endpoint, e);
    }
}

From source file:org.csploit.android.core.System.java

public static Target getTargetByAddress(String address) {
    try {/*  w w  w.  ja v a  2s  .co  m*/
        return getTargetByAddress(InetAddress.getByName(address));
    } catch (UnknownHostException e) {
        Logger.error("cannot convert '" + address + "' to InetAddress: " + e.getMessage());
    }
    return null;
}

From source file:org.codinjutsu.tools.jenkins.security.DefaultSecurityClient.java

private void runMethod(String url, ResponseCollector responseCollector) {
    PostMethod post = new PostMethod(url);

    if (isCrumbDataSet()) {
        post.addRequestHeader(CRUMB_NAME, crumbData);
    }/*from  ww w  . j  av a 2  s .co m*/

    post = addFiles(post);

    try {
        if (files.isEmpty()) {
            httpClient.getParams().setParameter("http.socket.timeout", DEFAULT_SOCKET_TIMEOUT);
            httpClient.getParams().setParameter("http.connection.timeout", DEFAULT_CONNECTION_TIMEOUT);
        } else {
            httpClient.getParams().setParameter("http.socket.timeout", 0);
            httpClient.getParams().setParameter("http.connection.timeout", 0);
        }

        int statusCode = httpClient.executeMethod(post);
        final String responseBody;
        try (InputStream inputStream = post.getResponseBodyAsStream();) {
            responseBody = IOUtils.toString(inputStream, post.getResponseCharSet());
        }
        checkResponse(statusCode, responseBody);

        if (HttpURLConnection.HTTP_OK == statusCode) {
            responseCollector.collect(statusCode, responseBody);
        }
        if (isRedirection(statusCode)) {
            responseCollector.collect(statusCode, post.getResponseHeader("Location").getValue());
        }
    } catch (HttpException httpEx) {
        throw new ConfigurationException(
                String.format("HTTP Error during method execution '%s': %s", url, httpEx.getMessage()), httpEx);
    } catch (UnknownHostException uhEx) {
        throw new ConfigurationException(String.format("Unknown server: %s", uhEx.getMessage()), uhEx);
    } catch (IOException ioEx) {
        throw new ConfigurationException(
                String.format("IO Error during method execution '%s': %s", url, ioEx.getMessage()), ioEx);
    } finally {
        post.releaseConnection();
    }
}

From source file:com.edmunds.common.configuration.dns.ConfigurationUtilImpl.java

private Map<String, String> buildTokenMap() {
    Validate.notNull(configuration, "ConfigurationUtilImpl.configuration is null");
    Validate.notNull(connection, "ConfigurationUtilImpl.connection is null");

    Map<String, String> tokenMap = new HashMap<String, String>();

    tokenMap.put(ENVIRONMENT_REPLACE_TOKEN, getLegacyEnvironmentName());
    tokenMap.put(URL_PREFIX_REPLACE_TOKEN, configuration.getUrlLegacyPrefix());
    tokenMap.put(TOKEN_LOGICAL_ENVIRONMENT_NAME, configuration.getLogicalEnvironmentName());
    tokenMap.put(TOKEN_ENVIRONMENT_INDEX, configuration.getEnvironmentIndex());

    final String urlPrefix = configuration.getUrlPrefix();
    tokenMap.put(TOKEN_URL_PREFIX, urlPrefix);
    tokenMap.put(TOKEN_LOCAL_ENVIRONMENT_NAME, configuration.getEnvironmentName());
    tokenMap.put(TOKEN_LOCAL_ENVIRONMENT_DATA_CENTER, configuration.getDataCenter());
    tokenMap.put(TOKEN_LOCAL_ENVIRONMENT_SITE, configuration.getSite());
    tokenMap.put(TOKEN_INTERNAL_ENVIRONMENT_NAME, connection.getInternalEnvironmentName());
    tokenMap.put(TOKEN_INTERNAL_ENVIRONMENT_DATA_CENTER, connection.getInternalDataCenter());
    String prefixNoDash = null;/*from   w  ww  .  j a v a  2 s  . com*/
    if (urlPrefix != null) {
        prefixNoDash = urlPrefix.endsWith("-") ? urlPrefix.substring(0, urlPrefix.length() - 1) : urlPrefix;
    }
    tokenMap.put(TOKEN_URL_PREFIX_NODASH, prefixNoDash);

    try {
        String hostName = InetAddress.getLocalHost().getHostName();
        tokenMap.put(HOST_REPLACE_TOKEN, hostName);
    } catch (UnknownHostException exc) {
        log.warn("Error looking up host name. No substitution will be performed: " + exc.getMessage(), exc);
    }

    try {
        String canonicalHostName = InetAddress.getLocalHost().getCanonicalHostName();
        tokenMap.put(CANONICAL_HOST_REPLACE_TOKEN, canonicalHostName);
    } catch (UnknownHostException exc) {
        log.warn("Error looking up host name. No substitution will be performed: " + exc.getMessage(), exc);
    }

    return tokenMap;
}

From source file:org.sonatype.nexus.test.utils.NexusStatusUtil.java

/**
 * @param port the port to check for being open
 * @param portName the name of the port we are checking
 * @return true if port is open, false if not
 *//*from w ww. ja va  2  s .co m*/
private boolean isPortOpen(final int port, final String portName) {
    Socket sock = null;
    try {
        sock = new Socket("localhost", port);
        return true;
    } catch (UnknownHostException e1) {
        if (log.isDebugEnabled()) {
            log.debug(portName + "(" + port + ") is not open: " + e1.getMessage());
        }
    } catch (IOException e1) {
        if (log.isDebugEnabled()) {
            log.debug(portName + "(" + port + ") is not open: " + e1.getMessage());
        }
    } finally {
        if (sock != null) {
            try {
                sock.close();
            } catch (IOException e) {
                if (log.isDebugEnabled()) {
                    log.debug("Problem closing socket to " + portName + "(" + port + ") : " + e.getMessage());
                }
            }
        }
    }
    return false;
}

From source file:ubic.gemma.core.loader.entrez.pubmed.PubMedSearchTest.java

@Test
public void testSearchAndRetrieveByHTTP() throws Exception {
    try {//from  w w  w. j av a2  s.c  o m
        PubMedSearch pms = new PubMedSearch();
        Collection<String> searchTerms = new HashSet<>();
        searchTerms.add("brain");
        searchTerms.add("hippocampus");
        searchTerms.add("habenula");
        searchTerms.add("glucose");
        Collection<BibliographicReference> actualResult = pms.searchAndRetrieveByHTTP(searchTerms);
        assertTrue("Expected at least 5 results, got " + actualResult.size(), actualResult.size() >= 5);
        /*
         * at least, this was the result on 4/2008.
         */
    } catch (java.net.UnknownHostException e) {
        PubMedSearchTest.log.warn("Test skipped due to unknown host exception");
    } catch (java.io.IOException e) {
        if (e.getMessage().contains("503") || e.getMessage().contains("502")) {
            PubMedSearchTest.log.warn("Test skipped due to a 50X error from NCBI");
            return;
        }
        throw e;
    }
}

From source file:hudson.os.windows.ManagedWindowsServiceLauncher.java

@Override
public void afterDisconnect(SlaveComputer computer, TaskListener listener) {
    try {/*from  ww w  . j a v a2  s.co m*/
        JIDefaultAuthInfoImpl auth = createAuth();
        JISession session = JISession.createSession(auth);
        session.setGlobalSocketTimeout(60000);
        SWbemServices services = WMI.connect(session, computer.getName());
        Win32Service slaveService = services.getService("hudsonslave");
        if (slaveService != null) {
            listener.getLogger().println(Messages.ManagedWindowsServiceLauncher_StoppingService());
            slaveService.StopService();
        }
    } catch (UnknownHostException e) {
        e.printStackTrace(listener.error(e.getMessage()));
    } catch (JIException e) {
        e.printStackTrace(listener.error(e.getMessage()));
    }
}

From source file:org.apache.storm.util.CoreUtil.java

@ClojureClass(className = "backtype.storm.util#local-hostname")
public static String localHostname() {
    String localHostName = "127.0.0.1";
    try {/*from   w ww .  j  a v  a 2 s  . c o m*/
        localHostName = InetAddress.getLocalHost().getCanonicalHostName();
    } catch (UnknownHostException e) {
        LOG.warn(e.getMessage());
    }
    return localHostName;
}

From source file:org.openhab.binding.lgwebos.internal.discovery.LGWebOSDiscovery.java

/**
 * Evaluate local IP optional configuration property.
 *
 * @param localIP optional configuration string
 * @return local ip or <code>empty</code> if property is not set or unparseable.
 *///www .  ja  v a2s  .  c  o  m
private Optional<InetAddress> evaluateConfigPropertyLocalIP(String localIP) {
    if (StringUtils.isNotBlank(localIP)) {
        try {
            logger.debug("localIP property was explicitly set to: {}", localIP);
            return Optional.ofNullable(InetAddress.getByName(localIP.trim()));
        } catch (UnknownHostException e) {
            logger.warn("localIP property could not be parsed: {} Details: {}", localIP, e.getMessage());
        }
    }

    return Optional.empty();
}

From source file:org.openhab.binding.lgwebos.internal.discovery.LGWebOSDiscovery.java

/**
 * Uses OpenHAB's NetworkAddressService to determine the local primary network interface.
 *
 * @return local ip or <code>empty</code> if configured primary IP is not set or could not be parsed.
 *//* w w  w  .  j  a v  a2  s  .co m*/
private Optional<InetAddress> getIpFromNetworkAddressService() {
    String ipAddress = networkAddressService.getPrimaryIpv4HostAddress();
    if (ipAddress == null) {
        logger.warn("No network interface could be found.");
        return Optional.empty();
    }
    try {
        return Optional.of(InetAddress.getByName(ipAddress));
    } catch (UnknownHostException e) {
        logger.warn("Configured primary IP cannot be parsed: {} Details: {}", ipAddress, e.getMessage());
        return Optional.empty();
    }

}