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:com.dc.tes.License.java

private static String LicenseServerConnect(Message request) {
    String license = "";
    Socket client = null;//  www.  ja v a 2 s  .  c  om
    try {
        client = new Socket(LICENSE_SERVER_IP, LICENSE_SERVER_PORT);
    } catch (UnknownHostException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        license = "Lisence?";
        log.error(license);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        license = "Lisence?";
        log.error(license);
    }

    try {
        client.getOutputStream().write(request.Export());
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        license = "?Lisence??";
        log.error(license);
    }
    Message response = null;
    try {
        response = new Message(client.getInputStream());
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        license = "?Lisence??";
        log.error(license);
    }
    if (response.getInteger(MessageItem.LICENSE.AVAILABLE) == 0) {
        license = "License???"
                + response.getString(MessageItem.LICENSE.MSG);
        log.error(license);
    }
    if (request.getInteger(MessageItem.LICENSE.SIGN) == 0) {
        license = response.getString(MessageItem.LICENSE.LICENSEFILE);
    }
    return license;
}

From source file:hobby.wei.c.phone.Network.java

public static String IP_Host(String host, boolean format) {
    try {// www . j ava 2s  .c o m
        String ip = InetAddress.getByName(host).getHostAddress();
        return format ? ip.replace('.', '_') : ip;
    } catch (UnknownHostException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.apache.zeppelin.rest.AbstractTestRestApi.java

private static String getHostname() {
    try {/* w w w .ja v  a2s.c o  m*/
        return InetAddress.getLocalHost().getHostName();
    } catch (UnknownHostException e) {
        e.printStackTrace();
        return "localhost";
    }
}

From source file:zz.pseas.ghost.utils.HttpClinetUtil.java

/**
 * @author GS//from  www .j  a  v a2  s.c om
 * @param url
 * @param para
 * @param cookie
 * @return
 * @throws IOException
 */
public static String get(String url, String cookie) throws IOException {
    String responseBody = null;
    GetMethod getMethod = new GetMethod(url);
    getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler()); // ????
    if (!cookie.equals("")) {
        getMethod.setRequestHeader("cookie", cookie);
    }
    try {
        int statusCode = hc.executeMethod(getMethod);
        if (statusCode != HttpStatus.SC_OK) {
            LOG.error("Method failed: " + getMethod.getStatusLine());
        }
        responseBody = getMethod.getResponseBodyAsString();
    } catch (UnknownHostException e) {
        e.printStackTrace();
        LOG.error("??" + e.getMessage());
    } catch (HttpException e) { // ?
        e.printStackTrace();
        LOG.error("?" + e.getMessage());
    } catch (IOException e) { // ?
        e.printStackTrace();
        LOG.error("?" + e.getMessage());
    } finally {
        getMethod.releaseConnection(); // 
    }
    return responseBody;
}

From source file:zz.pseas.ghost.utils.HttpClinetUtil.java

/**
 * @author GS//w  w w.  j  a v a  2s.  c om
 * @param url
 * @param para
 *            Post??
 * @return
 * @throws IOException
 */
public static String post(String url, Map<String, String> para) throws IOException {
    String responseBody = null;
    PostMethod postMethod = new PostMethod(url);
    NameValuePair[] data = new NameValuePair[para.size()];
    int index = 0;
    for (String s : para.keySet()) {
        data[index++] = new NameValuePair(s, para.get(s));
    }
    postMethod.setRequestBody(data); // ?
    try {
        int statusCode = hc.executeMethod(postMethod);
        if (statusCode != HttpStatus.SC_OK) {
            LOG.error("Method failed: " + postMethod.getStatusLine());
        }
        responseBody = postMethod.getResponseBodyAsString();
    } catch (UnknownHostException e) {
        e.printStackTrace();
        LOG.error("??" + e.getMessage());
    } catch (HttpException e) {
        e.printStackTrace();
        LOG.error(e.getMessage());
    } catch (IOException e) {
        e.printStackTrace();
        LOG.error(e.getMessage());
    } finally {
        postMethod.releaseConnection(); // 
    }
    return responseBody;
}

From source file:zz.pseas.ghost.utils.HttpClinetUtil.java

/**
 * @author GS//from  ww w .j  a va2s . c o  m
 * @param url
 * @param para
 * @param cookie
 * @return
 * @throws IOException
 */
public static String get(String url, Map<String, String> para, String cookie) throws IOException {
    String responseBody = null;
    GetMethod getMethod = new GetMethod(url);
    getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler()); // ????
    NameValuePair[] data = new NameValuePair[para.size()];
    int index = 0;
    for (String s : para.keySet()) {
        data[index++] = new NameValuePair(s, para.get(s)); // ??
    }
    getMethod.setQueryString(data); // ?
    if (!cookie.equals("")) {
        getMethod.setRequestHeader("cookie", cookie);
    }
    try {
        int statusCode = hc.executeMethod(getMethod);
        if (statusCode != HttpStatus.SC_OK) {
            LOG.error("Method failed: " + getMethod.getStatusLine());
        }
        responseBody = getMethod.getResponseBodyAsString();
    } catch (UnknownHostException e) {
        e.printStackTrace();
        LOG.error("??" + e.getMessage());
    } catch (HttpException e) { // ?
        e.printStackTrace();
        LOG.error("?" + e.getMessage());
    } catch (IOException e) { // ?
        e.printStackTrace();
        LOG.error("?" + e.getMessage());
    } finally {
        getMethod.releaseConnection(); // 
    }
    return responseBody;
}

From source file:org.basdroid.common.NetworkUtils.java

public static String getApIpAddr(Context context) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    DhcpInfo dhcpInfo = wifiManager.getDhcpInfo();
    byte[] ipAddress = convert2Bytes(dhcpInfo.serverAddress);
    try {/*from w  w  w. j a  v a2  s  .  com*/
        String apIpAddr = InetAddress.getByAddress(ipAddress).getHostAddress();
        return apIpAddr;
    } catch (UnknownHostException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:it.wami.map.mongodeploy.OsmToMongoDB.java

/**
 * //from   w  w w  .  jav a2 s  .  c  om
 * @param host
 * @param port
 * @param mco 
 * @return
 */
private static MongoClient createMongo(String host, int port, MongoClientOptions mco) {
    MongoClient mongo = null;
    try {
        mongo = new MongoClient(new ServerAddress(host, port), mco);
        System.out.println(mongo.getConnectPoint());
    } catch (UnknownHostException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return mongo;
}

From source file:net.itransformers.idiscover.discoveryhelpers.xml.SnmpForXslt.java

public static String getSubnetFromPrefix(String prefix) {
    try {/*  ww w.j  a  v a  2 s  .  c o  m*/
        cidrUtils = new CIDRUtils(prefix);
        return cidrUtils.getNetworkAddress();
    } catch (UnknownHostException e) {
        e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
    }
    return null;

}

From source file:net.itransformers.idiscover.discoveryhelpers.xml.SnmpForXslt.java

public static String getBroadCastFromPrefix(String prefix) {

    try {//w w  w .  ja  va  2 s .c  o m
        CIDRUtils cidrUtils = new CIDRUtils(prefix);
        return cidrUtils.getBroadcastAddress();
    } catch (UnknownHostException e) {
        e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
    }
    return null;

}