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:org.cloudifysource.shell.validators.PortAvailabilityValidator.java

private void validateFreePorts(final String portOrRange) throws CLIValidationException {
    try {/*from   w ww .  ja va2  s.  com*/
        if (IPUtils.isValidPortRange(portOrRange)) {
            int lowestPort = IPUtils.getMinimumPort(portOrRange);
            int highestPort = IPUtils.getMaximumPort(portOrRange);
            IPUtils.validatePortIsFreeInRange(Constants.getHostAddress(), lowestPort, highestPort);
        } else {
            try {
                int port = Integer.parseInt(portOrRange);
                if (IPUtils.isValidPortNumber(port)) {
                    IPUtils.validatePortIsFree(Constants.getHostAddress(), port);
                } else {
                    throw new IllegalArgumentException("Invalid port or range: " + portOrRange);
                }
            } catch (NumberFormatException e) {
                throw new IllegalArgumentException("Invalid port or range: " + portOrRange);
            }
        }
    } catch (UnknownHostException uhe) {
        // thrown if the IP address of the host could not be determined.
        throw new CLIValidationException(uhe, 124,
                CloudifyErrorMessages.PORT_VALIDATION_ABORTED_UNKNOWN_HOST.getName(), uhe.getMessage());
    } catch (IOException ioe) {
        // thrown if an I/O error occurs when creating the socket or connecting.
        throw new CLIValidationException(ioe, 125,
                CloudifyErrorMessages.PORT_VALIDATION_ABORTED_IO_ERROR.getName(), ioe.getMessage());
    } catch (SecurityException se) {
        // thrown if a security manager exists and permission to resolve the host name is denied.
        throw new CLIValidationException(se, 126,
                CloudifyErrorMessages.PORT_VALIDATION_ABORTED_NO_PERMISSION.getName(), se.getMessage());
    }
}

From source file:com.sun.portal.rssportlet.RssPortlet.java

private void processEditAddAction(ActionRequest request, ActionResponse response, AlertHandler alertHandler,
        Resources resources, SettingsBean readBean, SettingsBean writeBean) {
    String url = request.getParameter(INPUT_ADD_FEED);
    try {//  w  ww .ja va2  s  .c  om
        // see if the url exists
        // if there's no exception, then the feed exists and is valid
        FeedHelper.getInstance().getFeed(readBean, url);

        //add to the existing values
        LinkedList feeds = readBean.getFeeds();
        feeds.add(url);
        writeBean.setFeeds(feeds);

        //
        // set newly added feed as selected feed
        //
        writeBean.setSelectedFeed(url);

        // we stay in edit mode here
    } catch (MalformedURLException mue) {
        alertHandler.setError(resources.get("invalid_url"), mue.getMessage());
        log.info("MalformedURLException: " + mue.getMessage());
        getPortletConfig().getPortletContext().log("could not add feed", mue);
    } catch (UnknownHostException uhe) {
        alertHandler.setError(resources.get("invalid_url"), uhe.getMessage());
        log.info("UnknownHostException: " + uhe.getMessage());
    } catch (FileNotFoundException fnfe) {
        alertHandler.setError(resources.get("invalid_url"), fnfe.getMessage());
        log.info("FileNotFoundException: " + fnfe.getMessage());
        getPortletConfig().getPortletContext().log("could not add feed", fnfe);
    } catch (IllegalArgumentException iae) {
        alertHandler.setError(resources.get("invalid_url"), iae.getMessage());
        log.info("IllegalArgumentException: " + iae.getMessage());
        getPortletConfig().getPortletContext().log("could not add feed", iae);
    } catch (FeedException fe) {
        alertHandler.setError(resources.get("invalid_url"), fe.getMessage());
        log.info("FeedException: " + fe.getMessage());
        getPortletConfig().getPortletContext().log("could not add feed", fe);
    } catch (IOException ioe) {
        alertHandler.setError(resources.get("invalid_url"), ioe.getMessage());
        log.info("IOException: " + ioe.getMessage());
        getPortletConfig().getPortletContext().log("could not add feed", ioe);
    } catch (Exception ex) {
        alertHandler.setError(resources.get("invalid_url"), ex.getMessage());
        log.info("Exception: " + ex.getMessage());
        getPortletConfig().getPortletContext().log("could not add feed", ex);
    }
}

From source file:com.bigdata.dastor.client.RingCache.java

public void refreshEndPointMap() {
    for (String seed : seeds_) {
        try {/*from w w w . jav  a2  s .  com*/
            TSocket socket = new TSocket(seed, port_);
            TBinaryProtocol binaryProtocol = new TBinaryProtocol(socket, false, false);
            Dastor.Client client = new Dastor.Client(binaryProtocol);
            socket.open();

            Map<String, String> tokenToHostMap = (Map<String, String>) JSONValue
                    .parse(client.get_string_property(DastorThriftServer.TOKEN_MAP));

            BiMap<Token, InetAddress> tokenEndpointMap = HashBiMap.create();
            for (Map.Entry<String, String> entry : tokenToHostMap.entrySet()) {
                Token token = StorageService.getPartitioner().getTokenFactory().fromString(entry.getKey());
                String host = entry.getValue();
                try {
                    tokenEndpointMap.put(token, InetAddress.getByName(host));
                } catch (UnknownHostException e) {
                    throw new AssertionError(e); // host strings are IPs
                }
            }

            tokenMetadata = new TokenMetadata(tokenEndpointMap);

            break;
        } catch (TException e) {
            /* let the Exception go and try another seed. log this though */
            logger_.debug("Error contacting seed " + seed + " " + e.getMessage());
        }
    }
}

From source file:org.apache.cassandra.client.RingCache.java

public void refreshEndPointMap() {
    for (String seed : seeds_) {
        try {//from  w w w  .ja  v a2 s.  c om
            TSocket socket = new TSocket(seed, port_);
            TBinaryProtocol binaryProtocol = new TBinaryProtocol(socket, false, false);
            Cassandra.Client client = new Cassandra.Client(binaryProtocol);
            socket.open();

            Map<String, String> tokenToHostMap = (Map<String, String>) JSONValue
                    .parse(client.get_string_property(CassandraServer.TOKEN_MAP));

            BiMap<Token, InetAddress> tokenEndpointMap = HashBiMap.create();
            for (Map.Entry<String, String> entry : tokenToHostMap.entrySet()) {
                Token token = StorageService.getPartitioner().getTokenFactory().fromString(entry.getKey());
                String host = entry.getValue();
                try {
                    tokenEndpointMap.put(token, InetAddress.getByName(host));
                } catch (UnknownHostException e) {
                    throw new AssertionError(e); // host strings are IPs
                }
            }

            tokenMetadata = new TokenMetadata(tokenEndpointMap);

            break;
        } catch (TException e) {
            /* let the Exception go and try another seed. log this though */
            logger_.debug("Error contacting seed " + seed + " " + e.getMessage());
        }
    }
}

From source file:org.eclipse.skalli.services.extension.validators.HostReachableValidator.java

/**
* Returning an issue (Severity.ERROR) if host was not reachable, might be null
*///from   ww  w  .  ja  va2  s.  c  o m
private Issue getIssueByReachableHost(Severity minSeverity, UUID entityId, int item, String host) {
    if (Severity.ERROR.compareTo(minSeverity) <= 0) {
        try {
            if (!InetAddress.getByName(host).isReachable(TIMEOUT)) {
                return newIssue(Severity.ERROR, entityId, item, TXT_HOST_NOT_REACHABLE, host);
            }
        } catch (UnknownHostException e) {
            return newIssue(Severity.ERROR, entityId, item, TXT_HOST_UNKNOWN, host);
        } catch (IOException e) {
            LOG.warn(MessageFormat.format("I/O Exception on validation: {0}", e.getMessage()), e); //$NON-NLS-1$
            return null;
        }
    }
    return null;
}

From source file:cn.isif.util_plus.http.SyncHttpHandler.java

public ResponseStream sendRequest(HttpRequestBase request) throws HttpException {

    HttpRequestRetryHandler retryHandler = client.getHttpRequestRetryHandler();
    while (true) {
        boolean retry = true;
        IOException exception = null;
        try {//from w w w.  j ava  2  s. c  om
            requestUrl = request.getURI().toString();
            requestMethod = request.getMethod();
            if (HttpUtils.sHttpCache.isEnabled(requestMethod)) {
                String result = HttpUtils.sHttpCache.get(requestUrl);
                if (result != null) {
                    return new ResponseStream(result);
                }
            }

            HttpResponse response = client.execute(request, context);
            return handleResponse(response);
        } catch (UnknownHostException e) {
            exception = e;
            retry = retryHandler.retryRequest(exception, ++retriedTimes, context);
        } catch (IOException e) {
            exception = e;
            retry = retryHandler.retryRequest(exception, ++retriedTimes, context);
        } catch (NullPointerException e) {
            exception = new IOException(e.getMessage());
            exception.initCause(e);
            retry = retryHandler.retryRequest(exception, ++retriedTimes, context);
        } catch (HttpException e) {
            throw e;
        } catch (Throwable e) {
            exception = new IOException(e.getMessage());
            exception.initCause(e);
            retry = retryHandler.retryRequest(exception, ++retriedTimes, context);
        }
        if (!retry) {
            throw new HttpException(exception);
        }
    }
}

From source file:com.youzu.android.framework.http.SyncHttpHandler.java

public ResponseStream sendRequest(HttpRequestBase request) throws HttpException {

    HttpRequestRetryHandler retryHandler = client.getHttpRequestRetryHandler();
    while (true) {
        boolean retry = true;
        IOException exception = null;
        try {/*w w w  .j a va  2s  .  c  o m*/
            requestUrl = request.toString();
            requestMethod = request.getMethod();
            if (HttpUtils.sHttpCache.isEnabled(requestMethod)) {
                String result = HttpUtils.sHttpCache.get(requestUrl + request.toString());
                if (result != null) {
                    return new ResponseStream(result);
                }
            }

            HttpResponse response = client.execute(request, context);
            return handleResponse(response);
        } catch (UnknownHostException e) {
            exception = e;
            retry = retryHandler.retryRequest(exception, ++retriedTimes, context);
        } catch (IOException e) {
            exception = e;
            retry = retryHandler.retryRequest(exception, ++retriedTimes, context);
        } catch (NullPointerException e) {
            exception = new IOException(e.getMessage());
            exception.initCause(e);
            retry = retryHandler.retryRequest(exception, ++retriedTimes, context);
        } catch (HttpException e) {
            throw e;
        } catch (Throwable e) {
            exception = new IOException(e.getMessage());
            exception.initCause(e);
            retry = retryHandler.retryRequest(exception, ++retriedTimes, context);
        }
        if (!retry) {
            throw new HttpException(exception);
        }
    }
}

From source file:fm.last.irccat.IRCCat.java

public IRCCat(XMLConfiguration c) throws Exception {
    this.config = c;
    setEncoding("UTF8");
    cmdScript = config.getString("script.cmdhandler");
    maxCmdResponseLines = config.getInt("script.maxresponselines", 26);
    nick = config.getString("bot.nick");
    setName(nick);/*w w w. j a va 2s. c  om*/
    setLogin(nick);
    setMessageDelay(config.getLong("bot.messagedelay", 1000));
    setFinger(config.getString("bot.finger", "IRCCat - a development support bot, used by Last.fm"));

    try {
        // connect to server
        int tries = 0;
        while (!isConnected()) {
            tries++;
            System.out
                    .println("Connecting to server [try " + tries + "]: " + config.getString("server.address"));
            connect(config.getString("server.address"), config.getInt("server.port", 6667),
                    config.getString("server.password", ""));
            if (tries > 1)
                Thread.sleep(10000);
        }
    } catch (UnknownHostException uhe) {
        // we get stuck here on java.net.UnknownHostException
        // so just exit and let supervisor restart us
        System.err.println(uhe.toString());
        System.err.println(uhe.getMessage());
        System.exit(-1);
    } catch (Exception e) {
        System.err.println(e.toString());
        System.err.println(e.getMessage());
    }

}

From source file:com.dongfang.net.http.SyncHttpHandler.java

public ResponseStream sendRequest(HttpRequestBase request) throws HttpException {

    boolean retry = true;
    HttpRequestRetryHandler retryHandler = client.getHttpRequestRetryHandler();
    while (retry) {
        IOException exception = null;
        try {/*from w  w w .ja v a  2s . c o  m*/
            // ??
            // requestUrl = request.getURI().toString();
            // if (request.getMethod().equals(HttpRequest.HttpMethod.GET.toString())) {
            // String result = HttpUtils.sHttpGetCache.get(requestUrl);
            // if (result != null) {
            // return new ResponseStream(result);
            // }
            // }

            HttpResponse response = client.execute(request, context);
            return handleResponse(response);
        } catch (UnknownHostException e) {
            exception = e;
            retry = retryHandler.retryRequest(exception, ++retriedTimes, context);
        } catch (IOException e) {
            exception = e;
            retry = retryHandler.retryRequest(exception, ++retriedTimes, context);
        } catch (NullPointerException e) {
            exception = new IOException(e.getMessage());
            exception.initCause(e);
            retry = retryHandler.retryRequest(exception, ++retriedTimes, context);
        } catch (HttpException e) {
            throw e;
        } catch (Throwable e) {
            exception = new IOException(e.getMessage());
            exception.initCause(e);
            retry = retryHandler.retryRequest(exception, ++retriedTimes, context);
        }
        if (!retry && exception != null) {
            throw new HttpException(exception);
        }
    }
    return null;
}

From source file:eu.clarin.cmdi.virtualcollectionregistry.service.impl.HttpResponseValidator.java

@Override
public void validate(IValidatable<String> validatable) {
    try {/*  w w w .j a v  a  2 s. c  o m*/
        if (!checkValidityOfUri(URI.create(validatable.getValue()))) {
            ValidationError error = new ValidationError();
            if (status == null) {
                error.setMessage(String.format("There was an unkown issue when trying to connect to '%s'",
                        validatable.getValue()));
            } else {
                error.setMessage(String.format("'%s' received invalid HTTP response: HTTP %d %s",
                        validatable.getValue(), status.getStatusCode(), status.getReasonPhrase()));
            }
            validatable.error(error);
        }
    } catch (UnknownHostException ex) {
        ValidationError error = new ValidationError();
        error.setMessage(String.format("Unkown host: '%s'", validatable.getValue()));
        validatable.error(error);
    } catch (IOException ex) {
        ValidationError error = new ValidationError();
        error.setMessage(String.format("There was an I/O issue when trying to connect to '%s': %s",
                validatable.getValue(), ex.getMessage()));
        validatable.error(error);
    } catch (IllegalArgumentException ex) {
        ValidationError error = new ValidationError();
        error.setMessage(String.format("Invalid URI: '%s'", validatable.getValue()));
        validatable.error(error);
    }
}