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:edu.umass.cs.reconfiguration.SQLReconfiguratorDB.java

private static void testDemandProfileUpdate(String name, SQLReconfiguratorDB<Integer> rcDB) {
    AbstractDemandProfile demandProfile = new DemandProfile(name);
    int numRequests = 20;
    // fake random request demand
    for (int i = 0; i < numRequests; i++) {
        try {//from ww w. j  a  v  a2s . com
            demandProfile.register(getRandomInterfaceRequest(name), getRandomIPAddress(), null);
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }
    DemandReport<Integer> demandReport = new DemandReport<Integer>((int) Math.random() * 100, name, 0,
            demandProfile);
    // insert demand profile
    rcDB.updateDemandStats(demandReport);
}

From source file:org.deviceconnect.android.deviceplugin.irkit.IRKitManager.java

/**
 * WiFi?IP??./*from   w ww . jav  a2 s .c o  m*/
 * 
 * @param ipValue IP?int
 * @return InetAddress?????null?
 */
private InetAddress parseIPAddress(final int ipValue) {
    byte[] byteaddr = new byte[] { (byte) (ipValue & 0xff), (byte) (ipValue >> 8 & 0xff),
            (byte) (ipValue >> 16 & 0xff), (byte) (ipValue >> 24 & 0xff) };
    try {
        return InetAddress.getByAddress(byteaddr);
    } catch (UnknownHostException e) {
        if (BuildConfig.DEBUG) {
            e.printStackTrace();
        }
        // IP?????????????
        return null;
    }
}

From source file:com.connectsdk.service.DLNAService.java

public void subscribeServices() {
    Util.runInBackground(new Runnable() {

        @Override/*from w ww . j a  va  2  s  .com*/
        public void run() {
            String myIpAddress = null;
            try {
                myIpAddress = Util.getIpAddress(context).getHostAddress();
            } catch (UnknownHostException e) {
                e.printStackTrace();
            }

            List<Service> serviceList = serviceDescription.getServiceList();

            if (serviceList != null) {
                for (int i = 0; i < serviceList.size(); i++) {
                    String eventSubURL = makeControlURL("/", serviceList.get(i).eventSubURL);
                    if (eventSubURL == null) {
                        continue;
                    }

                    try {
                        HttpConnection connection = HttpConnection
                                .newSubscriptionInstance(new URI("http", "", serviceDescription.getIpAddress(),
                                        serviceDescription.getPort(), eventSubURL, "", ""));
                        connection.setMethod(HttpConnection.Method.SUBSCRIBE);
                        connection.setHeader("CALLBACK",
                                "<http://" + myIpAddress + ":" + httpServer.getPort() + eventSubURL + ">");
                        connection.setHeader("NT", "upnp:event");
                        connection.setHeader("TIMEOUT", "Second-" + TIMEOUT);
                        connection.setHeader("Connection", "close");
                        connection.setHeader("Content-length", "0");
                        connection.setHeader("USER-AGENT", "Android UPnp/1.1 ConnectSDK");
                        connection.execute();
                        if (connection.getResponseCode() == 200) {
                            SIDList.put(serviceList.get(i).serviceType, connection.getResponseHeader("SID"));
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                }
            }
        }
    });

    resubscribeServices();
}

From source file:org.lnicholls.galleon.server.Server.java

private void printServerProperties() {
    try {/*w  w w  .  j  av a2 s . c  o m*/
        InetAddress inetAddress = InetAddress.getLocalHost();

        log.info("Galleon Version=" + getVersion());
        log.info("Local IP=" + Tools.getLocalIpAddress());
        log.info("Host=" + inetAddress.getHostName());

        Tools.logMemory();
    } catch (UnknownHostException ex) {
        Tools.logException(Server.class, ex);
    } catch (Throwable ex) {
        ex.printStackTrace();
    }
}

From source file:it.isislab.dmason.util.SystemManagement.Worker.Updater.java

public static void uploadLog(UpdateData up, String updateDir, boolean isBatch) {
    String hostname = "";
    String jvmName = "";
    String balanceLog = "Balance";
    String workerLog = "workerStep";
    String paramsFile = "params.conf";
    logPath = "Logs/workers/";

    if (up.getFTPAddress() == null)
        return;/*from  w  w  w  . java  2s.co m*/

    FTPIP = up.getFTPAddress().getIPaddress();
    FTPPORT = up.getFTPAddress().getPort();

    System.out.println("FPT: " + FTPIP + "PORT: " + FTPPORT);
    FTPClient client = connect(FTPIP, Integer.parseInt(FTPPORT));

    login(client);

    try {
        InetAddress addr = InetAddress.getLocalHost();

        // Get IP Address
        //byte[] ipAddr = addr.getAddress();

        // Get hostname
        hostname = addr.getHostName();
    } catch (UnknownHostException e) {
    }

    RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean();

    //
    // Get name representing the running Java virtual machine.
    // It returns something like 6460@AURORA. Where the value
    // before the @ symbol is the PID.
    //
    jvmName = bean.getName();

    /*try {
       client.createDirectory(dateFormat.format(date)+"@"+hostname);
    } catch (IllegalStateException e1) {
       // TODO Auto-generated catch block
       e1.printStackTrace();
    } catch (IOException e1) {
       // TODO Auto-generated catch block
       e1.printStackTrace();
    } catch (FTPIllegalReplyException e1) {
       // TODO Auto-generated catch block
       e1.printStackTrace();
    } catch (FTPException e1) {
       isDirExists = true;
    }*/

    try {

        if (client == null)
            return;

        client.changeDirectory(updateDir);

        File blog = new File(logPath + balanceLog + jvmName + ".log");
        if (blog.exists())
            client.upload(blog);
        else
            System.out.println("File not found");

        File wlog = new File(logPath + workerLog + jvmName + ".log");
        if (wlog.exists())
            client.upload(wlog);
        else
            System.out.println("File not found");

        File params = new File(logPath + paramsFile);
        if (params.exists())
            client.upload(params);
        else
            System.out.println("File not found");

        ArrayList<File> fileToBackup = new ArrayList<File>();
        fileToBackup.add(params);
        fileToBackup.add(blog);
        fileToBackup.add(wlog);

        backupLog(updateDir, fileToBackup);
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (FTPIllegalReplyException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (FTPException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (FTPDataTransferException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (FTPAbortedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:org.archive.crawler.fetcher.OptimizeFetchHTTP.java

private void setLocalIP(HttpClient http) {
    String localIP = IPSwitcher.getLocalIP();
    if (localIP != null) {
        try {//w  w w .ja  v a 2s  . c  o  m
            http.getHostConfiguration().setLocalAddress(InetAddress.getByName(localIP));
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.mobiperf.measurements.RRCTask.java

/**
 * The "times" are the inter-packet intervals at which to run the test. Ideally these should be
 * based on the model constructed by the server, a default assumed value is used in their absence.
 * //from w w w .j  av  a 2  s .  c  o  m
 * <ol>
 * <li> Send a packet to initiate the RRC state desired. </li>
 * <li>Create a randomly generated host name (to ensure that the host name is not cached). I 
 * found on some devices that even when you clear the cache manually, the data remains in 
 * the cache.</li>
 * <li> Time how long it took to look it up.</li> 
 * <li> Count the total packets sent, globally on the phone. If more packets were sent than </li>
 * expected,  abort and try again. </li> 
 * <li> Otherwise, save the data for that test and move to the next inter-packet interval.</li>
 * </ol>
 * 
 * Test is similar to the approach taken in DnsLookUpTask.java.
 * 
 * @param times List of inter-packet intervals, in half-second increments, at which to run the 
 * test
 * @param desc Stores parameters for the RRC inference tests in general
 * @throws MeasurementError
 */

public void runDnsTest(final Integer[] times, RRCDesc desc) throws MeasurementError {
    Logger.d("Active inference DNS test: about to begin");
    if (times.length != desc.dnsTest.length) {
        desc.dnsTest = new int[times.length];
    }
    long dataConsumedThisTask = 0;

    long startTime = 0;
    long endTime = 0;

    // For each inter-packet interval...
    for (int i = 0; i < times.length; i++) {
        // On a failure, try again until a threshold is reached.
        for (int j = 0; j < desc.GIVEUP_THRESHHOLD; j++) {

            // Sometimes the network can change in the middle of a test
            checkIfWifi();
            if (stop) {
                return;
            }

            /*
             * We keep track of the packets sent at the beginning and end of the test so we can detect
             * if there is competing traffic anywhere on the phone.
             */

            PacketMonitor packetMonitor = new PacketMonitor();

            // Initiate the desired RRC state by sending a large enough packet
            // to go to DCH and waiting for the specified amount of time
            try {
                InetAddress serverAddr;
                serverAddr = InetAddress.getByName(desc.echoHost);
                sendPacket(serverAddr, desc.MAX, desc);
                waitTime(times[i] * desc.GRANULARITY, true);
            } catch (InterruptedException e1) {
                e1.printStackTrace();
                continue;
            } catch (UnknownHostException e) {
                e.printStackTrace();
                continue;
            } catch (IOException e) {
                e.printStackTrace();
                continue;
            }

            // Create a random URL, to avoid the caching problem
            UUID uuid = UUID.randomUUID();
            String host = uuid.toString() + ".com";
            // Start measuring the time to complete the task
            startTime = System.currentTimeMillis();
            try {
                @SuppressWarnings("unused")
                InetAddress serverAddr = InetAddress.getByName(host);
            } catch (UnknownHostException e) {
                // we do this on purpose! Since it's a fake URL the lookup will fail
            }
            dataConsumedThisTask += DnsLookupTask.AVG_DATA_USAGE_BYTE;
            // When we fail to find the URL, we stop timing
            endTime = System.currentTimeMillis();

            // Check how many packets were sent again. If the expected number
            // of packets were sent, we can finish and go to the next task.
            // Otherwise, we have to try again.
            if (!packetMonitor.isTrafficInterfering(5, 5)) {
                break;
            }

            startTime = 0;
            endTime = 0;
        }

        // If we broke out of the try-again loop, the last set of results are
        // valid and we can save them.
        long rtt = endTime - startTime;
        try {
            desc.setDns(i, (int) rtt);
        } catch (MeasurementError e) {
            e.printStackTrace();
        }
        Logger.d("Time for DNS" + rtt);
    }
    incrementData(dataConsumedThisTask);
}

From source file:com.mobiperf.measurements.RRCTask.java

/**
 * Determines the packet size dependence of the RRC task.
 * /*w  w w.  j a v  a2  s.  c om*/
 * Given a specified list of inter-packet intervals, perform the RRC inference measurement for
 * packets of sizes incremented by the size granularity specified.
 * 
 * @param times  Inter-packet intervals to test
 * @param desc Parameters for the RRC inference task
 * @param data Stores results of the RRC inference task
 * @param testId A unique ID identifying this set of tests
 */
private void runSizeThresholdTest(final Integer[] times, RRCDesc desc, RRCTestData data, long testId) {

    InetAddress serverAddr;
    try {
        serverAddr = InetAddress.getByName(desc.echoHost);
    } catch (UnknownHostException e) {
        Logger.e("Invalid or unreachable echo host. Test aborted.");
        e.printStackTrace();
        return;
    }
    for (int i = 0; i < times.length; i++) {
        for (int j = desc.sizeGranularity; j <= 1024; j += desc.sizeGranularity) {
            try {
                long result = inferDemotionPacketSize(serverAddr, times[i], desc, j);
                data.setRrcSizeTestData(times[i], j, result, testId);
            } catch (IOException e) {
                e.printStackTrace();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (MeasurementError e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:com.vendsy.bartsy.venue.BartsyApplication.java

public void printOrders(ArrayList<Order> addedOrders) {

    String ip = Utilities.loadPref(this, R.string.config_printer_ip, null);

    if (ip == null) {
        Log.e(TAG, "Printer IP address not configured");
        return;/*from  ww w  . j  a v a2  s  .co  m*/
    }

    try {
        for (Order order : addedOrders) {
            Socket sock = new Socket(ip, 9100);
            PrintWriter oStream = new PrintWriter(sock.getOutputStream());
            order.println(oStream);
            oStream.print("\n\n\n");
            oStream.close();
            sock.close();
        }
    } catch (UnknownHostException e) {
        e.printStackTrace();
        Log.e(TAG, "Unknown host");
    } catch (IOException e) {
        e.printStackTrace();
        Log.e(TAG, "I/O error");
    }
}

From source file:com.mobiperf.measurements.RRCTask.java

/**
 * Due to problems with how we detect interfering traffic, this test does not always work and
 * results should be treated with caution. I am keeping this test around, though, as we can still 
 * get data on how much HTTP handshakes vary in how long they take.
 * //w w  w  .  j a  v  a  2s .c om
 * The "times" are the inter-packet intervals at which to run the test. Ideally these should be
 * based on the model constructed by the server, a default assumed value is used in their absence.
 * 
 * Based on the time it takes to load a response from the page.
 * 
 * This test is not currently as accurate as the other tests, for reasons described below, and has
 * thus been disabled.
 * 
 * @param times List of inter-packet intervals, in half-second increments, at which to run the 
 * tests
 * @param desc Stores parameters for the RRC inference tests in general
 */
private void runHTTPTest(final Integer[] times, RRCDesc desc) {
    /*
     * Length of time it takes to request and read in a page.
     */

    Logger.d("Active inference HTTP test: about to begin");
    if (times.length != desc.httpTest.length) {
        desc.httpTest = new int[times.length];
    }
    long startTime = 0;
    long endTime = 0;

    try {
        for (int i = 0; i < times.length; i++) {
            // We try until we reach a threshhold or until there is no
            // competing traffic.
            for (int j = 0; j < desc.GIVEUP_THRESHHOLD; j++) {
                // Sometimes the network can change in the middle of a test
                checkIfWifi();
                if (stop) {
                    return;
                }

                /*
                 * We keep track of the packets sent at the beginning and end of the test so we can detect
                 * if there is competing traffic anywhere on the phone.
                 */
                PacketMonitor packetMonitor;

                /*
                 * We also keep track of the data consumed in order to remain within
                 * the data limit
                 */
                PacketMonitor datamonitor = new PacketMonitor();
                datamonitor.setBySize();
                datamonitor.readCurrentPacketValues();

                // Initiate the desired RRC state by sending a large enough packet
                // to go to DCH and waiting for the specified amount of time
                try {
                    // Wait for 1 second. Give time for any extraneous data sending to complete
                    waitTime(1, false);
                    InetAddress serverAddr;
                    serverAddr = InetAddress.getByName(desc.echoHost);
                    sendPacket(serverAddr, desc.MAX, desc);
                    packetMonitor = new PacketMonitor();

                    waitTime(times[i] * desc.GRANULARITY, true);

                } catch (InterruptedException e1) {
                    e1.printStackTrace();
                    continue;
                } catch (UnknownHostException e) {
                    e.printStackTrace();
                    continue;
                } catch (IOException e) {
                    e.printStackTrace();
                    continue;
                }
                startTime = System.currentTimeMillis();

                // Somewhat approximte: we can pick up packets sent by our request.
                // Our request seems to never send more than 24 packets when there is no interference.
                boolean success = !packetMonitor.isTrafficInterfering(3, 70);
                HttpClient client = new DefaultHttpClient();
                HttpGet request = new HttpGet();

                request.setURI(new URI("http://" + desc.target + "?dummy=" + i + "" + j));

                HttpResponse response = client.execute(request);
                endTime = System.currentTimeMillis();

                BufferedReader in = null;
                in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
                StringBuffer sb = new StringBuffer("");
                String line = "";

                while ((line = in.readLine()) != null) {
                    sb.append(line + "\n");
                }
                in.close();

                // This may overestimate the data consumed, but there's no good way
                // to tell what was us and what was another app
                data_consumed += datamonitor.getPacketsSentDiff();

                if (success) {
                    break;
                }
                startTime = 0;
                endTime = 0;

            }

            long rtt = endTime - startTime;
            try {
                desc.setHttp(i, (int) rtt);
            } catch (MeasurementError e) {
                e.printStackTrace();
            }
            Logger.d("Time for Http" + rtt);
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
}