Example usage for java.net NoRouteToHostException getMessage

List of usage examples for java.net NoRouteToHostException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:uk.ac.bbsrc.tgac.miso.core.util.TransmissionUtils.java

public static FTPClient ftpConnect(String host, int port, String username, String password) throws IOException {
    FTPClient ftp = new FTPClient();
    try {//from  w ww . ja  v a 2  s .  co m
        ftp.connect(host, port);
        log.debug("Trying " + host + ":" + port);
        log.debug(ftp.getReplyString());
        int reply = ftp.getReplyCode();
        if (!FTPReply.isPositiveCompletion(reply)) {
            ftp.disconnect();
            throw new IOException("FTP server refused connection: " + reply);
        } else {
            log.debug("Connected");
        }

        ftp.login(username, password);
        ftp.setFileType(FTP.BINARY_FILE_TYPE);
        ftp.enterLocalPassiveMode();
    } catch (NoRouteToHostException e) {
        throw new IOException("Couldn't connect to printer: " + e.getMessage(), e);
    } catch (UnknownHostException e) {
        throw new IOException("Couldn't connect to printer: " + e.getMessage(), e);
    }
    return ftp;
}

From source file:uk.ac.bbsrc.tgac.miso.core.util.TransmissionUtils.java

public static FTPClient ftpConnect(String host, String username, String password) throws IOException {
    FTPClient ftp = new FTPClient();
    try {//from   w w w. j  a  v a  2s.co  m

        ftp.connect(host);
        log.debug("Trying " + host);
        log.debug(ftp.getReplyString());
        int reply = ftp.getReplyCode();
        if (!FTPReply.isPositiveCompletion(reply)) {
            ftp.disconnect();
            throw new IOException("FTP server refused connection: " + reply);
        } else {
            log.info("Connected");
        }

        ftp.login(username, password);
        ftp.setFileType(FTP.BINARY_FILE_TYPE);
        ftp.enterLocalPassiveMode();
    } catch (NoRouteToHostException e) {
        throw new IOException("Couldn't connect to printer: " + e.getMessage(), e);
    } catch (UnknownHostException e) {
        throw new IOException("Couldn't connect to printer: " + e.getMessage(), e);
    }
    return ftp;
}

From source file:org.paxle.crawler.urlRedirector.impl.testers.HttpTester.java

public boolean reject(URI requestUri) {
    // doing a head request to determine the mime-type
    HeadMethod head = null;//from   w w  w . j  a  v a 2  s .  c  o m
    try {
        // trying to do a head request
        head = new HeadMethod(requestUri.toString());
        final int status = this.httpClient.executeMethod(head);

        // skipping not OK ressources
        if (status != HttpStatus.SC_OK) {
            logger.info(
                    String.format("Rejecting URL '%s'. Status-Code was: %s", requestUri, head.getStatusLine()));
            return true;
        }

        // getting mime-type
        final String mimeType = this.getMimeType(head);

        // skipping images / css
        if (mimeType == null || mimeType.startsWith("image/") || mimeType.equalsIgnoreCase("text/css")
                || mimeType.equalsIgnoreCase("text/javascript")
                || mimeType.equalsIgnoreCase("application/x-javascript")) {
            logger.info(String.format("Rejecting URL '%s'. Unsupported mime-type: %s", requestUri, mimeType));
            return true;
        }

        // URI seems to be ok
        return false;
    } catch (NoRouteToHostException e) {
        this.logger.warn(String.format("Rejecting URL %s: %s", requestUri, e.getMessage()));
    } catch (UnknownHostException e) {
        this.logger.warn(String.format("Rejecting URL %s: Unknown host.", requestUri));
    } catch (ConnectException e) {
        this.logger.warn(String.format("Rejecting URL %s: Unable to connect to host.", requestUri));
    } catch (ConnectTimeoutException e) {
        this.logger.warn(String.format("Rejecting URL %s: %s.", requestUri, e.getMessage()));
    } catch (SocketTimeoutException e) {
        this.logger.warn(String.format("Rejecting URL %s: Connection timeout.", requestUri));
    } catch (CircularRedirectException e) {
        this.logger.warn(String.format("Rejecting URL %s: %s", requestUri, e.getMessage()));
    } catch (NoHttpResponseException e) {
        this.logger.warn(String.format("Rejecting URL %s: %s", requestUri, e.getMessage()));
    } catch (ContentLengthLimitExceededException e) {
        this.logger.warn(String.format("Rejecting URL %s: %s", requestUri, e.getMessage()));
    } catch (Throwable e) {
        logger.error(String.format("Rejecting URL '%s': ", requestUri, e.getMessage()), e);
    } finally {
        if (head != null)
            head.releaseConnection();
    }

    return true;
}

From source file:com.daskiworks.ghwatch.backend.WatchedRepositoriesService.java

/**
 * @param id of repository to unwatch/*w  ww . j ava  2  s  .c  o  m*/
 * @return view data with result of call
 */
public BaseViewData unwatchRepository(long id) {
    BaseViewData nswd = new BaseViewData();
    try {
        synchronized (TAG) {
            WatchedRepositories oldNs = Utils.readFromStore(TAG, context, persistFile);
            if (oldNs != null) {
                Repository ret = oldNs.removeRepositoryById(id);
                if (ret != null) {
                    RemoteSystemClient.deleteToURL(context, authenticationManager.getGhApiCredentials(context),
                            GHConstants.URL_BASE + "/repos/" + ret.getRepositoryFullName() + "/subscription",
                            null);
                    Utils.writeToStore(TAG, context, persistFile, oldNs);
                }
            }
        }
    } catch (NoRouteToHostException e) {
        nswd.loadingStatus = LoadingStatus.CONN_UNAVAILABLE;
    } catch (AuthenticationException e) {
        nswd.loadingStatus = LoadingStatus.AUTH_ERROR;
    } catch (IOException e) {
        Log.w(TAG, "Repository unwatch failed due connection problem: " + e.getMessage());
        nswd.loadingStatus = LoadingStatus.CONN_ERROR;
    } catch (Exception e) {
        Log.e(TAG, "Repository unwatch failed due: " + e.getMessage(), e);
        nswd.loadingStatus = LoadingStatus.UNKNOWN_ERROR;
    }
    return nswd;
}

From source file:com.daskiworks.ghwatch.backend.UnreadNotificationsService.java

/**
 * Real business logic for check new notifications on GitHub and fire androidNotification if necessary.
 * /*w  ww  .ja  v  a  2  s . co m*/
 * @see #newNotificationCheck()
 */
protected void newNotificationCheckImpl() {
    Log.d(TAG, "Notification check started");
    try {
        synchronized (TAG) {
            NotificationStream oldNs = Utils.readFromStore(TAG, context, persistFile);

            String lastModified = prepareLastModifiedHeaderContent(oldNs,
                    Utils.isInternetConnectionAvailableWifi(Utils.getConnectivityManager(context)));

            NotificationStream ns = readNotificationStreamFromServer(URL_NOTIFICATIONS, lastModified);

            if (ns != null) {
                if (lastModified != null) {
                    // incremental update has been performed and some new notif is available (ns is not null), so we have to add old ones to keep them
                    for (Notification n : oldNs)
                        ns.addNotification(n);
                    ns.setLastFullUpdateTimestamp(oldNs.getLastFullUpdateTimestamp());
                }
                Utils.writeToStore(TAG, context, persistFile, ns);

                fireAndroidNotification(ns, oldNs);
                updateWidgetsFromBackgroundCheck(ns, oldNs);
            }
        }
    } catch (NoRouteToHostException e) {
        Log.d(TAG, "Notification check failed due: " + e.getMessage());
    } catch (Exception e) {
        Log.w(TAG, "Notification check failed due: " + e.getMessage());
    } finally {
        PreferencesUtils.storeLong(context, PreferencesUtils.INT_SERVERINFO_LASTUNREADNOTIFBACKREQUESTTIMESTAMP,
                System.currentTimeMillis());
        Log.d(TAG, "Notification check finished");
    }
}

From source file:io.logspace.agent.hq.HqAgentController.java

protected void performCommit() {
    try {/*from  w w  w .  j  ava  2 s . c om*/
        do {
            List<Event> eventsForUpload = this.getEventsForUpload();
            if (eventsForUpload == null || eventsForUpload.isEmpty()) {
                return;
            }

            this.uploadEvents(eventsForUpload);
            this.purgeUploadedEvents(eventsForUpload);
        } while (this.persistentQueue.size() >= UPLOAD_SIZE);
    } catch (NoRouteToHostException nrthex) {
        this.logger.error(
                "Could not upload events because the HQ was not available: {}. Trying again in {} seconds.",
                nrthex.getMessage(), RETRY_DELAY);
        new RetryThread(this.commitRunnable, RETRY_DELAY).start();
    } catch (ConnectException cex) {
        this.logger.error(
                "Could not upload events because the HQ was not available: {}. Trying again in {} seconds.",
                cex.getMessage(), RETRY_DELAY);
        new RetryThread(this.commitRunnable, RETRY_DELAY).start();
    } catch (IOException ioex) {
        this.logger.error("Failed to upload events. Trying again in {} seconds.", RETRY_DELAY, ioex);
        new RetryThread(this.commitRunnable, RETRY_DELAY).start();
    } catch (UploadException uex) {
        this.logger.error("The HQ did not accept events: {} Trying again in {} seconds.", uex.getMessage(),
                RETRY_DELAY);
        new RetryThread(this.commitRunnable, RETRY_DELAY).start();
    }
}

From source file:io.logspace.agent.hq.HqAgentController.java

@Override
public void update(Date nextFireTime) {
    try {//from  w w w.  j  a v  a 2s  . co  m
        this.uploadCapabilities();
    } catch (UnknownHostException uhex) {
        this.logger.error(
                "Could not upload capabilities because the HQ was not available: {} - Will retry at {}",
                uhex.getMessage(), nextFireTime);
        // no need to try downloading as well
        return;
    } catch (NoRouteToHostException nrthex) {
        this.logger.error(
                "Could not upload capabilities because the HQ was not available: {} - Will retry at {}",
                nrthex.getMessage(), nextFireTime);
        // no need to try downloading as well
        return;
    } catch (ConnectException cex) {
        this.logger.error(
                "Could not upload capabilities because the HQ was not available: {} - Will retry at {}",
                cex.getMessage(), nextFireTime);
        // no need to try downloading as well
        return;
    } catch (IOException ioex) {
        this.logger.error("Failed to upload capabilities. Will retry at " + nextFireTime, ioex);
    }

    try {
        this.downloadOrder();
    } catch (ConnectException cex) {
        this.logger.error("Could not download orders because the HQ was not available: {} - Will retry at {}",
                cex.getMessage(), nextFireTime);
    } catch (HttpResponseException hrex) {
        if (hrex.getStatusCode() == HTTP_NOT_FOUND) {
            this.logger.error("There was no order available: {} - Will retry at {}", hrex.getMessage(),
                    nextFireTime);
        } else if (hrex.getStatusCode() == HTTP_FORBIDDEN) {
            this.logger.error("Not allowed to download order: {} - Will retry at {}", hrex.getMessage(),
                    nextFireTime);
        } else {
            this.logger.error("Failed to download order. Will retry at {}", nextFireTime, hrex);
        }
    } catch (IOException ioex) {
        this.logger.error("Failed to download order. Will retry at {}", nextFireTime, ioex);
    }
}

From source file:com.daskiworks.ghwatch.backend.UnreadNotificationsService.java

public BaseViewData muteNotificationThread(long id) {
    BaseViewData nswd = new BaseViewData();
    try {// www. j a v  a 2s.  c om
        RemoteSystemClient.putToURL(context, authenticationManager.getGhApiCredentials(context),
                URL_THREADS + id + "/subscription", null, "{\"ignored\":true}");
        // #49 mark it as read also to be removed from list
        markNotificationAsRead(id);
    } catch (NoRouteToHostException e) {
        nswd.loadingStatus = LoadingStatus.CONN_UNAVAILABLE;
    } catch (AuthenticationException e) {
        nswd.loadingStatus = LoadingStatus.AUTH_ERROR;
    } catch (IOException e) {
        Log.w(TAG, "Notification thread mute failed due connection problem: " + e.getMessage());
        nswd.loadingStatus = LoadingStatus.CONN_ERROR;
    } catch (Exception e) {
        Log.e(TAG, "Notification thread mute failed due: " + e.getMessage(), e);
        nswd.loadingStatus = LoadingStatus.UNKNOWN_ERROR;
    }
    return nswd;
}

From source file:com.daskiworks.ghwatch.backend.UnreadNotificationsService.java

public BaseViewData markAllNotificationsAsRead(String repository) {
    BaseViewData nswd = new BaseViewData();
    try {//from   w  w  w.j a  va  2  s.  c  o  m
        String url = URL_NOTIFICATIONS;
        if (repository != null) {
            url = URL_REPOS + repository + "/notifications";
        }
        RemoteSystemClient.putToURL(context, authenticationManager.getGhApiCredentials(context), url, null,
                "{}");
    } catch (NoRouteToHostException e) {
        nswd.loadingStatus = LoadingStatus.CONN_UNAVAILABLE;
    } catch (AuthenticationException e) {
        nswd.loadingStatus = LoadingStatus.AUTH_ERROR;
    } catch (IOException e) {
        Log.w(TAG, "NotificationRead marking failed due connection problem: " + e.getMessage());
        nswd.loadingStatus = LoadingStatus.CONN_ERROR;
    } catch (Exception e) {
        Log.e(TAG, "NotificationRead marking failed due: " + e.getMessage(), e);
        nswd.loadingStatus = LoadingStatus.UNKNOWN_ERROR;
    }
    return nswd;
}

From source file:com.daskiworks.ghwatch.backend.UnreadNotificationsService.java

public BaseViewData markNotificationAsRead(long id) {
    BaseViewData nswd = new BaseViewData();
    try {/*ww  w . j av a 2 s  .  c om*/
        RemoteSystemClient.postNoData(context, authenticationManager.getGhApiCredentials(context),
                URL_THREADS + id, null);
        synchronized (TAG) {
            NotificationStream oldNs = Utils.readFromStore(TAG, context, persistFile);
            if (oldNs != null) {
                oldNs.removeNotificationById(id);
                Utils.writeToStore(TAG, context, persistFile, oldNs);
                updateWidgets();
            }
        }
    } catch (NoRouteToHostException e) {
        nswd.loadingStatus = LoadingStatus.CONN_UNAVAILABLE;
    } catch (AuthenticationException e) {
        nswd.loadingStatus = LoadingStatus.AUTH_ERROR;
    } catch (IOException e) {
        Log.w(TAG, "NotificationRead marking failed due connection problem: " + e.getMessage());
        nswd.loadingStatus = LoadingStatus.CONN_ERROR;
    } catch (Exception e) {
        Log.e(TAG, "NotificationRead marking failed due: " + e.getMessage(), e);
        nswd.loadingStatus = LoadingStatus.UNKNOWN_ERROR;
    }
    return nswd;
}