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:info.sugoiapps.xoclient.XOverClient.java

/**
 * Get the internal IP address of the client machine.
 * @return the address/*  w w w. j a va2s .c o  m*/
 */
private static String getLocalAddress() {
    InetAddress addr;
    try {
        addr = InetAddress.getLocalHost();
    } catch (UnknownHostException e) {
        e.printStackTrace();
        return "No address found";
    }
    return addr.getHostAddress();
}

From source file:com.predic8.membrane.core.interceptor.acl.Hostname.java

private static InetAddress initV4() {
    try {/* w  ww  .j av a  2  s.com*/
        //this should probably never fail... unless no network available.
        return InetAddress.getByName("127.0.0.1");
    } catch (UnknownHostException e) {
        e.printStackTrace(); //if you must... maybe logging framework is not set up yet.
        log.error("Failed resolving localhost IPv4 127.0.0.1!");
        return null;
    }
}

From source file:com.predic8.membrane.core.interceptor.acl.Hostname.java

private static InetAddress initV6() {
    try {/*from  w w w.  ja va 2  s .c o m*/
        //could this fail if the machine has no IPv6 support?
        return InetAddress.getByName("0:0:0:0:0:0:0:1");
    } catch (UnknownHostException e) {
        e.printStackTrace(); //if you must... maybe logging framework is not set up yet.
        log.error("Failed resolving localhost IPv6 0:0:0:0:0:0:0:1!");
        return null;
    }
}

From source file:com.ibm.watson.movieapp.dialog.fvt.config.SetupMethod.java

/**
 * serverUnderTest() - Check to see if automation is being run via Maven
 * @return - String containing baseURL to use for testing
 *///from   w  w  w. j  a va 2s .co m
public static String serverUnderTest() {

    String ipAddress = "";
    String baseURL = "";

    String server = System.getProperty("app.url");

    if (server == null) {
        baseURL = Utils.readConfigProperty("serverUnderTest");
    } else {
        InetAddress localMachine = null;
        try {
            localMachine = InetAddress.getLocalHost();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        ipAddress = localMachine.getHostAddress();
        baseURL = server.replace("localhost", ipAddress);
    }

    return baseURL;
}

From source file:Main.java

public static String getDhcpIpString(Context mContext) {
    WifiManager mWifiManager;//w  w  w  .j av  a  2  s  .  c o m
    String broadcastIp = null;
    mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
    if (mWifiManager.isWifiEnabled()) {
        DhcpInfo myDhcpInfo = mWifiManager.getDhcpInfo();
        if (myDhcpInfo == null) {
            Toast.makeText(mContext, "can not get dhcp info", Toast.LENGTH_SHORT).show();
            return null;
        } else {
            try {
                broadcastIp = getBroadcastAddress(myDhcpInfo).getHostAddress();
            } catch (UnknownHostException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                return null;
            }
        }
        return broadcastIp;
    }
    return null;
}

From source file:org.apache.metron.helpers.topology.ErrorUtils.java

@SuppressWarnings("unchecked")
public static JSONObject generateErrorMessage(String message, Throwable t) {
    JSONObject error_message = new JSONObject();

    /*/*w  ww . java2 s .  c o  m*/
     * Save full stack trace in object.
     */
    String stackTrace = ExceptionUtils.getStackTrace(t);

    String exception = t.toString();

    error_message.put("time", System.currentTimeMillis());
    try {
        error_message.put("hostname", InetAddress.getLocalHost().getHostName());
    } catch (UnknownHostException ex) {
        // TODO Auto-generated catch block
        ex.printStackTrace();
    }

    error_message.put("message", message);
    error_message.put(Constants.SOURCE_TYPE, "error");
    error_message.put("exception", exception);
    error_message.put("stack", stackTrace);

    return error_message;
}

From source file:net.dfs.server.main.ServerServicesStarter.java

public static String serverName() {
    String name = null;//www.  ja  va  2s. c  o m
    try {
        name = InetAddress.getLocalHost().getHostName();
    } catch (UnknownHostException e) {
        e.printStackTrace();
    }
    return name;
}

From source file:net.librec.util.Systems.java

/**
 * Get IP of the System.//from w  w w  .  j  a v a  2s .c o  m
 *
 * @return IP of the System
 */
public static String getIP() {
    InetAddress ip = null;
    try {
        ip = InetAddress.getLocalHost();
    } catch (UnknownHostException e) {
        e.printStackTrace();
    }
    return ip.getHostName() + "@" + ip.getHostAddress();
}

From source file:com.vip.saturn.job.utils.LocalHostService.java

/**
 * ?Host??./*from  www .  j  a  va2 s .com*/
 * 
 * @return Host??
 */
public static String getHostName() {
    if (!Strings.isNullOrEmpty(cachedHostName)) {
        return cachedHostName;
    } else {
        try {
            cachedHostName = InetAddress.getLocalHost().getHostName();
        } catch (UnknownHostException e) {//NOSONAR
            e.printStackTrace();//NOSONAR
            return ERROR_HOSTNAME;
        }
        return cachedHostName;
    }
}

From source file:com.zq.fin.seckill.web.BaseController.java

 /**
 * ??ip//from ww w . ja va  2 s. c om
 * @param request
 * @return
 */
public static String getIpAddr(HttpServletRequest request){
      
   String ipAddress = request.getHeader("x-forwarded-for");
   if(ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
      ipAddress = request.getHeader("Proxy-Client-IP");
   }
   if(ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
      ipAddress = request.getHeader("WL-Proxy-Client-IP");
   }
   if(ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
      ipAddress = request.getRemoteAddr();
      if(ipAddress.equals("127.0.0.1") || ipAddress.equals("0:0:0:0:0:0:0:1")){
         //????IP
         InetAddress inet=null;
         try {
            inet = InetAddress.getLocalHost();
         } catch (UnknownHostException e) {
            e.printStackTrace();
         }
         ipAddress= inet.getHostAddress();
      }
   }
   //?IPIP,IP','
   if(ipAddress!=null && ipAddress.length()>15){ //"***.***.***.***".length() = 15
      if(ipAddress.indexOf(",")>0){
         ipAddress = ipAddress.substring(0,ipAddress.indexOf(","));
      }
   }
      
   return ipAddress; 
}