List of usage examples for java.net UnknownHostException getMessage
public String getMessage()
From source file:org.emoseman.aconf.AutoConfig.java
private static String gethostname() { try {/*from ww w. j a v a 2 s.c o m*/ return InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { log.error(e.getMessage()); } return "failed to resolve hostname"; }
From source file:at.ac.tuwien.dsg.cloud.salsa.engine.utils.SystemFunctions.java
public static boolean isIPv4Address(String address) { if (address.isEmpty()) { return false; }/*from w w w .ja va2 s . co m*/ try { Object res = InetAddress.getByName(address); return (res.getClass().equals(Inet4Address.class)); } catch (final UnknownHostException ex) { logger.error("Cannot get the host IP address. The captured address is: {}. Error: {}", address, ex.getMessage()); return false; } }
From source file:com.adobe.aem.demomachine.gui.AemDemoUtils.java
public static void antTarget(AemDemo aemDemo, String targetName) { String selectedDemoMachine = (String) aemDemo.getListDemoMachines().getSelectedValue(); if (Arrays.asList(AemDemoConstants.INSTANCE_ACTIONS).contains(targetName) && (selectedDemoMachine == null || selectedDemoMachine.toString().length() == 0)) { JOptionPane.showMessageDialog(null, "Please select a demo environment before running this command"); } else {/*from w w w. ja v a2 s. c om*/ // New ANT project AemDemoProject p = new AemDemoProject(aemDemo); if (selectedDemoMachine != null && selectedDemoMachine.length() > 0) p.setUserProperty("demo.build", selectedDemoMachine.toString()); // Make sure host name is there try { p.setUserProperty("demo.hostname", InetAddress.getLocalHost().getHostName()); } catch (UnknownHostException ex) { logger.error(ex.getMessage()); } p.init(); ProjectHelper helper = ProjectHelper.getProjectHelper(); p.addReference("ant.projectHelper", helper); helper.parse(p, aemDemo.getBuildFile()); // Running the target name as a new Thread System.out.println("Running ANT target: " + targetName); Thread t = new Thread(new AemDemoRunnable(aemDemo, p, targetName)); t.start(); } }
From source file:zz.pseas.ghost.utils.HttpClinetUtil.java
/** * @author GS//www. jav a2 s. co m * @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 ww. jav a 2 s. c o m * @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 w w w. ja v a2s . com * @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.apache.ws.security.util.UUIDGenerator.java
protected static synchronized void getInitialUUID() { if (baseUUID != null) { return;//from w ww . ja v a 2s . co m } if (myRand == null) { myRand = new Random(); } long rand = myRand.nextLong(); String sid; try { sid = InetAddress.getLocalHost().toString(); } catch (UnknownHostException e) { sid = Thread.currentThread().getName(); } StringBuffer sb = new StringBuffer(); sb.append(sid); sb.append(":"); sb.append(Long.toString(rand)); MessageDigest md5 = null; try { md5 = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { if (log.isDebugEnabled()) { log.debug(e.getMessage(), e); } //todo have to be properly handled } md5.update(sb.toString().getBytes()); byte[] array = md5.digest(); StringBuffer sb2 = new StringBuffer(); for (int j = 0; j < array.length; ++j) { int b = array[j] & 0xFF; sb2.append(Integer.toHexString(b)); } int begin = myRand.nextInt(); if (begin < 0) begin = begin * -1; begin = begin % 8; baseUUID = sb2.toString().substring(begin, begin + 18).toUpperCase(); }
From source file:ubicrypt.core.Utils.java
public static String machineName() { try {//from w w w . j av a 2s . c om return System.getProperty("user.name") + "/" + InetAddress.getLocalHost().getHostName(); } catch (final UnknownHostException e) { log.error(e.getMessage(), e); } return System.getProperty("user.name"); }
From source file:com.flexive.shared.stream.FxStreamUtils.java
/** * Probe all network interfaces and return the most suited to run a StreamServer on. * Preferred are interfaces that are not site local. * * @return best suited host to run a StreamServer * @throws UnknownHostException on errors *///ww w . java 2 s .c o m public static InetAddress probeNetworkInterfaces() throws UnknownHostException { try { final String forcedAddress = System.getProperty("FxStreamIP"); if (forcedAddress != null) { try { InetAddress ad = InetAddress.getByName(forcedAddress); LOG.info("Binding [fleXive] streamserver to forced address [" + forcedAddress + "] ..."); return ad; } catch (UnknownHostException e) { LOG.error("Forced [fleXive] streamserver bind address [" + forcedAddress + "] can not be used: " + e.getMessage() + " - probing available network interfaces ..."); } } Enumeration<NetworkInterface> nifs = NetworkInterface.getNetworkInterfaces(); NetworkInterface nif; InetAddress preferred = null, fallback = null; while (nifs.hasMoreElements()) { nif = nifs.nextElement(); if (LOG.isDebugEnabled()) LOG.debug("Probing " + nif.getDisplayName() + " ..."); if (nif.getDisplayName().startsWith("vmnet") || nif.getDisplayName().startsWith("vnet")) continue; Enumeration<InetAddress> inas = nif.getInetAddresses(); while (inas.hasMoreElements()) { InetAddress na = inas.nextElement(); if (LOG.isDebugEnabled()) LOG.debug("Probing " + nif.getDisplayName() + na); if (!(na instanceof Inet4Address)) continue; if (!na.isLoopbackAddress() && na.isReachable(1000)) { if (preferred == null || (preferred.isSiteLocalAddress() && !na.isSiteLocalAddress())) preferred = na; } if (fallback == null && na.isLoopbackAddress()) fallback = na; } } if (LOG.isDebugEnabled()) LOG.debug("preferred: " + preferred + " fallback: " + fallback); if (preferred != null) return preferred; if (fallback != null) return fallback; return InetAddress.getLocalHost(); } catch (Exception e) { return InetAddress.getLocalHost(); } }
From source file:com.gisgraphy.domain.geoloc.importer.ImporterHelper.java
/** * @param address//from www .ja v a 2s . co m * the address of the file to be downloaded * @param localFileName * the local file name (with absolute path) */ public static void download(String address, String localFileName) { logger.info("download file " + address + " to " + localFileName); OutputStream out = null; HttpURLConnection conn = null; InputStream in = null; try { URL url = new URL(address); out = new BufferedOutputStream(new FileOutputStream(localFileName)); conn = (HttpURLConnection) url.openConnection(); if (conn instanceof HttpURLConnection) { int responseCode = ((HttpURLConnection) conn).getResponseCode(); //manage most frequent error code and Gisgraphy specific one switch (responseCode) { case 509: throw new RuntimeException("Sorry, there is too many users connected for " + address + ", this site has limmited resources, please try again later"); case 500: throw new RuntimeException("Sorry, the server return an 500 status code for " + address + ", an internal error has occured"); case 404: throw new RuntimeException("Sorry, the server return an 404 status code for " + address + ", the file probably not exists or the URL is not correct"); default: break; } } in = conn.getInputStream(); byte[] buffer = new byte[1024]; int numRead; long numWritten = 0; while ((numRead = in.read(buffer)) != -1) { out.write(buffer, 0, numRead); numWritten += numRead; } logger.info(localFileName + "\t" + numWritten); } catch (UnknownHostException e) { String errorMessage = "can not download " + address + " to " + localFileName + " : " + e.getMessage() + ". if the host exists and is reachable," + " maybe this links can help : http://www.gisgraphy.com/forum/viewtopic.php?f=3&t=64 "; logger.warn(errorMessage); throw new ImporterException(errorMessage, e); } catch (Exception e) { logger.warn("can not download " + address + " to " + localFileName + " : " + e.getMessage()); throw new ImporterException(e); } finally { try { if (in != null) { in.close(); } if (out != null) { out.flush(); out.close(); } } catch (IOException ioe) { logger.error("cannot close streams"); } } }