List of usage examples for java.net UnknownHostException getMessage
public String getMessage()
From source file:org.wso2.carbon.appfactory.ext.appserver.LeaderElector.java
private void addEvenListener() { //add listener to Complete Topology Event topologyEventReceiver.addEventListener(new CompleteTopologyEventListener() { @Override//from ww w . j ava2 s .co m protected void onEvent(Event event) { if (log.isDebugEnabled()) { log.debug("[CompleteTopologyEventListener] Received: " + event.getClass()); } try { String currentNodeIp = InetAddress.getLocalHost().getHostAddress(); Map<String, InetAddress> memberIpMap = new HashMap<String, InetAddress>(); for (Service service : ((CompleteTopologyEvent) event).getTopology().getServices()) { for (Cluster cluster : service.getClusters()) { for (Member member : cluster.getMembers()) { MemberStatus memStatus = member.getStatus(); if (MemberStatus.Activated.equals(memStatus)) { memberIpMap.put(member.getMemberIp(), InetAddress.getByName(member.getMemberIp())); } } } /*if the current node ip is not there in the service cluster; it should be a different service cluster*/ if (memberIpMap.get(currentNodeIp) != null) { break; } else { memberIpMap.clear(); } } if (memberIpMap.isEmpty()) { return; } List<InetAddress> memberIpList = new ArrayList<InetAddress>(memberIpMap.values()); Collections.sort(memberIpList, new Comparator<InetAddress>() { @Override public int compare(InetAddress addr1, InetAddress addr2) { byte[] ba1 = addr1.getAddress(); byte[] ba2 = addr2.getAddress(); // general ordering: ipv4 before ipv6 if (ba1.length < ba2.length) { return -1; } if (ba1.length > ba2.length) { return 1; } // we have 2 ips of the same type, so we have to compare each byte for (int i = 0; i < ba1.length; i++) { int b1 = unsignedByteToInt(ba1[i]); int b2 = unsignedByteToInt(ba2[i]); if (b1 == b2) { continue; } if (b1 < b2) { return -1; } else { return 1; } } return 0; } private int unsignedByteToInt(byte b) { return (int) b & 0xFF; } }); if ((memberIpMap.get(currentNodeIp) != null) && currentNodeIp.equals(memberIpList.get(0).getHostAddress())) { isNotifyEligible = true; } else { isNotifyEligible = false; } } catch (UnknownHostException e) { log.error("Unable to identify the host ip " + e.getMessage(), e); } } }); }
From source file:org.cloudifysource.shell.validators.NicAddressValidator.java
@Override public void validate() throws CLIValidationException { ServerSocket serverSocket = null; try {//w ww.j a v a2 s. com if (StringUtils.isBlank(nicAddress)) { nicAddress = Constants.getHostAddress(); } if (StringUtils.isBlank(nicAddress)) { throw new IllegalArgumentException("NIC Address is empty"); } IPUtils.testOpenServerSocket(nicAddress); } catch (UnknownHostException uhe) { // thrown if the host could not be determined. throw new CLIValidationException(uhe, 121, CloudifyErrorMessages.NIC_VALIDATION_ABORTED_UNKNOWN_HOST.getName(), uhe.getMessage()); } catch (IOException ioe) { // thrown if an I/O error occurs when creating the socket or connecting to it. throw new CLIValidationException(ioe, 122, CloudifyErrorMessages.NIC_VALIDATION_ABORTED_IO_ERROR.getName(), nicAddress, ioe.getMessage()); } catch (SecurityException se) { // thrown if a security manager exists and doesn't allow the operation. throw new CLIValidationException(se, 123, CloudifyErrorMessages.NIC_VALIDATION_ABORTED_NO_PERMISSION.getName(), se.getMessage()); } finally { if (serverSocket != null) { try { serverSocket.close(); } catch (Exception e) { //ignore } } } }
From source file:com.baidu.rigel.biplatform.cache.store.service.impl.HazelcastStoreManager.java
/** * HZ??HZ//from w w w . j a va 2s.c o m * * @param configPath * hz? */ public HazelcastStoreManager(HazelcastProperties hazelcastProperties) { // Properties prop = new Properties(); // try { // prop = loadConf(null); // } catch (IOException e) { // LOGGER.warn("load conf error,use default config"); // } Config cfg = new Config(); cfg.getGroupConfig().setName(hazelcastProperties.getGroupUserName()); cfg.getGroupConfig().setPassword(hazelcastProperties.getGroupPassword()); cfg.setInstanceName(hazelcastProperties.getInstanceName()); // cfg.getQueueConfig(EVENT_QUEUE).addItemListenerConfig(new ItemListenerConfig(this.hazelcastQueueItemListener,true)); if (hazelcastProperties.getMancenter().isEnable() && StringUtils.isNotBlank(hazelcastProperties.getMancenter().getUrl())) { cfg.getManagementCenterConfig().setEnabled(true); cfg.getManagementCenterConfig().setUrl(hazelcastProperties.getMancenter().getUrl()); } System.setProperty("hazelcast.socket.bind.any", "false"); String ip = "127.0.0.1"; try { ip = InetAddress.getLocalHost().getHostAddress(); } catch (UnknownHostException e) { LOGGER.warn("get ip error, {}", e.getMessage()); } LOGGER.info("local memchine ip: {}", ip); cfg.getProperties();//.getGroupProperties().SOCKET_SERVER_BIND_ANY cfg.getNetworkConfig().getInterfaces().addInterface(ip); cfg.getNetworkConfig().getInterfaces().setEnabled(true); JoinConfig join = cfg.getNetworkConfig().getJoin(); TcpIpConfig tcpIpConfig = join.getTcpIpConfig(); tcpIpConfig.addMember(hazelcastProperties.getMembers()); if (!tcpIpConfig.getMembers().contains("127.0.0.1")) { tcpIpConfig.addMember("127.0.0.1"); } LOGGER.info("hazelcast members in prop:{}", tcpIpConfig.getMembers()); tcpIpConfig.setEnabled(true); this.hazelcast = Hazelcast.newHazelcastInstance(cfg); this.cacheManager = new HazelcastCacheManager(this.hazelcast); }
From source file:com.qpark.eip.core.spring.lockedoperation.dao.LockedOperationDaoImpl.java
private void setupHostValues() { if (this.hostName == null) { try {//from w w w . j a v a 2 s . co m InetAddress localaddr = InetAddress.getLocalHost(); this.hostAddress = localaddr.getHostAddress(); this.hostName = localaddr.getHostName(); } catch (UnknownHostException e) { this.logger.error(e.getMessage(), e); this.hostName = "localhost"; } } }
From source file:at.ac.tuwien.infosys.Balancer.java
@RequestMapping(value = "/ip", method = RequestMethod.GET) public String getIp() { InetAddress ip;/* w w w . ja v a 2 s.c o m*/ String hostname; try { ip = InetAddress.getLocalHost(); hostname = ip.getHostName(); return "{\"ip\":\"" + ip + "\", \"hostname\":\"" + hostname + "\"}"; } catch (UnknownHostException e) { e.printStackTrace(); return "Error: " + e.getMessage(); } }
From source file:edu.ku.brc.ui.FeedBackSender.java
/** * @param item// w w w .ja va2 s . com * @throws Exception */ protected void send(final FeedBackSenderItem item) throws Exception { if (item != null) { // check the website for the info about the latest version HttpClient httpClient = new HttpClient(); httpClient.getParams().setParameter("http.useragent", getClass().getName()); //$NON-NLS-1$ PostMethod postMethod = new PostMethod(getSenderURL()); // get the POST parameters (which includes usage stats, if we're allowed to send them) NameValuePair[] postParams = createPostParameters(item); postMethod.setRequestBody(postParams); // connect to the server try { httpClient.executeMethod(postMethod); // get the server response String responseString = postMethod.getResponseBodyAsString(); if (StringUtils.isNotEmpty(responseString)) { System.err.println(responseString); } } catch (java.net.UnknownHostException uex) { log.error(uex.getMessage()); } catch (Exception e) { e.printStackTrace(); } } }
From source file:com.up.testjavasdkdemo.ssltest.HttpHandler.java
private void makeRequestWithRetries(HttpUriRequest request) throws IOException { if (isResume && targetUrl != null) { File downloadFile = new File(targetUrl); long fileLen = 0; if (downloadFile.isFile() && downloadFile.exists()) { fileLen = downloadFile.length(); }//ww w . jav a 2s . com if (fileLen > 0) request.setHeader("RANGE", "bytes=" + fileLen + "-"); } boolean retry = true; IOException cause = null; // HttpRequestRetryHandler retryHandler = client.getHttpRequestRetryHandler(); while (retry) { try { if (!isCancelled()) { HttpResponse response = client.execute(request, context); if (!isCancelled()) { handleResponse(response); } } return; } catch (UnknownHostException e) { publishProgress(UPDATE_FAILURE, e, 0, e.getMessage()); return; } catch (IOException e) { cause = e; // if (executionCount >= retryCount) { retry = false; publishProgress(UPDATE_FAILURE, e, 0, e.getMessage()); // } else { // retryHandler.retryRequest(cause, ++executionCount, context); // } } catch (NullPointerException e) { // HttpClient 4.0.x ?bug // http://code.google.com/p/android/issues/detail?id=5255 cause = new IOException("NPE in HttpClient" + e.getMessage()); // if (executionCount >= retryCount) { retry = false; publishProgress(UPDATE_FAILURE, e, 0, e.getMessage()); // } else { // retryHandler.retryRequest(cause, ++executionCount, context); // } } catch (Exception e) { cause = new IOException("Exception" + e.getMessage()); // if (executionCount >= retryCount) { retry = false; publishProgress(UPDATE_FAILURE, e, 0, e.getMessage()); // } else { // retryHandler.retryRequest(cause, ++executionCount, context); // } } finally { } } if (cause != null) throw cause; else throw new IOException(""); }
From source file:org.signserver.server.ListBasedAddressAuthorizer.java
/** * Helper method to extract addresses from configuration properties. Will also set fatal errors for malformed addresses. * // w ww .ja v a 2 s .co m * @param addresses Comma-separated list of IP addresses (taken from the configuration) * @param component Used to prefix a possible error string * @return A set of InetAddress objects representing the list */ private Set<InetAddress> splitAddresses(final String addresses, final String component) { final Set<InetAddress> res = new HashSet<InetAddress>(); final String[] addressArr = addresses.split(","); for (String address : addressArr) { address = address.trim(); if (address.length() > 0) { try { res.add(InetAddress.getByName(address)); } catch (UnknownHostException e) { fatalErrors.add(component + ", illegal address specified: " + e.getMessage()); } } } return res; }
From source file:org.apache.hadoop.net.TestDNS.java
/** * Get the IP addresses of an unknown interface *///from w w w.j a v a 2 s . c o m @Test public void testIPsOfUnknownInterface() throws Exception { try { DNS.getIPs("name-of-an-unknown-interface"); fail("Got an IP for a bogus interface"); } catch (UnknownHostException e) { assertEquals("No such interface name-of-an-unknown-interface", e.getMessage()); } }
From source file:org.apache.jmeter.protocol.http.control.DNSCacheManager.java
/** * {@inheritDoc}/*from w ww . j a v a2s. c o m*/ */ @Override public Object clone() { DNSCacheManager clone = (DNSCacheManager) super.clone(); clone.systemDefaultDnsResolver = new SystemDefaultDnsResolver(); clone.cache = new LinkedHashMap<>(); CollectionProperty dnsServers = getServers(); try { String[] serverNames = new String[dnsServers.size()]; int index = 0; for (JMeterProperty jMeterProperty : dnsServers) { serverNames[index] = jMeterProperty.getStringValue(); index++; } clone.resolver = new ExtendedResolver(serverNames); log.debug("Using DNS Resolvers: " + Arrays.asList(((ExtendedResolver) clone.resolver).getResolvers())); // resolvers will be chosen via round-robin ((ExtendedResolver) clone.resolver).setLoadBalance(true); } catch (UnknownHostException uhe) { log.warn("Failed to create Extended resolver: " + uhe.getMessage()); } return clone; }