List of usage examples for java.net UnknownHostException getMessage
public String getMessage()
From source file:com.amalto.workbench.utils.LocalTreeObjectRepository.java
private String UnifyUrl(String url) { Pattern mask = Pattern.compile("http://(.*?):(.*)");//$NON-NLS-1$ Matcher matcher = mask.matcher(url); if (matcher.find()) { String ip = matcher.group(1); String ipAlias = "";//$NON-NLS-1$ String hostName = "";//$NON-NLS-1$ try {//from w w w .jav a 2 s.c om InetAddress addr = InetAddress.getLocalHost(); ipAlias = addr.getHostAddress().toString(); hostName = addr.getHostName().toString(); if (ip.equals("127.0.0.1") || ip.equals(ipAlias) || ip.equals(hostName) || ip.equals("localhost")) {//$NON-NLS-1$//$NON-NLS-2$ url = "http://" + ipAlias + ":" + matcher.group(2);//$NON-NLS-1$//$NON-NLS-2$ } } catch (UnknownHostException e) { log.error(e.getMessage(), e); } } return url; }
From source file:com.clustercontrol.nodemap.session.NodeMapControllerBean.java
/** * fping?ping?????<BR>/*from w w w . ja v a 2 s.com*/ * @param facilityId Ping?ID()collect?facilityID??? * @return ping?? * @throws HinemosUnknown * @throws NodeMapException */ public List<String> pingToFacilityList(List<String> facilityList) throws HinemosUnknown, NodeMapException { String message = ""; String messageOrg = ""; //?????? // hosts[] IP(String ??) // hostsv6[] IPv6(String??) // node IP???? // target nodo? HashSet<String> hosts = new HashSet<String>(); HashSet<String> hostsv6 = new HashSet<String>(); // ip?name Hashtable<String, List<String>> facilityNameTable = new Hashtable<>(); String facilityId = null; int version = 4; String[] node; for (int index = 0; index < facilityList.size(); index++) { facilityId = facilityList.get(index); if (facilityId != null && !"".equals(facilityId)) { node = new String[2]; try { // ?? NodeInfo info = new RepositoryControllerBean().getNode(facilityId); if (info.getIpAddressVersion() != null) { version = info.getIpAddressVersion(); } else { version = 4; } if (version == 6) { InetAddress[] ip = InetAddress.getAllByName(info.getIpAddressV6()); if (ip.length != 1) { //IPInetAddress??????1???????? //UnnownHostExcption UnknownHostException e = new UnknownHostException(); m_log.info("pingToFacilityList() : " + e.getClass().getSimpleName() + ", " + e.getMessage()); throw e; } node[0] = ip[0].getHostAddress(); if (node[0] != null && !node[0].equals("")) { //IPHashSet????? hostsv6.add(node[0]); } } else { node[0] = info.getIpAddressV4(); if (node[0] != null && !node[0].equals("")) { //IPHashSet????? hosts.add(node[0]); } } if (node[0] != null && !node[0].equals("")) { node[1] = info.getNodeName(); //target?????? List<String> facilitys = facilityNameTable.get(node[0]); if (facilitys == null) { facilitys = new ArrayList<>(); } facilitys.add(facilityId); facilityNameTable.put(node[0], facilitys); } } catch (FacilityNotFound e) { message = MessageConstant.MESSAGE_COULD_NOT_GET_NODE_ATTRIBUTES_PING.getMessage() + "," + facilityId; messageOrg = e.getMessage(); throw new NodeMapException(message + ", " + messageOrg, e); } catch (UnknownHostException e) { // ??? } } } int runCount = 0; int runInterval = 0; int pingTimeout = 0; try { // [](default:1?19) String runCountKey = "nodemap.ping.runcount"; runCount = HinemosPropertyUtil .getHinemosPropertyNum(runCountKey, Long.valueOf(PingRunCountConstant.TYPE_COUNT_01)) .intValue(); CommonValidator.validateInt(runCountKey, runCount, 1, 9); // [ms](default:1000?05000) String runIntervalKey = "nodemap.ping.runinterval"; runInterval = HinemosPropertyUtil .getHinemosPropertyNum(runIntervalKey, Long.valueOf(PingRunIntervalConstant.TYPE_SEC_02)) .intValue(); CommonValidator.validateInt(runIntervalKey, runInterval, 0, 5 * 1000); // [ms](default:5000?13600000) String pintTimeoutKey = "nodemap.ping.timeout"; pingTimeout = HinemosPropertyUtil .getHinemosPropertyNum(pintTimeoutKey, Long.valueOf(PingRunIntervalConstant.TYPE_SEC_05)) .intValue(); CommonValidator.validateInt(pintTimeoutKey, pingTimeout, 1, 60 * 60 * 1000); } catch (Exception e) { m_log.warn("pingToFacilityList() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); throw new HinemosUnknown(e.getMessage(), e); } ReachAddressFping reachabilityFping = new ReachAddressFping(runCount, runInterval, pingTimeout); boolean result = true; boolean resultTmp = true; ArrayList<String> msgErr = new ArrayList<>(); ArrayList<String> msgErrV6 = new ArrayList<>(); Hashtable<String, PingResult> fpingResultSet = new Hashtable<String, PingResult>(); Hashtable<String, PingResult> fpingResultSetV6 = new Hashtable<String, PingResult>(); RunMonitorPing monitorPing = new RunMonitorPing(); //IPv4???fping?? if (hosts.size() != 0) { result = reachabilityFping.isReachable(hosts, 4); msgErr = reachabilityFping.getM_errMsg(); } //IPv6???fping6?? if (hostsv6.size() != 0) { resultTmp = reachabilityFping.isReachable(hostsv6, 6); msgErrV6 = reachabilityFping.getM_errMsg(); } if (!result || !resultTmp) { return null; } List<String> retList = new ArrayList<>(); fpingResultSet = monitorPing.wrapUpFping(msgErr, runCount, 4); fpingResultSetV6 = monitorPing.wrapUpFping(msgErrV6, runCount, 6); //IPv4????????IPv6????? m_log.debug("pingToFacilityList(): before fpingResultSet check"); if (fpingResultSet.size() == 0) { m_log.debug("pingToFacilityList(): after fpingResultSet check"); fpingResultSet = fpingResultSetV6; } //IPv4??????IPv6?? else if (fpingResultSetV6.size() != 0) { fpingResultSet.putAll(fpingResultSetV6); } for (Map.Entry<String, List<String>> ipAdd : facilityNameTable.entrySet()) { PingResult pingResult = fpingResultSet.get(ipAdd.getKey()); for (String facility : ipAdd.getValue()) { retList.add(facility + " : " + pingResult.getMesseageOrg()); } } return retList; }
From source file:com.corebase.android.framework.http.client.AsyncHttpRequest.java
private void makeRequestWithRetries() throws IOException { // This is an additional layer of retry logic lifted from droid-fu // See:// w w w .j a v a 2s . c o m // https://github.com/kaeppler/droid-fu/blob/master/src/main/java/com/github/droidfu/http/BetterHttpRequestBase.java boolean retry = true; IOException cause = null; HttpRequestRetryHandler retryHandler = client.getHttpRequestRetryHandler(); while (retry) { try { makeRequest(); return; } catch (UnknownHostException e) { if (responseHandler != null) { responseHandler.sendFailureMessage(mycontext, e, "can't resolve host"); } Log.i("msg", "1"); return; } catch (SocketException e) { // Added to detect host unreachable if (responseHandler != null) { responseHandler.sendFailureMessage(mycontext, e, "can't resolve host"); } Log.i("msg", "2"); return; } catch (SocketTimeoutException e) { if (responseHandler != null) { responseHandler.sendFailureMessage(mycontext, e, "socket time out"); } Log.i("msg", "3"); return; } catch (IOException e) { cause = e; retry = retryHandler.retryRequest(cause, ++executionCount, context); Log.i("msg", "4"); } catch (NullPointerException e) { // there's a bug in HttpClient 4.0.x that on some occasions // causes // DefaultRequestExecutor to throw an NPE, see // http://code.google.com/p/android/issues/detail?id=5255 cause = new IOException("NPE in HttpClient" + e.getMessage()); Log.i("msg", "4"); retry = retryHandler.retryRequest(cause, ++executionCount, context); } catch (Exception e) { e.printStackTrace(); cause = new IOException("Exception" + e.getMessage()); retry = retryHandler.retryRequest(cause, ++executionCount, context); Log.i("msg", "4"); } } // ?? // ConnectException ex = new ConnectException(); // ex.initCause(cause); throw cause; }
From source file:org.apache.cassandra.staleness.Session.java
public Session(String[] arguments) throws IllegalArgumentException { float STDev = 0.1f; CommandLineParser parser = new PosixParser(); try {//from w ww . ja v a2s. com CommandLine cmd = parser.parse(availableOptions, arguments); if (cmd.getArgs().length > 0) { System.err.println("Application does not allow arbitrary arguments: " + StringUtils.join(cmd.getArgList(), ", ")); System.exit(1); } if (cmd.hasOption("h")) throw new IllegalArgumentException("help"); if (cmd.hasOption("n")) numKeys = Integer.parseInt(cmd.getOptionValue("n")); if (cmd.hasOption("F")) numDifferentKeys = Integer.parseInt(cmd.getOptionValue("F")); else numDifferentKeys = numKeys; if (cmd.hasOption("N")) skipKeys = Float.parseFloat(cmd.getOptionValue("N")); if (cmd.hasOption("t")) threads = Integer.parseInt(cmd.getOptionValue("t")); if (cmd.hasOption("c")) columns = Integer.parseInt(cmd.getOptionValue("c")); if (cmd.hasOption("S")) columnSize = Integer.parseInt(cmd.getOptionValue("S")); if (cmd.hasOption("C")) cardinality = Integer.parseInt(cmd.getOptionValue("C")); //if (cmd.hasOption("d")) // nodes = cmd.getOptionValue("d").split(","); //if (cmd.hasOption("D")) //{ // try // { // String node = null; // List<String> tmpNodes = new ArrayList<String>(); // BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(cmd.getOptionValue("D")))); // while ((node = in.readLine()) != null) // { // if (node.length() > 0) // tmpNodes.add(node); // } // nodes = tmpNodes.toArray(new String[tmpNodes.size()]); // in.close(); // } // catch(IOException ioe) // { // throw new RuntimeException(ioe); // } //} if (cmd.hasOption("s")) STDev = Float.parseFloat(cmd.getOptionValue("s")); if (cmd.hasOption("r")) random = true; outFileName = (cmd.hasOption("f")) ? cmd.getOptionValue("f") : null; if (cmd.hasOption("p")) port = Integer.parseInt(cmd.getOptionValue("p")); if (cmd.hasOption("m")) unframed = Boolean.parseBoolean(cmd.getOptionValue("m")); if (cmd.hasOption("u")) superColumns = Integer.parseInt(cmd.getOptionValue("u")); if (cmd.hasOption("y")) columnFamilyType = ColumnFamilyType.valueOf(cmd.getOptionValue("y")); if (cmd.hasOption("K")) { retryTimes = Integer.valueOf(cmd.getOptionValue("K")); if (retryTimes <= 0) { throw new RuntimeException("--keep-trying option value should be > 0"); } } if (cmd.hasOption("k")) { retryTimes = 1; ignoreErrors = true; } if (cmd.hasOption("i")) progressInterval = Integer.parseInt(cmd.getOptionValue("i")); if (cmd.hasOption("g")) keysPerCall = Integer.parseInt(cmd.getOptionValue("g")); if (cmd.hasOption("e")) consistencyLevel = ConsistencyLevel.valueOf(cmd.getOptionValue("e").toUpperCase()); if (cmd.hasOption("x")) indexType = IndexType.valueOf(cmd.getOptionValue("x").toUpperCase()); if (cmd.hasOption("R")) replicationStrategy = cmd.getOptionValue("R"); if (cmd.hasOption("l")) replicationStrategyOptions.put("replication_factor", String.valueOf(Integer.parseInt(cmd.getOptionValue("l")))); else if (replicationStrategy.endsWith("SimpleStrategy")) replicationStrategyOptions.put("replication_factor", "1"); if (cmd.hasOption("L")) enable_cql = true; if (cmd.hasOption("P")) { if (!enable_cql) { System.err .println("-P/--use-prepared-statements is only applicable with CQL (-L/--enable-cql)"); System.exit(-1); } use_prepared = true; } if (cmd.hasOption("O")) { String[] pairs = StringUtils.split(cmd.getOptionValue("O"), ','); for (String pair : pairs) { String[] keyAndValue = StringUtils.split(pair, ':'); if (keyAndValue.length != 2) throw new RuntimeException("Invalid --strategy-properties value."); replicationStrategyOptions.put(keyAndValue[0], keyAndValue[1]); } } if (cmd.hasOption("W")) replicateOnWrite = false; if (cmd.hasOption("I")) compression = cmd.getOptionValue("I"); averageSizeValues = cmd.hasOption("V"); try { sendToDaemon = cmd.hasOption("send-to") ? InetAddress.getByName(cmd.getOptionValue("send-to")) : null; } catch (UnknownHostException e) { throw new RuntimeException(e); } if (cmd.hasOption("Q")) { AbstractType comparator = TypeParser.parse(DEFAULT_COMPARATOR); String[] names = StringUtils.split(cmd.getOptionValue("Q"), ","); columnNames = new ArrayList<ByteBuffer>(names.length); for (String columnName : names) columnNames.add(comparator.fromString(columnName)); } else { columnNames = null; } if (cmd.hasOption("Z")) { compactionStrategy = cmd.getOptionValue("Z"); try { // validate compaction strategy class CFMetaData.createCompactionStrategy(compactionStrategy); } catch (ConfigurationException e) { System.err.println(e.getMessage()); System.exit(1); } } if (cmd.hasOption("U")) { AbstractType parsed = null; try { parsed = TypeParser.parse(cmd.getOptionValue("U")); } catch (ConfigurationException e) { System.err.println(e.getMessage()); System.exit(1); } comparator = cmd.getOptionValue("U"); timeUUIDComparator = parsed instanceof TimeUUIDType; if (!(parsed instanceof TimeUUIDType || parsed instanceof AsciiType || parsed instanceof UTF8Type)) { System.err.println("Currently supported types are: TimeUUIDType, AsciiType, UTF8Type."); System.exit(1); } } else { comparator = null; timeUUIDComparator = false; } } catch (ParseException e) { throw new IllegalArgumentException(e.getMessage(), e); } catch (ConfigurationException e) { throw new IllegalStateException(e.getMessage(), e); } mean = numDifferentKeys / 2; sigma = numDifferentKeys * STDev; operations = new AtomicInteger(); keys = new AtomicInteger(); latency = new AtomicLong(); }
From source file:com.pyj.http.AsyncHttpRequest.java
private void makeRequestWithRetries() throws ConnectException { // This is an additional layer of retry logic lifted from droid-fu // See: https://github.com/kaeppler/droid-fu/blob/master/src/main/java/com/github/droidfu/http/BetterHttpRequestBase.java boolean retry = true; IOException cause = null;//from ww w. jav a 2s . c o m HttpRequestRetryHandler retryHandler = client.getHttpRequestRetryHandler(); while (retry) { try { makeRequest(); return; } catch (UnknownHostException e) { if (responseHandler != null) { responseHandler.sendFailureMessage( new HupuHttpException("???????"), (String) null, reqType); } return; } catch (SocketException e) { // Added to detect host unreachable if (responseHandler != null) { responseHandler.sendFailureMessage( new HupuHttpException("????"), (String) null, reqType); } return; } catch (SocketTimeoutException e) { if (responseHandler != null) { responseHandler.sendFailureMessage( new HupuHttpException("????"), (String) null, reqType); } return; } catch (IOException e) { cause = e; retry = retryHandler.retryRequest(cause, ++executionCount, context); } catch (NullPointerException e) { // there's a bug in HttpClient 4.0.x that on some occasions causes // DefaultRequestExecutor to throw an NPE, see // http://code.google.com/p/android/issues/detail?id=5255 cause = new IOException("NPE in HttpClient" + e.getMessage()); retry = retryHandler.retryRequest(cause, ++executionCount, context); } } // no retries left, crap out with exception ConnectException ex = new ConnectException(); ex.initCause(cause); throw ex; }
From source file:us.paulevans.basicxslt.BasicXSLTFrame.java
/** * Method to validate the source xml./*from w ww.ja va 2 s . c o m*/ */ private boolean validateXml(String aLabel, String sourceXmlFile, boolean checkWarnings, boolean checkErrors, boolean checkFatalErrors, JFrame parent, boolean aSuppressSuccessDialog) { boolean isValid; FileContent content; isValid = false; try { content = fsManager.resolveFile(sourceXmlFile).getContent(); Utils.getInstance().isValidXml(content, checkWarnings, checkErrors, checkFatalErrors); isValid = true; if (!aSuppressSuccessDialog) { Utils.showDialog(parent, MessageFormat.format(stringFactory.getString(LabelStringFactory.MAIN_FRAME_VALID_XML_MSG), sourceXmlFile), stringFactory.getString(LabelStringFactory.MAIN_FRAME_VALID_XML_MSG_HDR_YES), JOptionPane.INFORMATION_MESSAGE); } } catch (UnknownHostException aException) { logger.error(aException); Utils.handleXMLError(stringFactory.getString(LabelStringFactory.MAIN_FRAME_VALID_XML_MSG_HDR_NO), aLabel, stringFactory.getString(LabelStringFactory.MAIN_FRAME_XML_VALIDATION_ERR), sourceXmlFile, this, aException.getMessage()); } catch (SocketException aException) { logger.error(aException); Utils.handleXMLError(stringFactory.getString(LabelStringFactory.MAIN_FRAME_VALID_XML_MSG_HDR_NO), aLabel, stringFactory.getString(LabelStringFactory.MAIN_FRAME_XML_VALIDATION_ERR), sourceXmlFile, this, aException.getMessage()); } catch (Throwable aAny) { Utils.handleXMLError(stringFactory.getString(LabelStringFactory.MAIN_FRAME_VALID_XML_MSG_HDR_NO), aLabel, stringFactory.getString(LabelStringFactory.MAIN_FRAME_XML_VALIDATION_ERR), sourceXmlFile, this, aAny); } return isValid; }
From source file:org.apache.hadoop.yarn.server.nodemanager.TestNodeStatusUpdater.java
private YarnConfiguration createNMConfig(int port) throws IOException { YarnConfiguration conf = new YarnConfiguration(); String localhostAddress = null; try {// w ww . j a v a2s . c o m localhostAddress = InetAddress.getByName("localhost").getCanonicalHostName(); } catch (UnknownHostException e) { Assert.fail("Unable to get localhost address: " + e.getMessage()); } conf.setInt(YarnConfiguration.NM_PMEM_MB, 5 * 1024); // 5GB conf.set(YarnConfiguration.NM_ADDRESS, localhostAddress + ":" + port); conf.set(YarnConfiguration.NM_LOCALIZER_ADDRESS, localhostAddress + ":" + ServerSocketUtil.getPort(49160, 10)); conf.set(YarnConfiguration.NM_LOG_DIRS, logsDir.getAbsolutePath()); conf.set(YarnConfiguration.NM_REMOTE_APP_LOG_DIR, remoteLogsDir.getAbsolutePath()); conf.set(YarnConfiguration.NM_LOCAL_DIRS, nmLocalDir.getAbsolutePath()); conf.setLong(YarnConfiguration.NM_LOG_RETAIN_SECONDS, 1); return conf; }
From source file:com.cnaude.purpleirc.PurpleIRC.java
public String getPlayerHost(final String playerIP) { if (playerIP == null) { return "unknown"; }/*from ww w .j a v a2s. c o m*/ if (hostCache.containsKey(playerIP)) { return hostCache.get(playerIP); } else { getServer().getScheduler().runTaskLaterAsynchronously(this, new Runnable() { @Override public void run() { long a = System.currentTimeMillis(); InetAddress addr = null; try { addr = InetAddress.getByName(playerIP); } catch (UnknownHostException ex) { logError(ex.getMessage()); } String host; if (addr != null) { host = addr.getHostName(); } else { host = playerIP; } hostCache.put(playerIP, host); logDebug( "getPlayerHost[" + (System.currentTimeMillis() - a) + "ms] " + playerIP + " = " + host); } }, 0); return playerIP; } }
From source file:org.ngrinder.NGrinderStarter.java
/** * Start ngrinder agent.//w w w . j a v a2 s.com * * @param controllerIp * controllerIp; */ public void startAgent(String controllerIp) { LOG.info("***************************************************"); LOG.info(" Start nGrinder Agent ..."); String consoleIP = StringUtils.isNotEmpty(controllerIp) ? controllerIp : agentConfig.getAgentProperties().getProperty("agent.console.ip", "127.0.0.1"); if (!NetworkUtil.isValidIP(consoleIP)) { LOG.error("Hey!! {} does not seems like IP. Try to resolve the ip by {}.", consoleIP, consoleIP); InetAddress byName; try { byName = InetAddress.getByName(consoleIP); consoleIP = byName.getHostAddress(); agentConfig.getAgentProperties().setProperty("agent.console.ip", consoleIP); LOG.info("Console IP is resolved as {}.", consoleIP); } catch (UnknownHostException e) { consoleIP = "127.0.0.1"; LOG.info("Console IP resolution is failed. Use 127.0.0.1 instead."); } finally { agentConfig.getAgentProperties().setProperty("agent.console.ip", consoleIP); } } int consolePort = agentConfig.getAgentProperties().getPropertyInt("agent.console.port", AgentControllerCommunicationDefauts.DEFAULT_AGENT_CONTROLLER_SERVER_PORT); String region = agentConfig.getAgentProperties().getProperty("agent.region", ""); LOG.info("with console: {}:{}", consoleIP, consolePort); boolean serverMode = agentConfig.getPropertyBoolean("agent.servermode", false); if (!serverMode) { LOG.info("JVM server mode is disabled. If you turn on ngrinder.servermode in agent.conf." + " It will provide the better agent performance."); } try { String localHostAddress = NetworkUtil.getLocalHostAddress(); System.setProperty("java.rmi.server.hostname", localHostAddress); agentController = new AgentControllerDaemon(localHostAddress); agentController.getAgentController().setAgentConfig(agentConfig); agentController.setRegion(region); agentController.setAgentConfig(agentConfig); agentController.run(consoleIP, consolePort); } catch (Exception e) { LOG.error("ERROR: {}", e.getMessage()); printHelpAndExit("Error while starting Agent", e); } }
From source file:org.nuxeo.launcher.config.ConfigurationGenerator.java
private void evalLoopbackURL() throws ConfigurationException { String loopbackURL = userConfig.getProperty(PARAM_LOOPBACK_URL); if (loopbackURL != null) { log.debug("Using configured loop back url: " + loopbackURL); return;// w w w . j ava 2 s .c o m } InetAddress bindAddress = getBindAddress(); // Address and ports already checked by #checkAddressesAndPorts try { if (bindAddress.isAnyLocalAddress()) { boolean preferIPv6 = "false".equals(System.getProperty("java.net.preferIPv4Stack")) && "true".equals(System.getProperty("java.net.preferIPv6Addresses")); bindAddress = preferIPv6 ? InetAddress.getByName("::1") : InetAddress.getByName("127.0.0.1"); log.debug("Bind address is \"ANY\", using local address instead: " + bindAddress); } } catch (UnknownHostException e) { log.debug(e, e); log.error(e.getMessage()); } String httpPort = userConfig.getProperty(PARAM_HTTP_PORT); String contextPath = userConfig.getProperty(PARAM_CONTEXT_PATH); // Is IPv6 or IPv4 ? if (bindAddress instanceof Inet6Address) { loopbackURL = "http://[" + bindAddress.getHostAddress() + "]:" + httpPort + contextPath; } else { loopbackURL = "http://" + bindAddress.getHostAddress() + ":" + httpPort + contextPath; } log.debug("Set as loop back URL: " + loopbackURL); defaultConfig.setProperty(PARAM_LOOPBACK_URL, loopbackURL); }