List of usage examples for java.net SocketException printStackTrace
public void printStackTrace()
From source file:com.redhat.rhn.domain.monitoring.satcluster.SatClusterFactory.java
/** * Create a new SatCluster (scout)/*from w w w.j a v a 2 s. c om*/ * @param user who creates the Scout * @return new instance */ public static SatCluster createSatCluster(User user) { SatCluster retval = new SatCluster(); CommandTarget ct = new CommandTarget(); ct.setOrg(user.getOrg()); ct.setTargetType("cluster"); retval.setCommandTarget(ct); retval.setOrg(user.getOrg()); retval.setPhysicalLocation(PHYSICAL_LOCATION); retval.setTargetType(ct.getTargetType()); retval.setDeployed("1"); retval.setLastUpdateUser(user.getLogin()); retval.setLastUpdateDate(new Date()); try { InetAddress ip = InetAddress.getLocalHost(); boolean haveIpv4 = ip instanceof Inet4Address; if (haveIpv4) { retval.setVip(ip.getHostAddress()); } else { retval.setVip6(ip.getHostAddress()); } NetworkInterface ni = NetworkInterface.getByInetAddress(ip); for (InterfaceAddress ifa : ni.getInterfaceAddresses()) { InetAddress ia = ifa.getAddress(); if ((ia instanceof Inet4Address) != haveIpv4) { if (haveIpv4) { retval.setVip6(ia.getHostAddress()); } else { retval.setVip(ia.getHostAddress()); } break; } } } catch (Exception e) { log.warn("Failed to find out IP host addresses. " + "Setting loopback IPs instead."); try { NetworkInterface ni = NetworkInterface.getByName("lo"); for (InterfaceAddress ifa : ni.getInterfaceAddresses()) { InetAddress ia = ifa.getAddress(); if (ia instanceof Inet4Address) { if (StringUtils.isEmpty(retval.getVip())) { retval.setVip(ia.getHostAddress()); } } else { //IPv6 if (StringUtils.isEmpty(retval.getVip6())) { retval.setVip6(ia.getHostAddress()); } } } } catch (SocketException se) { log.fatal("Failed to find out loopback IPs."); se.printStackTrace(); } } return retval; }
From source file:ca.frozen.curlingtv.classes.Utils.java
public static String getLocalIpAddress() { try {// www .j a va 2 s. c o m for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en .hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) { return inetAddress.getHostAddress(); } } } } catch (SocketException ex) { ex.printStackTrace(); } return null; }
From source file:at.tlphotography.jAbuseReport.Reporter.java
/** * Whois look up.//w ww . j ava 2 s . co m * * @param ip * the ip * @return the string */ private static String whoIsLookUp(String ip) { String[] serverList = { "whois.ripe.net", "whois.lacnic.net", "whois.registro.br" }; WhoisClient whois = new WhoisClient(); try { for (String server : serverList) { whois.connect(server); String whoisData1 = whois.query(ip); StringBuilder result = new StringBuilder(""); ; result.append(whoisData1); String mail = extractEMail(result.toString()); if (mail != null) return mail; } return "not found"; } catch (SocketException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { try { if (whois.isConnected()) whois.disconnect(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return null; }
From source file:com.icloud.framework.core.util.FBUtilities.java
public static String getIp() { String localip = null;// IP?IP String netip = null;// IP try {/* w w w.j av a 2 s.c o m*/ Enumeration<NetworkInterface> netInterfaces = NetworkInterface.getNetworkInterfaces(); InetAddress ip = null; boolean finded = false;// ?IP while (netInterfaces.hasMoreElements() && !finded) { NetworkInterface ni = netInterfaces.nextElement(); Enumeration<InetAddress> address = ni.getInetAddresses(); while (address.hasMoreElements()) { ip = address.nextElement(); if (!ip.isSiteLocalAddress() && !ip.isLoopbackAddress() && ip.getHostAddress().indexOf(":") == -1) {// IP netip = ip.getHostAddress(); finded = true; break; } else if (ip.isSiteLocalAddress() && !ip.isLoopbackAddress() && ip.getHostAddress().indexOf(":") == -1) {// IP localip = ip.getHostAddress(); } } } } catch (SocketException e) { e.printStackTrace(); } if (netip != null && !"".equals(netip)) { return netip; } else { return localip; } }
From source file:edu.stanford.epad.epadws.processing.pipeline.task.EpadStatisticsTask.java
public static String getIPAddress() { String ip = ""; String ipi = ""; Enumeration e;//from w w w. java 2 s . c o m try { e = NetworkInterface.getNetworkInterfaces(); while (e.hasMoreElements()) { NetworkInterface n = (NetworkInterface) e.nextElement(); Enumeration ee = n.getInetAddresses(); while (ee.hasMoreElements()) { InetAddress i = (InetAddress) ee.nextElement(); ipi = i.getHostAddress(); if (!ipi.startsWith("127") && !ipi.startsWith("192") && !ipi.startsWith("172") && !ipi.startsWith("10.") && !ipi.startsWith("0:")) ip = ipi; } } } catch (SocketException e1) { e1.printStackTrace(); } if (ip.length() == 0) return ipi; else return ip; }
From source file:org.ossmeter.platform.communicationchannel.nntp.NntpUtil.java
public static NNTPClient connectToNntpServer(NntpNewsGroup newsgroup) { NNTPClient client = new NNTPClient(); client.setDefaultPort(newsgroup.getPort()); String serverUrl = newsgroup.getUrl(); if (serverUrl.endsWith("/")) { serverUrl = newsgroup.getUrl().substring(0, newsgroup.getUrl().lastIndexOf("/")); }// www . j av a 2 s . c o m try { client.connect(serverUrl); if (newsgroup.getAuthenticationRequired()) { client.authenticate(newsgroup.getUsername(), newsgroup.getPassword()); } } catch (SocketException e) { // TODO Auto-generated catch block System.err.println("SocketException while connecting to NNTP server: '" + newsgroup.getUrl() + "': " + e.getMessage()); e.printStackTrace(); // System.exit(1); } catch (IOException e) { // TODO Auto-generated catch block System.err.println( "IOException while connecting to NNTP server: '" + newsgroup.getUrl() + "': " + e.getMessage()); e.printStackTrace(); // System.exit(1); } return client; }
From source file:org.vuphone.assassins.android.http.HTTPGetter.java
private static HashMap<String, Double> handleGameAreaResponse(HttpGet get) { HttpResponse resp;/*from w w w . j a v a 2s. com*/ // Execute the get try { resp = c.execute(get); } catch (ClientProtocolException e1) { e1.printStackTrace(); Log.e(VUphone.tag, pre + "HTTP error while executing post"); return null; } catch (SocketException se) { // If we have no Internet connection, we don't want to wipe the // existing list of land mines by returning null. Log.e(VUphone.tag, pre + "SocketException: Invalid Internet " + "Connection"); se.printStackTrace(); return null; } catch (IOException e1) { e1.printStackTrace(); Log.e(VUphone.tag, pre + "HTTP error in server response"); return null; } catch (Exception e) { Log.e(VUphone.tag, pre + "An unknown exception was thrown"); e.printStackTrace(); return null; } Log.i(VUphone.tag, pre + "HTTP operation complete. Processing response."); // Convert Response Entity to usable format ByteArrayOutputStream bao = new ByteArrayOutputStream(); try { resp.getEntity().writeTo(bao); Log.v(VUphone.tag, pre + "Http response: " + bao); } catch (IOException e) { e.printStackTrace(); Log.e(VUphone.tag, pre + "Unable to write response to byte[]"); return null; } if (bao.size() == 0) { Log.w(VUphone.tag, pre + "Response was completely empty, " + "are you sure you are using the " + "same version client and server? " + "At the least, there should have " + "been empty XML here"); } HashMap<String, Double> data = new HashMap<String, Double>(); String response = bao.toString(); String[] vals = response.split("&"); for (int i = 0; i < vals.length; i++) { String[] val = vals[i].split("="); data.put(val[0], Double.valueOf(val[1])); } return data; }
From source file:org.vuphone.assassins.android.http.HTTPGetter.java
private static ArrayList<LandMine> handleLandMineResponse(HttpGet get) { HttpResponse resp;/* ww w . j av a2 s . co m*/ // Execute the get try { resp = c.execute(get); } catch (ClientProtocolException e1) { e1.printStackTrace(); Log.e(VUphone.tag, pre + "HTTP error while executing post"); return null; } catch (SocketException se) { // If we have no Internet connection, we don't want to wipe the // existing list of land mines by returning null. Log.e(VUphone.tag, pre + "SocketException: handled by " + "returning current land mine list."); se.printStackTrace(); return GameObjects.getInstance().getLandMines(); } catch (IOException e1) { e1.printStackTrace(); Log.e(VUphone.tag, pre + "HTTP error in server response"); return null; } catch (Exception e) { Log.e(VUphone.tag, pre + "An unknown exception was thrown"); e.printStackTrace(); return null; } Log.i(VUphone.tag, pre + "HTTP operation complete. Processing response."); // Convert Response Entity to usable format ByteArrayOutputStream bao = new ByteArrayOutputStream(); try { resp.getEntity().writeTo(bao); Log.v(VUphone.tag, pre + "Http response: " + bao); } catch (IOException e) { e.printStackTrace(); Log.e(VUphone.tag, pre + "Unable to write response to byte[]"); return null; } // Extract Land Mines from response if (bao.size() == 0) { Log.w(VUphone.tag, pre + "Response was completely empty, " + "are you sure you are using the " + "same version client and server? " + "At the least, there should have " + "been empty XML here"); } ArrayList<LandMine> mines = new ArrayList<LandMine>( landMineHandler_.processXML(new InputSource(new ByteArrayInputStream(bao.toByteArray())))); return mines; //return GameObjects.getInstance().getLandMines(); //return null; }
From source file:comikit.droidscript.DroidScriptServer.java
public static String[] getIpAddresses() { try {//from ww w . j a v a 2 s.c o m List<String> ipaddresses = new ArrayList<String>(); Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); while (interfaces.hasMoreElements()) { NetworkInterface interf = interfaces.nextElement(); Enumeration<InetAddress> adresses = interf.getInetAddresses(); while (adresses.hasMoreElements()) { InetAddress address = adresses.nextElement(); if (!address.isLoopbackAddress()) { ipaddresses.add(address.getHostAddress().toString()); } } } if (0 < ipaddresses.size()) { return ipaddresses.toArray(new String[1]); } } catch (SocketException e) { e.printStackTrace(); } return null; }
From source file:de.madvertise.android.sdk.MadvertiseUtil.java
/** * Fetch the address of the enabled interface * //from w w w .jav a 2s . c o m * @return ip address as string */ public static String getLocalIpAddress(MadvertiseViewCallbackListener listener) { try { for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en .hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); if (!inetAddress.isLoopbackAddress()) { if (inetAddress instanceof Inet4Address) { return inetAddress.getHostAddress().toString(); } } } } } catch (SocketException e) { if (listener != null) { listener.onError(e); } e.printStackTrace(); } if (listener != null) { listener.onError(new IllegalArgumentException("Couldn't obtain the local ip address")); } return ""; }