List of usage examples for java.net UnknownHostException getMessage
public String getMessage()
From source file:org.spirit.util.BotListUniqueId.java
public static final String getUniqueId() { String digest = ""; try {/* w w w . j a v a 2 s .c om*/ MessageDigest md = MessageDigest.getInstance("MD5"); String timeVal = "" + (System.currentTimeMillis() + 1); String localHost = ""; ; try { localHost = InetAddress.getLocalHost().toString(); } catch (UnknownHostException e) { // If an error, we can use other values. log.error("Error trying to get localhost" + e.getMessage()); } String randVal = "" + new Random().nextInt(); String val = timeVal + localHost + randVal; md.reset(); md.update(val.getBytes()); // Generate the digest. digest = toHexString(md.digest()); } catch (NoSuchAlgorithmException e) { log.error("Error trying to generate unique Id" + e.getMessage()); } // End of the Try - Catch return digest; }
From source file:com.sm.transport.Utils.java
/** * * @return long represent by HostAddress+ PID */// w ww. j a va 2 s .c om public static long getDefaultNodeId() { String host = null; try { host = Inet4Address.getLocalHost().getHostAddress(); } catch (java.net.UnknownHostException ex) { logger.error(ex.getMessage() + " using 127.0.0.1"); host = "127.0.0.1"; } int ip = getIP(host); logger.info("pid " + getPID() + " ip " + ip + " host " + host); long toReturn = (((long) getPID()) << 32) + ip; return toReturn; }
From source file:com.evolveum.midpoint.web.security.MidPointAuthenticationProvider.java
public static String getRemoteHost() { WebRequest req = (WebRequest) RequestCycle.get().getRequest(); HttpServletRequest httpReq = (HttpServletRequest) req.getContainerRequest(); String remoteIp = httpReq.getRemoteHost(); String localIp = httpReq.getLocalAddr(); if (remoteIp.equals(localIp)) { try {//from w w w .j a v a2s. c o m InetAddress inetAddress = InetAddress.getLocalHost(); remoteIp = inetAddress.getHostAddress(); } catch (UnknownHostException ex) { LOGGER.error("Can't get local host: " + ex.getMessage()); } } return remoteIp; }
From source file:org.lic.ip.iplocator.IPv4RadixIntTree.java
private static long inet_aton(String ipStr) { try {//from ww w.j av a 2 s . co m ByteBuffer bb = ByteBuffer.allocate(8); bb.putInt(0); bb.put(InetAddress.getByName(ipStr).getAddress()); bb.rewind(); return bb.getLong(); } catch (UnknownHostException e) { logger.error(e.getMessage(), e); } return 0; }
From source file:org.sonar.application.config.ClusterSettings.java
private static InetAddress convertToInetAddress(String text, String key) { InetAddress inetAddress;/*from w ww . j ava2 s . c om*/ HostAndPort hostAndPort = HostAndPort.fromString(text); if (!InetAddresses.isInetAddress(hostAndPort.getHostText())) { try { inetAddress = InetAddress.getByName(hostAndPort.getHostText()); } catch (UnknownHostException e) { throw new MessageException(format("The interface address [%s] of [%s] cannot be resolved : %s", text, key, e.getMessage())); } } else { inetAddress = forString(hostAndPort.getHostText()); } return inetAddress; }
From source file:org.apache.hadoop.hive.ql.txn.compactor.Worker.java
/** * Get the hostname that this worker is run on. Made static and public so that other classes * can use the same method to know what host their worker threads are running on. * @return hostname// w ww. j av a2s . co m */ public static String hostname() { try { return InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { LOG.error("Unable to resolve my host name " + e.getMessage()); throw new RuntimeException(e); } }
From source file:io.udvi.amqp.mq.transport.connection.CAMQPConnectionManager.java
public synchronized static void initialize(String containerId) { if (CAMQPConnectionManager.containerId == null) { String hostName = "localhost"; try {/*from w w w . jav a2s .c o m*/ InetAddress localMachine = InetAddress.getLocalHost(); hostName = localMachine.getHostAddress(); log.debug("hostName: " + hostName); } catch (java.net.UnknownHostException uhe) { String errorMessage = "Caught UnknownHostException while resolving canonicalHostName: " + uhe.getMessage(); log.error(errorMessage); throw new CAMQPConnectionException(errorMessage); } CAMQPConnectionManager.containerId = String.format("%s@%s", containerId, hostName); log.info("Initialized UdviMQ endpoint ID: " + CAMQPConnectionManager.containerId); System.out.println("Initialized UdviMQ endpoint ID: " + CAMQPConnectionManager.containerId); } else { throw new IllegalStateException("CAMQPConnectionManager already initialized: containerId: " + CAMQPConnectionManager.containerId); } }
From source file:net.dovemq.transport.connection.CAMQPConnectionManager.java
public synchronized static void initialize(String containerId) { if (CAMQPConnectionManager.containerId == null) { String hostName = "localhost"; try {// w w w .j a v a 2 s. c om InetAddress localMachine = InetAddress.getLocalHost(); hostName = localMachine.getHostAddress(); log.debug("hostName: " + hostName); } catch (java.net.UnknownHostException uhe) { String errorMessage = "Caught UnknownHostException while resolving canonicalHostName: " + uhe.getMessage(); log.error(errorMessage); throw new CAMQPConnectionException(errorMessage); } CAMQPConnectionManager.containerId = String.format("%s@%s", containerId, hostName); log.info("Initialized DoveMQ endpoint ID: " + CAMQPConnectionManager.containerId); System.out.println("Initialized DoveMQ endpoint ID: " + CAMQPConnectionManager.containerId); } else { throw new IllegalStateException("CAMQPConnectionManager already initialized: containerId: " + CAMQPConnectionManager.containerId); } }
From source file:uk.ac.bbsrc.tgac.miso.integration.util.IntegrationUtils.java
/** * Sends a String message to a given host socket * /*from w w w. java 2s .c om*/ * @param socket * of type Socket * @param query * of type String * @return String * @throws IntegrationException * when the socket couldn't be created */ public static String sendMessage(Socket socket, String query) throws IntegrationException { BufferedWriter wr = null; BufferedReader rd = null; try { wr = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), "UTF8")); // Send data wr.write(query + "\r\n"); wr.flush(); // Get response rd = new BufferedReader(new InputStreamReader(socket.getInputStream())); String line; StringBuilder sb = new StringBuilder(); while ((line = rd.readLine()) != null) { sb.append(line); } wr.close(); rd.close(); String dirty = sb.toString(); StringBuilder response = new StringBuilder(); int codePoint; int i = 0; while (i < dirty.length()) { codePoint = dirty.codePointAt(i); if ((codePoint == 0x9) || (codePoint == 0xA) || (codePoint == 0xD) || ((codePoint >= 0x20) && (codePoint <= 0xD7FF)) || ((codePoint >= 0xE000) && (codePoint <= 0xFFFD)) || ((codePoint >= 0x10000) && (codePoint <= 0x10FFFF))) { response.append(Character.toChars(codePoint)); } i += Character.charCount(codePoint); } return response.toString().replace("\\\n", "").replace("\\\t", ""); } catch (UnknownHostException e) { log.error("Cannot resolve host: " + socket.getInetAddress(), e); throw new IntegrationException(e.getMessage()); } catch (IOException e) { log.error("Couldn't get I/O for the connection to: " + socket.getInetAddress(), e); throw new IntegrationException(e.getMessage()); } finally { try { if (wr != null) { wr.close(); } if (rd != null) { rd.close(); } } catch (Throwable t) { log.error("close socket", t); } } }
From source file:org.eclipse.gyrex.cloud.internal.NodeInfo.java
private static String getDefaultLocationInfo(final String nodeId) { try {/*from w ww . j a v a 2 s .c om*/ return InetAddress.getLocalHost().getCanonicalHostName(); } catch (final UnknownHostException e) { return nodeId + ": " + e.getMessage(); } }