Example usage for java.net UnknownHostException printStackTrace

List of usage examples for java.net UnknownHostException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:org.sipfoundry.preflight.FTP.java

public ResultCode validate(int timeout, NetworkResources networkResources, JournalService journalService,
        InetAddress bindAddress) {
    ResultCode results = NONE;//from   ww w .  j  a  v  a 2 s . c  om
    InetAddress ftpServerAddress = null;
    String testFile = new String("00D01EFFFFFE");
    String[] verificationStrings = { "LIP-68XX configuration information", "[VOIP]", "outbound_proxy_server",
            "[PROVISION]", "decrypt_key" };

    if (networkResources.configServer == null) {
        journalService.println("No FTP server provided, skipping test.\n");
        return CONFIG_SERVER_MISSING;
    }

    journalService.println("Starting FTP server test.");

    if (IPAddressUtil.isLiteralIPAddress(networkResources.configServer)) {
        try {
            ftpServerAddress = InetAddress.getByName(networkResources.configServer);
        } catch (UnknownHostException e) {
            // Should never get here.
            e.printStackTrace();
        }
        journalService.println("Using FTP server literal address: " + networkResources.configServer);
    } else {
        // Try to retrieve A RECORD for FTP server, checking each DNS server.
        SimpleResolver resolver = null;
        try {
            resolver = new SimpleResolver();
            resolver.setLocalAddress(bindAddress);
            resolver.setTimeout(timeout);
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }

        for (InetAddress dnsServer : networkResources.domainNameServers) {
            journalService.println(
                    "Looking up FTP server address via DNS server: " + dnsServer.getCanonicalHostName());
            String targetMessage = new String("  FTP server address \"" + networkResources.configServer + "\"");
            resolver.setAddress(dnsServer);
            Lookup aLookup = null;
            try {
                aLookup = new Lookup(networkResources.configServer, Type.A);
            } catch (TextParseException e) {
                journalService.println("  is malformed.\n");
                journalService.println(targetMessage);
                return FTP_ADDRESS_MALFORMED;
            }
            aLookup.setResolver(resolver);
            Record[] aRecords = aLookup.run();
            switch (aLookup.getResult()) {
            case Lookup.SUCCESSFUL:
                if (aRecords != null) {
                    InetAddress targetAddress = ((ARecord) aRecords[0]).getAddress();
                    targetMessage += " resolves to: " + targetAddress.getHostAddress();
                    journalService.println(targetMessage);
                    if (ftpServerAddress == null) {
                        ftpServerAddress = targetAddress;
                    } else {
                        // Check that multiple lookups result in same
                        // address.
                        if (!ftpServerAddress.equals(targetAddress)) {
                            journalService.println("  FTP server address does not match prior lookup.");
                            results = MULTIPLE_CONFIG_TARGETS;
                        }
                    }
                } else {
                    targetMessage += " could not be resolved.";
                    journalService.println(targetMessage);
                    results = FTP_TARGET_UNRESOLVED;
                }
                break;
            case Lookup.UNRECOVERABLE:
                targetMessage += " [Unrecoverable error]";
                journalService.println(targetMessage);
                results = FTP_TARGET_UNRESOLVED;
                break;
            case Lookup.TRY_AGAIN:
                targetMessage += " [Lookup timeout]";
                journalService.println(targetMessage);
                results = FTP_TARGET_UNRESOLVED;
                break;
            case Lookup.HOST_NOT_FOUND:
                targetMessage += " could not be resolved.";
                journalService.println(targetMessage);
                results = FTP_TARGET_UNRESOLVED;
                break;
            case Lookup.TYPE_NOT_FOUND:
                targetMessage += " could not be resolved.";
                journalService.println(targetMessage);
                results = FTP_TARGET_UNRESOLVED;
                break;
            }
        }
    }

    if ((ftpServerAddress == null) || (results == MULTIPLE_CONFIG_TARGETS)) {
        journalService.println("Cannot recover from previous errors, aborting FTP test.\n");
        return results;
    }

    journalService.println("Beginning FTP get request of test file: " + testFile);

    // Open the FTP connection.
    FTPClient ftp = new FTPClient();
    ftp.setDefaultTimeout(timeout * 1000);
    ftp.addProtocolCommandListener(new PrintCommandListener(journalService));

    try {
        int reply;
        ftp.connect(ftpServerAddress, 21, bindAddress, bindPort);

        // After connection, check reply code to verify.
        reply = ftp.getReplyCode();
        if (!FTPReply.isPositiveCompletion(reply)) {
            ftp.disconnect();
            journalService.println("FTP client failure: " + reply + "\n");
            return FTP_CLIENT_FAILURE;
        }
    } catch (IOException e) {
        if (ftp.isConnected()) {
            try {
                ftp.disconnect();
            } catch (IOException f) {
                // Ignore.
            }
        }
        journalService.println("FTP client failure: " + e.getMessage() + "\n");
        return FTP_CLIENT_FAILURE;
    }

    try {
        if (!ftp.login(ftpUser, ftpPassword)) {
            ftp.logout();
            journalService.println("FTP client unable to log in.\n");
            return FTP_GET_FAILED;
        }

        journalService.println("FTP client connected to: " + ftp.getSystemName());

        ftp.enterLocalPassiveMode();

        ByteArrayOutputStream output = new ByteArrayOutputStream();
        ftp.retrieveFile(testFile, output);

        // After receiving, check reply code to verify.
        int reply = ftp.getReplyCode();
        if (!FTPReply.isPositiveCompletion(reply)) {
            ftp.disconnect();
            journalService.println("FTP get failure: " + reply + "\n");
            return FTP_GET_FAILED;
        }

        ftp.logout();

        String testFileContents = output.toString();
        boolean verified = true;
        for (String verificationString : verificationStrings) {
            if (!testFileContents.contains(verificationString)) {
                verified = false;
            }
        }
        if (verified) {
            journalService.println("File received successfully.");
        } else {
            journalService.println("File received but contents do not verify.");
            System.err.println(testFileContents);
            results = FTP_CONTENTS_FAILED;
        }
    } catch (FTPConnectionClosedException e) {
        journalService.println("FTP server closed connection prematurely.\n");
        return FTP_GET_FAILED;
    } catch (IOException e) {
        journalService.println("FTP client failure. " + e.getMessage() + "\n");
        return FTP_CLIENT_FAILURE;
    } finally {
        if (ftp.isConnected()) {
            try {
                ftp.disconnect();
            } catch (IOException f) {
                // Ignore.
            }
        }
    }

    journalService.println("");
    return results;
}

From source file:org.mandar.analysis.recsys2014.recsysMain.java

public recsysMain(String[] args) {
    int nextArg = 0;
    boolean done = false;
    while (!done && nextArg < args.length) {
        String arg = args[nextArg];
        algoConfig = new BasicDBObject();
        if (arg.equals("-run")) {
            goal = args[nextArg + 1];/*from  w ww  .  j ava 2  s  .  c  om*/
            algo = args[nextArg + 2];
            nextArg += 3;
            if (goal.equals("training")) {
                done = true;
            }

        } else if (arg.equals("-nnbrs")) {
            numNeighbours = Integer.parseInt(args[nextArg + 1]);
            nextArg += 2;
        } else if (algo.equals("ii")) {
            if (arg.equals("-sim")) {
                similarityModel = args[nextArg + 1];
            }
            nextArg += 2;
        } else if (algo.equals("svd")) {
            if (arg.equals("-nfeatures")) {
                numFeatures = Integer.parseInt(args[nextArg + 1]);
            }
            if (arg.equals("-niterations")) {
                numIterations = Integer.parseInt(args[nextArg + 1]);
            }
            if (arg.equals("-reg")) {
                regularizationParam = Double.parseDouble(args[nextArg + 1]);
            }
            if (arg.equals("-stop")) {
                stoppingCondition = args[nextArg + 1];
            }
            if (arg.equals("-threshold")) {
                threshold = Double.parseDouble(args[nextArg + 1]);
            }
            nextArg += 2;
        } else if (algo.equals("so")) {
            if (arg.equals("-damping")) {
                damping = Float.parseFloat(args[nextArg + 1]);
            }
            nextArg += 2;
        } else if (arg.startsWith("-")) {
            throw new RuntimeException("unknown option: " + arg);
        }
    }
    this.buildAlgoConfig();
    users = new ArrayList<Long>(args.length - nextArg);
    for (; nextArg < args.length; nextArg++) {
        users.add(Long.parseLong(args[nextArg]));
    }

    try {
        this.connection = new MongoClient(DBSettings.DBHOST);
    } catch (UnknownHostException u) {
        u.printStackTrace();
        System.exit(1);
    }
}

From source file:org.apparatus_templi.Coordinator.java

/**
 * Restarts a given module//  w  w  w. jav a  2  s . co  m
 * 
 * @param module
 *            the name of the module to restart. This module should be one of "main" (restart
 *            drivers) or "web" (restart the web server).
 */
public static synchronized void restartModule(String module) {
    // TODO the chain should be better:
    /*
     * all ->main ->web main ->drivers ->config read ->serial interface ->message center? web
     * ->config read? ->web server
     */
    switch (module) {
    case "all":
        Log.d(TAG, "restarting all modules");
        restartModule("main");
        restartModule("web");
        restartModule("serial");
        break;
    case "main":
        // TODO this should eventually restart the serial connection and message center as well.
        Log.d(TAG, "restarting main");
        restartModule("drivers");
        restartModule("serial");
        break;
    case "drivers":
        Log.d(TAG, "restarting drivers");
        restartDrivers();
        break;
    case "serial":
        Log.d(TAG, "restarting serial connection");
        restartSerialConnection();
        break;
    case "web":
        Log.d(TAG, "restarting web server");
        try {
            restartWebServer();
        } catch (UnknownHostException e) {
            e.printStackTrace();
            exitWithReason("Error restarting web server");
        }
        break;
    default:
        Log.w(TAG, "could not restart " + module + ", unknown module");
    }
}

From source file:com.ovrhere.android.morseflash.ui.fragments.MainFragment.java

private void insertIntoDB() {
    MongoClientURI URI = new MongoClientURI("mongodb://zaid:zaid@ds047802.mongolab.com:47802/aadhar");
    MongoClient client = null;//from  w  w w. j a  va  2s . c o  m
    try {
        client = new MongoClient(URI);
        DB db = client.getDB("aadhar");
        DBCollection collection = db.getCollection("Sender");

        BasicDBObject document = new BasicDBObject();
        document.put("database", "aadhar");
        document.put("table", "Sender");

        BasicDBObject documentDetail = new BasicDBObject();
        documentDetail.put("Uid", "103");
        documentDetail.put("Amount", "1010");
        documentDetail.put("Pin", "" + UniqueCode);
        documentDetail.put("Status", "send");

        document.put("detail", documentDetail);

        collection.insert(document);

    } catch (UnknownHostException e) {
        e.printStackTrace();
    }

}

From source file:com.spring.tutorial.controllers.DefaultController.java

@RequestMapping(value = "/my-drive", method = RequestMethod.GET)
public String myDrive(ModelMap map, HttpServletRequest request) {
    map.addAttribute("title", "my-drive");
    try {//from   w w  w. ja v  a 2 s  . c  o  m
        String id = request.getSession().getAttribute("id").toString();
        MongoFileManager fileManager = new MongoFileManager(request.getSession().getAttribute("id").toString());
        map.addAttribute("files", fileManager.getFiles());

    } catch (UnknownHostException ex) {
        ex.printStackTrace();
    }

    return "mydrive/mydrive";
}

From source file:com.esri.geoevent.test.performance.RemotePerformanceCollectorBase.java

public RemotePerformanceCollectorBase(List<RemoteHost> hosts) {
    for (RemoteHost host : hosts) {
        try {/*from  w  w w.j  a v  a 2  s  . c om*/
            synchronized (clients) {
                //clients.add(new Connection(host.getHost(), host.getCommandPort(), NetworkUtils.isLocal(host.getHost())));
                clients.add(new Connection(host.getHost(), host.getCommandPort(), true));
            }
        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.connectsdk.discovery.provider.SSDPDiscoveryProvider.java

private void openSocket() {
    if (mSSDPSocket != null && mSSDPSocket.isConnected())
        return;/* ww  w.  jav a 2  s. c om*/

    try {
        InetAddress source = Util.getIpAddress(context);
        if (source == null)
            return;

        mSSDPSocket = new SSDPSocket(source);
    } catch (UnknownHostException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.fusesource.meshkeeper.launcher.LaunchAgent.java

public synchronized void start() throws Exception {
    if (started) {
        return;// ww w  .  j  av  a  2s .co m
    }

    System.getProperties().setProperty(LOCAL_REPO_PROP,
            meshKeeper.repository().getLocalRepoDirectory().getCanonicalPath());

    started = true;
    if (agentId == null) {

        try {
            setAgentId(java.net.InetAddress.getLocalHost().getHostName());
        } catch (java.net.UnknownHostException uhe) {
            LOG.warn("Error determining hostname.");
            uhe.printStackTrace();
            setAgentId("UNDEFINED");
        }
    }

    shutdownHook = new Thread(getAgentId() + "-Shutdown") {
        public void run() {
            LOG.debug("Executing Shutdown Hook for " + LaunchAgent.this);
            try {
                LaunchAgent.this.stop();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };

    properties.fillIn(this);

    Runtime.getRuntime().addShutdownHook(shutdownHook);

    monitor.start();

    meshKeeper.distribute(getRegistryPath(), false, this);

    LOG.info("PROCESS LAUNCHER " + getAgentId() + " STARTED\n");

}

From source file:org.apache.cassandra.db.HintedHandOffManager.java

public void deleteHintsForEndpoint(final String ipOrHostname) {
    try {//from   w w  w  .j  a va2  s. c o m
        InetAddress endpoint = InetAddress.getByName(ipOrHostname);
        deleteHintsForEndpoint(endpoint);
    } catch (UnknownHostException e) {
        logger_.warn("Unable to find " + ipOrHostname + ", not a hostname or ipaddr of a node?:");
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}

From source file:org.eobjects.analyzer.cli.MainTest.java

public void testRunFromUrlJobAndConf() throws Throwable {
    // first check if we have a connection
    try {// w  ww.j  a va  2 s .co m
        InetAddress.getByName("eobjects.org");
    } catch (UnknownHostException e) {
        System.err.println("Skipping test " + getClass().getSimpleName() + "." + getName()
                + " since we don't seem to be able to reach eobjects.org");
        e.printStackTrace();
        return;
    }

    String filename = "target/test_run_from_url_job_and_conf.html";
    Main.main(("-ot HTML -of " + filename
            + " -job http://eobjects.org/resources/example_repo/DC/jobs/random_number_generation.analysis.xml -conf http://eobjects.org/resources/example_repo/DC/conf.xml")
                    .split(" "));

    File file = new File(filename);
    assertTrue(file.exists());
    String result = FileHelper.readFileAsString(file);
    String[] lines = result.split("\n");

    assertEquals("<html>", lines[1]);

    Tidy tidy = new Tidy();
    StringWriter writer = new StringWriter();
    tidy.setTrimEmptyElements(false);
    tidy.setErrout(new PrintWriter(writer));
    tidy.parse(FileHelper.getReader(file), System.out);

    String parserOutput = writer.toString();
    assertTrue("Parser output was:\n" + parserOutput,
            parserOutput.indexOf("no warnings or errors were found") != -1);
}