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.ice.android.common.http.SyncRequestHandler.java

private Object makeRequestWithRetries(HttpUriRequest request) throws IOException {

    boolean retry = true;
    IOException cause = null;/*from w  w w .ja  v a2 s .co  m*/
    HttpRequestRetryHandler retryHandler = client.getHttpRequestRetryHandler();
    while (retry) {
        try {
            HttpResponse response = client.execute(request, context);
            return entityHandler.handleEntity(response.getEntity(), null, charset);
        } catch (UnknownHostException e) {
            cause = e;
            retry = retryHandler.retryRequest(cause, ++executionCount, context);
        } catch (IOException e) {
            cause = e;
            retry = retryHandler.retryRequest(cause, ++executionCount, context);
        } catch (NullPointerException e) {
            // HttpClient 4.0.x ?bug
            // http://code.google.com/p/android/issues/detail?id=5255
            cause = new IOException("NPE in HttpClient" + e.getMessage());
            retry = retryHandler.retryRequest(cause, ++executionCount, context);
        } catch (Exception e) {
            cause = new IOException("Exception" + e.getMessage());
            retry = retryHandler.retryRequest(cause, ++executionCount, context);
        }
    }
    if (cause != null)
        throw cause;
    else
        throw new IOException("");
}

From source file:uk.ac.ebi.fg.biostudies.jobs.ReloadBiosamplesJob.java

public void doExecute(JobExecutionContext jec) throws Exception {
    logger.info("Reloading all Biosamples data into the Application Server");
    File setupDirectory = null;//from  w w  w . j av a  2  s  .c  o m
    File backDir = null;
    //File globalSetupDBDirectory = null;
    File setupTempDirectory = null;
    String hostname = "NA";
    try {
        hostname = InetAddress.getLocalHost().getHostName();
    } catch (UnknownHostException e) {
        logger.error("Host not available-> " + e.getMessage());
    }
    try {

        // Thread.currentThread().sleep(30000);//sleep for 1000 ms

        boolean updateActive = Application.getInstance().getPreferences().getBoolean("bs.xmlupdate.active");
        logger.info("Is Reloading Active?->" + updateActive);

        if (!updateActive) {
            logger.error("ReloadBiosamplesJob is trying to execute and the configuration does not allow that");
            this.getApplication().sendEmail(null, null, hostname + "->" + "BIOSAMPLES: WARNING",
                    "ReloadBiosamplesJob is trying to execute and the configuration does not allow that!");
            // throw new
            // Exception("ReloadBiosamplesJob is trying to execute and the configuration does not allow that!");
            return;
        }

        // I will create a backup directory, where I will backup the Actual
        // Setup directory, where I will put the new biosamples.xml and
        // where I will creste a new SetupDirectory based on the new
        // biosamples.xml
        String setupDir = Application.getInstance().getPreferences().getString("bs.setupDirectory");
        logger.info("setupDir->" + setupDir);

        setupDirectory = new File(setupDir);
        String backupDirectory = Application.getInstance().getPreferences().getString("bs.backupDirectory");
        logger.info("backupDirectory->" + backupDirectory);

        String globalSetupDir = Application.getInstance().getPreferences().getString("bs.globalSetupDirectory");
        logger.info("globalSetupDirectory->" + globalSetupDir);
        File globalSetupDirectory = new File(globalSetupDir);

        String globalSetupDBDir = Application.getInstance().getPreferences()
                .getString("bs.globalSetupDBDirectory");
        logger.info("globalSetupDBDirectory->" + globalSetupDBDir);

        String globalSetupLuceneDir = Application.getInstance().getPreferences()
                .getString("bs.globalSetupLuceneDirectory");
        logger.info("globalSetupLuceneDir->" + globalSetupLuceneDir);

        //globalSetupDBDirectory=new File(globalSetupDBDir);

        String dbname = Application.getInstance().getPreferences().getString("bs.xmldatabase.dbname");
        String dbPathDirectory = Application.getInstance().getPreferences().getString("bs.xmldatabase.path");
        File dbDirectory = new File(dbPathDirectory + File.separator + dbname);
        logger.debug("dbPathDirectory->" + dbDirectory);

        // this variable will be used in the creation of the bakup
        // directory anda in the creation od the database backup
        Long tempDir = System.nanoTime();

        String newDir = "backup_" + tempDir;
        backDir = new File(backupDirectory + File.separator + newDir);
        if (backDir.mkdir()) {
            logger.info("Backup directory was created in [{}]", backDir.getAbsolutePath());

        } else {
            // TODO: rpe stop the process
            logger.error("Backup directory was NOT created in [{}]", backDir.getAbsolutePath());
            throw new Exception(
                    hostname + "->" + "Backup directory was NOT created in " + backDir.getAbsolutePath());
        }

        // DownloadBiosamplesXmlFileFromAGE dxml = new
        // DownloadBiosamplesXmlFileFromAGE();
        // I need to know which type of biosample updting process am I using
        String typeBioSampleUpdate = Application.getInstance().getPreferences().getString("bs.xmlupdate.type");
        logger.debug("Type of Biosamples updating process->" + typeBioSampleUpdate);
        IDownloadBiosamplesXmlFile dxml = DownloadBiosamplesXmlFileFactory
                .createDownloadBiosamplesXmlFile(typeBioSampleUpdate);
        File xmlDir = new File(backDir.getAbsolutePath() + "/XmlDownload");
        if (xmlDir.mkdir()) {
            logger.info("XmlDownload  directory was created in [{}]", xmlDir.getAbsolutePath());
        } else {
            logger.error("XmlDownload directory was NOT created in [{}]", xmlDir.getAbsolutePath());
            throw new Exception(
                    hostname + "->" + "XmlDownload  directory was NOT created in " + xmlDir.getAbsolutePath());
        }
        String downloadDirectory = xmlDir.getAbsolutePath();
        boolean downloadOk = dxml.downloadXml(downloadDirectory);

        if (downloadOk) {

            File oldSetupDir = new File(backDir.getAbsolutePath() + "/OldSetup");
            if (oldSetupDir.mkdir()) {
                logger.info("OldSetup Backup directory was created in [{}]", oldSetupDir.getAbsolutePath());
                copyDirectory(setupDirectory, oldSetupDir);
            } else {
                logger.error("OldSetup Backup directory was NOT created in [{}]",
                        oldSetupDir.getAbsolutePath());
                throw new Exception(hostname + "->" + "oldSetupDir Backup directory was NOT created in "
                        + oldSetupDir.getAbsolutePath());
            }

            // update of the xmlDatabase
            logger.info("DatabaseXml Creation");

            // File newSetupDir= new File(backDir.getAbsolutePath() +
            // "/newSetup" );
            // I need to change this because it's not possible to move
            // directories from a local disk (/tomcat/temp to NFS). So my
            // all temporary Setup will be created in the same place where
            // is th Setup Directory)
            // getParentFile() to create at the same level of Setup
            // directory
            File newSetupDir = new File(setupDirectory.getParentFile().getAbsolutePath() + "/newSetup");

            if (newSetupDir.exists()) {
                // I will force the delete of the NewSetupDir (I need this
                // because if for any reason the process fails once (before
                // it renames nesSetup to Setup), the next time the process
                // will always fail because the newSetup already exists
                FileUtils.forceDelete(newSetupDir);
            }
            if (newSetupDir.mkdir()) {
                logger.info("newSetupDir  directory was created in [{}]", newSetupDir.getAbsolutePath());
            } else {
                logger.error("newSetupDir directory was NOT created in [{}]", newSetupDir.getAbsolutePath());
                throw new Exception(hostname + "->" + "newSetupDir  directory was NOT created in "
                        + newSetupDir.getAbsolutePath());
            }

            // update in a temporary database
            // index it in the newSetupDir
            updateXMLDatabase(xmlDir, newSetupDir, tempDir);
            logger.info("End of DatabaseXml Creation");
            // only after update the database I update the Lucenes Indexes
            logger.info("Deleting Setup Directory and renaming - from now on the application is not answering");

            SearchEngine search = ((SearchEngine) getComponent("SearchEngine"));

            // I need to close the IndexReader otherwise it would not be
            // possible dor me to delete the Setup directory (this problem
            // only occurs on NFS);
            search.getController().getEnvironment("biostudies").closeIndexReader();

            // remove the old setupdirectory /tmp/Setup is deleted
            deleteDirectory(setupDirectory);

            // Rename file (or directory) /tmp/newSetup->  /tmp/Setup
            logger.info("Before file renamed!!!");
            boolean success2 = newSetupDir.renameTo(setupDirectory);
            File globalSetupLuceneDirectory = new File(globalSetupDir + File.separator + globalSetupLuceneDir);
            if (success2) {
                logger.info("newSetupDir was successfully renamed to [{}]!!!",
                        setupDirectory.getAbsolutePath());
                // need to remove the globalSetupDirectory e copy the new
                // one to there
                if (globalSetupLuceneDirectory.exists()) {
                    FileUtils.forceDelete(globalSetupLuceneDirectory);
                } else {
                    logger.info("globalSetupLuceneDirectory doesnt exist!! [{}]!!!",
                            globalSetupLuceneDirectory.getAbsolutePath());
                }

            } else {
                logger.error("newSetupDir was not successfully renamed to [{}]!!!",
                        setupDirectory.getAbsolutePath());
                throw new Exception(hostname + "->" + "newSetupDir was not successfully renamed to ->"
                        + setupDirectory.getAbsolutePath());
            }
            logger.info("Deleting Setup Directory and renaming - End");

            // I do this to know the number of elements
            ((BioStudies) getComponent("BioStudies")).reloadIndex();
            // TODO: rpe nowaday I need to do this to clean the xmldatabase
            // connection nad to reload the new index
            ((IndexEnvironmentBioStudies) search.getController().getEnvironment("biostudies")).setup();

            //Copy the data to GlobalSETUP (doing this here to reduce the downtime            
            FileUtils.copyDirectory(setupDirectory, globalSetupLuceneDirectory);
            logger.info("XML DB was copied to globalSetupLuceneDirectory !! [{}]!!!",
                    globalSetupLuceneDirectory.getAbsolutePath());
            //I will also copy there the XML DB               
            File newSetupDBDir = new File(
                    dbDirectory.getParentFile().getAbsolutePath() + File.separator + dbname);

            File globalSetupDBDirectory = new File(globalSetupDir + File.separator + globalSetupDBDir);
            if (globalSetupDBDirectory.exists()) {
                FileUtils.forceDelete(globalSetupDBDirectory);
            } else {
                logger.info("globalSetupDBDirectory doesnt exist!! [{}]!!!",
                        globalSetupDBDirectory.getAbsolutePath());
                throw new Exception(hostname + "->" + "globalSetupDBDirectory doesnt exist!! ->"
                        + globalSetupDBDirectory.getAbsolutePath());
            }

            if (newSetupDBDir.exists()) {
                FileUtils.copyDirectory(newSetupDBDir, globalSetupDBDirectory);
                logger.info("XML DB was copied to globalSetupDBDirectory !! [{}]!!!",
                        globalSetupDBDirectory.getAbsolutePath());
            } else {
                logger.error("New Xml DB doesnt exist!! [{}]!!!", newSetupDBDir.getAbsolutePath());
                throw new Exception(
                        hostname + "->" + "New Xml DB doesnt exist!!->" + newSetupDBDir.getAbsolutePath());
            }

            //send an email saying that everything is ok (with some stats)
            this.getApplication().sendEmail(null, null,
                    hostname + "->" + "BIOSTUDIES: RELOAD biostudies-> + "
                            + ((IndexEnvironmentBioStudies) search.getController().getEnvironment("biostudies"))
                                    .getCountDocuments(),
                    "ReloadBiosamplesJob is finished!");

        } else {
            logger.debug("Something went wrong on Xml download");
            throw new Exception(hostname + "->" + " Something went wrong on Xml download");

        }

    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {

    }
    logger.info("End of Reloading all Biosamples data into the Application Server");

    // I want to start using the new version of the data
    // (/Users/rpslpereira/Apps/apache-tomcat-6.0.33/temp/StagingArea/4)
}

From source file:cn.rongcloud.im.server.network.http.AsyncHttpRequest.java

private void makeRequestWithRetries() throws IOException {
    boolean retry = true;
    IOException cause = null;//w ww. j a va 2  s .  c  o  m
    HttpRequestRetryHandler retryHandler = client.getHttpRequestRetryHandler();
    try {
        while (retry) {
            try {
                makeRequest();
                return;
            } catch (UnknownHostException e) {
                // switching between WI-FI and mobile data networks can cause a retry which then results in an UnknownHostException
                // while the WI-FI is initialising. The retry logic will be invoked here, if this is NOT the first retry
                // (to assist in genuine cases of unknown host) which seems better than outright failure
                cause = new IOException("UnknownHostException exception: " + e.getMessage());
                retry = (executionCount > 0) && retryHandler.retryRequest(cause, ++executionCount, context);
            } catch (NullPointerException e) {
                // there's a bug in HttpClient 4.0.x that on some occasions causes
                // DefaultRequestExecutor to throw an NPE, see
                // http://code.google.com/p/android/issues/detail?id=5255
                cause = new IOException("NPE in HttpClient: " + e.getMessage());
                retry = retryHandler.retryRequest(cause, ++executionCount, context);
            } catch (IOException e) {
                cause = e;
                retry = retryHandler.retryRequest(cause, ++executionCount, context);
            }
            if (retry && (responseHandler != null)) {
                responseHandler.sendRetryMessage();
            }
        }
    } catch (Exception e) {
        // catch anything else to ensure failure message is propagated
        Log.e("AsyncHttpRequest", "Unhandled exception origin cause", e);
        cause = new IOException("Unhandled exception: " + e.getMessage());
    }

    // cleaned up to throw IOException
    throw (cause);
}

From source file:com.sf.httpclient.core.HttpHandler.java

private void makeRequestWithRetries(HttpUriRequest request) throws IOException {
    if (isResume && targetUrl != null) {
        File downloadFile = new File(targetUrl);
        long fileLen = 0;
        if (downloadFile.isFile() && downloadFile.exists()) {
            fileLen = downloadFile.length();
        }//  w w w  .j a v a 2  s.com
        if (fileLen > 0)
            request.setHeader("RANGE", "bytes=" + fileLen + "-");
    }

    boolean retry = true;
    IOException cause = null;
    HttpRequestRetryHandler retryHandler = client.getHttpRequestRetryHandler();
    while (retry) {
        try {
            if (!isCancelled()) {
                HttpResponse response = client.execute(request, context);
                if (!isCancelled()) {
                    handleResponse(response);
                }
            }
            return;
        } catch (UnknownHostException e) {
            publishProgress(UPDATE_FAILURE, e, 0, "unknownHostExceptioncan't resolve host");
            return;
        } catch (IOException e) {
            cause = e;
            retry = retryHandler.retryRequest(cause, ++executionCount, context);
        } catch (NullPointerException e) {
            cause = new IOException("NPE in HttpClient" + e.getMessage());
            retry = retryHandler.retryRequest(cause, ++executionCount, context);
        } catch (Exception e) {
            cause = new IOException("Exception" + e.getMessage());
            retry = retryHandler.retryRequest(cause, ++executionCount, context);
        }
    }
    if (cause != null)
        throw cause;
    else
        throw new IOException("");
}

From source file:org.openuat.apps.IPSecConnectorAdmin.java

public void AuthenticationFailure(Object sender, Object remote, Exception e, String msg) {
    super.AuthenticationFailure(sender, remote, e, msg);
    guiHandler.setPaintingToFreeze(false);
    String text = " Authenciation Failure: " + msg + "\n Would you like to restart Authenctication for id="
            + actualid + "?";
    int option = guiHandler.showYesNoMessageBox(text, "Authentication Failure");
    if (option == JOptionPane.YES_OPTION && actualid != -1) {
        try {/*from ww  w .  j  a v  a2s  .  c o m*/
            guiHandler.doAutenticationForId(actualid);
        } catch (UnknownHostException e1) {
            guiHandler.showErrorMessageBox("Error:" + e1.getMessage(), "Uknown Host Exception");
        } catch (IOException e1) {
            guiHandler.showErrorMessageBox("Error:" + e1.getMessage(), "IO Exception");
        }
    } else {
        guiHandler.adminFrame.setVisible(false);
    }
}

From source file:gda.device.scannable.keyence.Keyence.java

/**
 * Set up initial connections to socket and wrap the stream in buffered reader and writer.
 * @throws DeviceException // w  w  w .  java2s . co  m
 */
public void connect() throws DeviceException {
    try {
        synchronized (socketAccessLock) {
            if (!isConnected()) {
                InetSocketAddress inetAddr = new InetSocketAddress(host, commandPort);
                socketChannel = SocketChannel.open();
                socketChannel.connect(inetAddr);

                socketChannel.socket().setSoTimeout(socketTimeOut);
                socketChannel.configureBlocking(true);
                socketChannel.finishConnect();

                cleanPipe();
                doStartupScript();

                connected = true;
            }
        }
    } catch (UnknownHostException ex) {
        // this could be fatal as reconnect attempts are futile.
        logger.error(getName() + ": connect: " + ex.getMessage());
    } catch (ConnectException ex) {
        logger.debug(getName() + ": connect: " + ex.getMessage());
    } catch (IOException ix) {
        logger.error(getName() + ": connect: " + ix.getMessage());
    }
}

From source file:com.ab.http.AsyncHttpRequest.java

/**
 * Make request with retries./*from w  w  w . java2 s.  com*/
 *
 * @throws IOException Signals that an I/O exception has occurred.
 */
private void makeRequestWithRetries() throws IOException {
    boolean retry = true;
    IOException cause = null;
    HttpRequestRetryHandler retryHandler = client.getHttpRequestRetryHandler();
    try {
        while (retry) {
            try {
                makeRequest();
                return;
            } catch (UnknownHostException e) {
                // switching between WI-FI and mobile data networks can cause a retry which then results in an UnknownHostException
                // while the WI-FI is initialising. The retry logic will be invoked here, if this is NOT the first retry
                // (to assist in genuine cases of unknown host) which seems better than outright failure
                cause = new IOException("UnknownHostException exception: " + e.getMessage());
                retry = (executionCount > 0) && retryHandler.retryRequest(cause, ++executionCount, context);
            } catch (NullPointerException e) {
                // there's a bug in HttpClient 4.0.x that on some occasions causes
                // DefaultRequestExecutor to throw an NPE, see
                // http://code.google.com/p/android/issues/detail?id=5255
                cause = new IOException("NPE in HttpClient: " + e.getMessage());
                retry = retryHandler.retryRequest(cause, ++executionCount, context);
            } catch (IOException e) {
                cause = e;
                retry = retryHandler.retryRequest(cause, ++executionCount, context);
            }
            if (retry && (responseHandler != null)) {
                responseHandler.sendRetryMessage();
            }
        }
    } catch (Exception e) {
        // catch anything else to ensure failure message is propagated
        cause = new IOException("Unhandled exception: " + e.getMessage());
    }

    // cleaned up to throw IOException
    throw (cause);
}

From source file:de.grobox.blitzmail.AsyncMailTask.java

@Override
protected Boolean doInBackground(Void... params) {
    // try to get proper hostname and set fake one if failed
    if (props.getProperty("mail.smtp.localhost", "").equals("android.com")) {
        String hostname = "";
        try {/*from   ww w  .jav a  2  s  . c o m*/
            hostname = InetAddress.getLocalHost().getHostName();
        } catch (UnknownHostException e) {
            // do nothing
        }
        if (!hostname.equals("localhost")) {
            props.setProperty("mail.smtp.localhost", hostname);
        }
    }

    MailSender sender = new MailSender(props);

    try {
        sender.sendMail(mail.optString("subject"), mail.optString("body"), mail.optString("cc", null),
                mail.optString("bcc", null));
    } catch (Exception e) {
        Log.d("AsyncMailTask", "ERROR: " + e.getMessage());

        // remember exception for when task is finished
        this.e = e;

        return false;
    }
    return true;
}

From source file:com.wisedu.scc.love.widget.http.SyncRequestHandler.java

private String makeRequestWithRetries(HttpUriRequest request) throws IOException {

    boolean retry = true;
    IOException cause = null;//from   w  w w  . j  a  v  a 2 s  .  co m
    HttpRequestRetryHandler retryHandler = client.getHttpRequestRetryHandler();

    while (retry) {
        try {
            HttpResponse response = client.execute(request, context);
            return entityHandler.handleEntity(response.getEntity(), null, charset);
        } catch (UnknownHostException e) {
            cause = e;
            retry = retryHandler.retryRequest(cause, ++executionCount, context);
        } catch (IOException e) {
            cause = e;
            retry = retryHandler.retryRequest(cause, ++executionCount, context);
        } catch (NullPointerException e) {
            e.printStackTrace();
            // HttpClient 4.0.x ?bug
            // http://code.google.com/p/android/issues/detail?id=5255
            cause = new IOException("NPE in HttpClient" + e.getMessage());
            retry = retryHandler.retryRequest(cause, ++executionCount, context);
        } catch (Exception e) {
            cause = new IOException("Exception" + e.getMessage());
            retry = retryHandler.retryRequest(cause, ++executionCount, context);
        }
    }

    if (cause != null)
        throw cause;
    else
        throw new IOException("");

}

From source file:org.openhab.binding.mochadx10.internal.MochadX10Binding.java

/**
 * Connect to the Mochad X10 host//from   w w w .  j  a va2  s.c  o  m
 */
private void connectToMochadX10Server() {
    try {
        client = new Socket(hostIp, hostPort);

        in = new BufferedReader(new InputStreamReader(client.getInputStream()));
        out = new DataOutputStream(client.getOutputStream());

        logger.debug("Connected to Mochad X10 server");
    } catch (UnknownHostException e) {
        logger.error("Unknown host: " + hostIp + ":" + hostPort);
    } catch (IOException e) {
        logger.error("IOException: " + e.getMessage() + " while trying to connect to Mochad X10 host: " + hostIp
                + ":" + hostPort);
    }
}