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:DNSLookup.java

public static void main(String args[]) {
    try {/*w w w  .j a v a2  s . c  o m*/
        InetAddress host;
        if (args.length == 0) {
            host = InetAddress.getLocalHost();
        } else {
            host = InetAddress.getByName(args[0]);
        }
        System.out.println("Host:'" + host.getHostName() + "' has address: " + host.getHostAddress());
        byte bytes[] = host.getAddress();
        int fourBytes[] = new int[bytes.length];
        for (int i = 0, n = bytes.length; i < n; i++) {
            fourBytes[i] = bytes[i] & 255;
        }
        System.out.println("\t" + fourBytes[0] + "." + fourBytes[1] + "." + fourBytes[2] + "." + fourBytes[3]);
    } catch (UnknownHostException e) {
        e.printStackTrace();
    }
}

From source file:StompMessageConsumer.java

public static void main(String[] args) throws ParseException {

    Options options = new Options();
    options.addOption("h", true, "Host to connect to");
    options.addOption("p", true, "Port to connect to");
    options.addOption("u", true, "User name");
    options.addOption("P", true, "Password");

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = parser.parse(options, args);

    String host = "192.168.1.7";
    String port = "61613";
    String user = "guest";
    String pass = "P@ssword1";

    if (cmd.hasOption("h")) {
        host = cmd.getOptionValue("h");
    }/*from ww w  .ja  v  a2s.  c  o m*/
    if (cmd.hasOption("p")) {
        port = cmd.getOptionValue("p");
    }
    if (cmd.hasOption("u")) {
        user = cmd.getOptionValue("u");
    }
    if (cmd.hasOption("P")) {
        pass = cmd.getOptionValue("P");
    }

    try {
        StompConnection connection = new StompConnection();

        connection.open(host, Integer.parseInt(port));
        connection.connect(user, pass);
        //      connection.open("orange.cloudtroopers.ro", 61613);
        //      connection.connect("system", "manager");

        connection.subscribe("jms.queue.memberRegistration", Subscribe.AckModeValues.CLIENT);
        connection.subscribe(StompMessagePublisher.MEMBER_REGISTRATION_JMS_DESTINATION,
                Subscribe.AckModeValues.CLIENT);

        connection.begin("tx2");
        StompFrame message = connection.receive();
        System.out.println(message.getBody());
        connection.ack(message, "tx2");
        connection.commit("tx2");

        connection.disconnect();
    } catch (UnknownHostException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:StompMessagePublisher.java

public static void main(String[] args) throws ParseException {

    Options options = new Options();
    options.addOption("h", true, "Host to connect to");
    options.addOption("p", true, "Port to connect to");
    options.addOption("u", true, "User name");
    options.addOption("P", true, "Password");
    options.addOption("d", true, "JMS Destination");
    options.addOption("j", true, "JSON to send");

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = parser.parse(options, args);

    // String host = "loyjbsms11-public.lolacloud.com";
    // String host = "pink.cloudtroopers.ro";
    String host = "localhost";
    // String host = "pink.cloudtroopers.ro";
    String port = "61613";
    String user = "guest";
    String pass = "P@ssword1";

    // String destination = REWARD_POINTS_JMS_DESTINATION;
    // String json = REWARD_POINTS_JSON_MERGE;

    String destination = MEMBER_REGISTRATION_JMS_DESTINATION;
    String json = MEMBER_REGISTRATION_JSON;

    if (cmd.hasOption("h")) {
        host = cmd.getOptionValue("h");
    }//from   w ww  .j a v a2  s . c o  m
    if (cmd.hasOption("p")) {
        port = cmd.getOptionValue("p");
    }
    if (cmd.hasOption("u")) {
        user = cmd.getOptionValue("u");
    }
    if (cmd.hasOption("P")) {
        pass = cmd.getOptionValue("P");
    }
    if (cmd.hasOption("d")) {
        destination = cmd.getOptionValue("d");
    }
    if (cmd.hasOption("j")) {
        json = cmd.getOptionValue("j");
    }

    try {
        StompConnection connection = new StompConnection();

        connection.open(host, Integer.parseInt(port));
        connection.connect(user, pass);

        for (int i = 0; i < 1; i++) {
            System.out.println(" msg " + i);
            String newJson = json.replaceAll("" + EXTERNAL_PROVIDER_ID, "" + (EXTERNAL_PROVIDER_ID + i));
            newJson = newJson.replaceAll("" + CUSTOMER_ACCT_ID, "" + (CUSTOMER_ACCT_ID + i));
            newJson = newJson.replaceAll("" + LOYALTY_ACCT_ID, "" + (LOYALTY_ACCT_ID + i));
            send(host, port, user, pass, destination, newJson, connection);
        }
        connection.disconnect();
        connection.close();
    } catch (UnknownHostException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:aplicacion.sistema.version.logic.JakartaFtpWrapper.java

public static void main(String[] args) {
    JakartaFtpWrapper ftp = new JakartaFtpWrapper();
    try {//  w  w  w.  j  ava  2s  .c o  m

        boolean connected = ftp.connectAndLogin("gisbertrepuestos.com.ar", "gisbertrepuestos.com.ar",
                "ipsilon@1982");
        if (connected) {
            System.out.println("BISBER REPUESTOS LOGIN");
            ftp.setPassiveMode(true);
            ftp.downloadFile("/beta/beta-patch.msp", "beta-patch.msp");
            System.out.println("Downloades files ok");

        }

    } catch (UnknownHostException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (FTPConnectionClosedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:Rpackage.MongoFixPostCode.java

public static void main(String[] args) {

    YelpAPI yelpApi = new YelpAPI();
    JSONParser parser = new JSONParser();
    try {//from   w ww .  j  a v a 2  s  .  c o m

        // Connect to mongodb
        MongoClient mongo = new MongoClient("10.33.2.142", 27017);

        // get database
        // if database doesn't exists, mongodb will create it for you
        DB db = mongo.getDB("test");

        // get collection
        // if collection doesn't exists, mongodb will create it for you
        DBCollection collection = db.getCollection("twitter_Stream");

        DBCursor cursor;
        BasicDBObject query;
        //------------------------------------
        // ( 1 ) collection.find() --> get all document

        DBObject clause1 = new BasicDBObject("Latitude", new BasicDBObject("$exists", true));
        DBObject clause2 = new BasicDBObject("tweet_Country_Code", new BasicDBObject("$exists", true));
        DBObject clause3 = new BasicDBObject("R_Post_Code", new BasicDBObject("$exists", false));
        /*{
          "$and":[
            {
              "tweet_Country_Code":{
                "$exists":true
              }
            },
            {
              "Latitude":{
                "$exists":false
              }
            },
            {
              "tweet_Country_Code":"AU"
            }
          ]
        }                
        */
        BasicDBList or = new BasicDBList();
        or.add(clause1);
        or.add(clause2);
        or.add(clause3);
        query = new BasicDBObject("$and", or);

        //{  "$and":[    {      "Latitude":{        "$exists":true      }    },    {      "R_Post_Code":{        "$exists":false      }    }  ]}            
        cursor = collection.find(query).addOption(Bytes.QUERYOPTION_NOTIMEOUT) //
                .addOption(Bytes.QUERYOPTION_AWAITDATA);

        System.out.println("( 1 ) .get the user id within  latitide");
        System.out.println("results --> " + cursor.count());
        FoursquareAPI_backup qui4squreApi = new FoursquareAPI_backup();
        try {
            while (cursor.hasNext()) {
                DBObject data = cursor.next();
                String v_user_Name = (String) data.get("user_name");
                Long v_twitte_id = (Long) data.get("tweet_ID");
                String v_twitte_text = (String) data.get("tweet_text");
                Long v_user_Id = (Long) data.get("user_Id");
                Double v_Latitude = (Double) data.get("Latitude");
                Double v_Longtitude = (Double) data.get("Longitude");
                String v_tweet_Place_Name = (String) data.get("tweet_Place_Name");
                String v_tweet_Country_Code = (String) data.get("tweet_Country_Code");

                if (v_user_Id == null) {
                    /*                        System.out.print("update:" +v_user_Name+"/status/"+ v_twitte_id);
                     try{
                     Status status = twitter.showStatus(v_twitte_id);
                     BasicDBObject jo = GetMongoRecord(status);
                     System.out.println( "-->" + status.getId() + " : " + jo.getString("Re_user_screenName") + ":" + jo.getString("tweet_text"));
                     collection.update(new BasicDBObject("tweet_ID", v_twitte_id), jo); // set the document in the DB to the new document for Jo                     
                     }catch (TwitterException ex){
                     if (ex.getStatusCode()==144) continue;
                     }
                     */
                    continue;
                }
                JSONObject businesses = yelpApi.search4Yelp("city", v_Latitude, v_Longtitude);//-27.497835,153.017472);                      
                boolean searchAgain = false;

                if (businesses == null)
                    searchAgain = true;
                else if (businesses.size() < 1)
                    searchAgain = true;

                if (searchAgain) {
                    System.out.println("La:" + v_Latitude + "\tLo:" + v_Longtitude);
                    businesses = qui4squreApi.search4Square("city", v_Latitude, v_Longtitude);
                    searchAgain = false;
                }
                if (businesses == null)
                    searchAgain = true;
                else if (businesses.size() < 1)
                    searchAgain = true;

                if (searchAgain) {
                    businesses = qui4squreApi.searchGoogleMap("city", v_Latitude, v_Longtitude);
                    if (businesses == null) {
                        System.out.println("\t" + v_tweet_Country_Code + "\t:" + v_tweet_Place_Name);
                        continue;
                    } else if (businesses.size() < 1) {
                        System.out.println("\t" + v_tweet_Country_Code + "\t:" + v_tweet_Place_Name);
                        continue;
                    }
                }

                String country_code = (String) businesses.get("country_code");
                String city_code = (String) businesses.get("city_name");
                String state_code = (String) businesses.get("state_code");
                String post_code = (String) businesses.get("post_code");

                BasicDBObject setNewFieldQuery = new BasicDBObject().append("$set",
                        new BasicDBObject().append("R_Country_Code", country_code)
                                .append("R_State_Code", state_code).append("R_City", city_code)
                                .append("R_Post_Code", post_code));

                collection.update(new BasicDBObject().append("tweet_ID", v_twitte_id), setNewFieldQuery); // set the document in the DB to the new document for Jo                                             

                setNewFieldQuery.clear();
                setNewFieldQuery = null;
            }
        } finally {
            cursor.close();
        }

        System.out.println("---------------------------------");

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

}

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

public static void main(String[] args) throws Exception {
    try {//ww  w  .  j  ava2s.co  m
        if (args.length == 0) {
            System.out.println("first param should be config file");
            System.exit(-1);
        }
        XMLConfiguration c = null;
        try {
            c = new XMLConfiguration(args[0]);
        } catch (ConfigurationException cex) {
            System.err.println("Configuration error, check config file");
            cex.printStackTrace();
            System.exit(1);
        }

        IRCCat bot = new IRCCat(c);

        // listen for stuff and send it to irc:
        ServerSocket serverSocket = null;
        InetAddress inet = null;
        try {
            if (bot.getCatIP() != null)
                inet = InetAddress.getByName(bot.getCatIP());
        } catch (UnknownHostException ex) {
            System.out.println("Could not resolve config cat.ip, fix your config");
            ex.printStackTrace();
            System.exit(2);
        }

        try {
            serverSocket = new ServerSocket(bot.getCatPort(), 0, inet);
        } catch (IOException e) {
            System.err.println("Could not listen on port: " + bot.getCatPort());
            System.exit(1);
        }

        System.out.println("Listening on " + bot.getCatIP() + " : " + bot.getCatPort());

        while (true) {
            try {
                Socket clientSocket = serverSocket.accept();
                // System.out.println("Connection on catport from: "
                // + clientSocket.getInetAddress().toString());
                CatHandler handler = new CatHandler(clientSocket, bot);
                handler.start();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

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

}

From source file:com.ls.zencat.ZenCat.java

public static void main(String[] args) throws Exception {
    try {//from  ww  w.ja v  a2  s  . c  o  m
        if (args.length == 0) {
            System.out.println("first param should be config file");
            System.exit(-1);
        }
        XMLConfiguration c = null;
        try {
            c = new XMLConfiguration(args[0]);
        } catch (ConfigurationException cex) {
            System.err.println("Configuration error, check config file");
            cex.printStackTrace();
            System.exit(1);
        }

        ZenCat bot = new ZenCat(c);

        // listen for stuff and send it to irc:
        ServerSocket serverSocket = null;
        InetAddress inet = null;
        try {
            if (bot.getCatIP() != null)
                inet = InetAddress.getByName(bot.getCatIP());
        } catch (UnknownHostException ex) {
            System.out.println("Could not resolve config cat.ip, fix your config");
            ex.printStackTrace();
            System.exit(2);
        }

        try {
            serverSocket = new ServerSocket(bot.getCatPort(), 0, inet);
        } catch (IOException e) {
            System.err.println("Could not listen on port: " + bot.getCatPort());
            System.exit(1);
        }

        System.out.println("Listening on " + bot.getCatIP() + " : " + bot.getCatPort());

        while (true) {
            try {
                Socket clientSocket = serverSocket.accept();
                // System.out.println("Connection on catport from: "
                // + clientSocket.getInetAddress().toString());
                CatHandler handler = new CatHandler(clientSocket, bot);
                handler.start();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

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

}

From source file:serverpaxos.ServerPaxos.java

/**
 * @param args the command line arguments
 *//* w  ww  .j  a  v a  2  s .c  o  m*/
public static void main(String[] args) throws IOException, InterruptedException, Exception {

    String ip;
    String hostname;
    Scanner scan = null;
    try {
        ip = InetAddress.getLocalHost().getHostAddress();
        System.out.println("Server IP address : " + ip);
        System.out.println("Port : 5000");
    } catch (UnknownHostException e) {
        e.printStackTrace();
    }
    server = new ServerSocket(5000);
    while (true) {
        Socket socket = server.accept();
        System.out.println("Connected");
        ClientController clientcontroller = new ClientController(socket);

        Thread t = new Thread(clientcontroller);
        t.start();

        Thread t2 = new Thread(new StringGetter(socket));
        t2.start();
    }

    // TODO code application logic here
}

From source file:org.cosmo.common.util.Util.java

public static void main(String[] args) {
    try {/*w  ww.  ja  va  2 s  . c  om*/
        //InetAddress address = InetAddress.getLocalHost();
        InetAddress address = InetAddress.getByName("192.168.46.53");

        /*
         * Get NetworkInterface for the current host and then read the
         * hardware address.
         */
        NetworkInterface ni = NetworkInterface.getByInetAddress(address);
        if (ni != null) {
            byte[] mac = ni.getHardwareAddress();
            if (mac != null) {
                /*
                 * Extract each array of mac address and convert it to hexa with the
                 * following format 08-00-27-DC-4A-9E.
                 */
                for (int i = 0; i < mac.length; i++) {
                    System.out.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : "");
                }
            } else {
                System.out.println("Address doesn't exist or is not accessible.");
            }
        } else {
            System.out.println("Network Interface for the specified address is not found.");
        }
    } catch (UnknownHostException e) {
        e.printStackTrace();
    } catch (SocketException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static String getServiceIp(String host) {
    InetAddress myServer = null;/*from  w  w  w  .  j a va 2  s .co m*/
    try {
        myServer = InetAddress.getByName(host);
    } catch (UnknownHostException e) {
        e.printStackTrace();
    }
    if (myServer == null) {
        return "0";
    }
    return myServer.getHostAddress();
}