List of usage examples for java.net InetAddress getHostName
public String getHostName()
From source file:com.cyberway.issue.crawler.writer.WARCWriterProcessor.java
/** * Return relevant values as header-like fields (here ANVLRecord, but * spec-defined "application/warc-fields" type when written). Field * names from from DCMI Terms and the WARC/0.17 specification. * //w w w . jav a2 s. c o m * @see com.cyberway.issue.crawler.framework.WriterPoolProcessor#getFirstrecordBody(java.io.File) */ @Override protected String getFirstrecordBody(File orderFile) { ANVLRecord record = new ANVLRecord(7); record.addLabelValue("software", "Heritrix/" + Heritrix.getVersion() + " http://crawler.archive.org"); try { InetAddress host = InetAddress.getLocalHost(); record.addLabelValue("ip", host.getHostAddress()); record.addLabelValue("hostname", host.getHostName()); } catch (UnknownHostException e) { logger.log(Level.WARNING, "unable top obtain local crawl engine host", e); } record.addLabelValue("format", "WARC File Format 0.17"); record.addLabelValue("conformsTo", "http://crawler.archive.org/warc/0.17/WARC0.17ISO.doc"); // Get other values from order.xml try { Document doc = XmlUtils.getDocument(orderFile); addIfNotBlank(record, "operator", XmlUtils.xpathOrNull(doc, "//meta/operator")); addIfNotBlank(record, "publisher", XmlUtils.xpathOrNull(doc, "//meta/organization")); addIfNotBlank(record, "audience", XmlUtils.xpathOrNull(doc, "//meta/audience")); addIfNotBlank(record, "isPartOf", XmlUtils.xpathOrNull(doc, "//meta/name")); String rawDate = XmlUtils.xpathOrNull(doc, "//meta/date"); if (StringUtils.isNotBlank(rawDate)) { Date date; try { date = ArchiveUtils.parse14DigitDate(rawDate); addIfNotBlank(record, "created", ArchiveUtils.getLog14Date(date)); } catch (ParseException e) { logger.log(Level.WARNING, "obtaining warc created date", e); } } addIfNotBlank(record, "description", XmlUtils.xpathOrNull(doc, "//meta/description")); addIfNotBlank(record, "robots", XmlUtils.xpathOrNull(doc, "//newObject[@name='robots-honoring-policy']/string[@name='type']")); addIfNotBlank(record, "http-header-user-agent", XmlUtils.xpathOrNull(doc, "//map[@name='http-headers']/string[@name='user-agent']")); addIfNotBlank(record, "http-header-from", XmlUtils.xpathOrNull(doc, "//map[@name='http-headers']/string[@name='from']")); } catch (IOException e) { logger.log(Level.WARNING, "obtaining warcinfo", e); } // really ugly to return as string, when it may just be merged with // a couple other fields at write time, but changing would require // larger refactoring return record.toString(); }
From source file:voldemort.server.VoldemortServer.java
/** * Compare the configured hostname with all the ip addresses and hostnames * for the server node, and log a warning if there is a mismatch. * *//* www .j a v a2 s . c o m*/ // TODO: VoldemortServer should throw exception if cluster xml, node id, and // server's state are not all mutually consistent. // // "I attempted to do this in the past. In practice its hard since the // hostname strings returned may not exactly match what's in cluster.xml // (ela4-app0000.prod vs ela4-app0000.prod.linkedin.com). And for folks // running with multiple interfaces and stuff in the open source world, not // sure how it would fan out.. // // I am in favour of doing this though.. May be implement a server config, // "strict.hostname.check.on.startup" which is false by default and true for // our environments and our SRE makes sure there is an exact match?" -- // VChandar // // "Strict host name doesn't work? We can always trim the rest before the comparison." // -- LGao private void checkHostName() { try { HashSet<String> ipAddrList = new HashSet<String>(); InetAddress localhost = InetAddress.getLocalHost(); InetAddress[] serverAddrs = InetAddress.getAllByName(localhost.getCanonicalHostName()); ipAddrList.add("localhost"); if (serverAddrs != null && serverAddrs.length > 0) { for (InetAddress addr : serverAddrs) { if (addr.getHostName() != null) ipAddrList.add(addr.getHostName()); if (addr.getHostAddress() != null) ipAddrList.add(addr.getHostAddress()); if (addr.getCanonicalHostName() != null) ipAddrList.add(addr.getCanonicalHostName()); } } if (!ipAddrList.contains(this.identityNode.getHost())) { logger.info("List of all IPs & Hostnames for the current node:" + ipAddrList); logger.info("Configured hostname [" + this.identityNode.getHost() + "] does not seem to match current node."); } } catch (UnknownHostException uhe) { logger.warn("Unable to obtain IP information for current node", uhe); } catch (SecurityException se) { logger.warn("Security Manager does not permit obtaining IP Information", se); } }
From source file:org.apache.hadoop.hdfs.nfs.mount.RpcProgramMountd.java
@Override public XDR mnt(XDR xdr, XDR out, int xid, InetAddress client) { AccessPrivilege accessPrivilege = hostsMatcher.getAccessPrivilege(client); if (accessPrivilege == AccessPrivilege.NONE) { return MountResponse.writeMNTResponse(Nfs3Status.NFS3ERR_ACCES, out, xid, null); }/*from w ww .j a v a 2 s . c o m*/ String path = xdr.readString(); if (LOG.isDebugEnabled()) { LOG.debug("MOUNT MNT path: " + path + " client: " + client); } String host = client.getHostName(); if (LOG.isDebugEnabled()) { LOG.debug("Got host: " + host + " path: " + path); } if (!exports.contains(path)) { LOG.info("Path " + path + " is not shared."); MountResponse.writeMNTResponse(Nfs3Status.NFS3ERR_NOENT, out, xid, null); return out; } FileHandle handle = null; try { HdfsFileStatus exFileStatus = dfsClient.getFileInfo(path); handle = new FileHandle(exFileStatus.getFileId()); } catch (IOException e) { LOG.error("Can't get handle for export:" + path, e); MountResponse.writeMNTResponse(Nfs3Status.NFS3ERR_NOENT, out, xid, null); return out; } assert (handle != null); LOG.info("Giving handle (fileId:" + handle.getFileId() + ") to client for export " + path); mounts.add(new MountEntry(host, path)); MountResponse.writeMNTResponse(Nfs3Status.NFS3_OK, out, xid, handle.getContent()); return out; }
From source file:org.exoplatform.outlook.jcr.ContentLink.java
/** * Instantiates a new content link.//from ww w. ja va 2 s. c om * * @param jcrService the jcr service * @param sessionProviders the session providers * @param finder the finder * @param organization the organization * @param identityRegistry the identity registry * @param cacheService the cache service * @param params the params * @throws ConfigurationException the configuration exception */ public ContentLink(RepositoryService jcrService, SessionProviderService sessionProviders, NodeFinder finder, OrganizationService organization, IdentityRegistry identityRegistry, CacheService cacheService, InitParams params) throws ConfigurationException { this.jcrService = jcrService; this.sessionProviders = sessionProviders; this.finder = finder; this.organization = organization; this.identityRegistry = identityRegistry; this.activeLinks = cacheService.getCacheInstance(LINK_CACHE_NAME); if (params != null) { PropertiesParam param = params.getPropertiesParam("link-configuration"); if (param != null) { config = Collections.unmodifiableMap(param.getProperties()); } else { if (LOG.isDebugEnabled()) { LOG.debug("Property parameters link-configuration not found, will use default settings."); } config = Collections.<String, String>emptyMap(); } } else { if (LOG.isDebugEnabled()) { LOG.debug("Component configuration not found, will use default settings."); } config = Collections.<String, String>emptyMap(); } StringBuilder restUrl = new StringBuilder(); String exoBaseUrl = System.getProperty(EXO_BASE_URL); if (exoBaseUrl == null || exoBaseUrl.toUpperCase().toLowerCase().startsWith("http://localhost")) { // seems we have base URL not set explicitly for the server String schema = config.get(CONFIG_SCHEMA); if (schema == null || (schema = schema.trim()).length() == 0) { schema = "http"; } String host = config.get(CONFIG_HOST); if (host == null || host.trim().length() == 0) { host = null; try { Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); while (host == null && interfaces.hasMoreElements()) { NetworkInterface nic = interfaces.nextElement(); Enumeration<InetAddress> addresses = nic.getInetAddresses(); while (host == null && addresses.hasMoreElements()) { InetAddress address = addresses.nextElement(); if (!address.isLoopbackAddress()) { host = address.getHostName(); } } } } catch (SocketException e) { // cannot get net interfaces } if (host == null) { try { host = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { host = "localhost:8080"; // assume development environment otherwise } } } restUrl.append(schema); restUrl.append("://"); restUrl.append(host); } else { restUrl.append(exoBaseUrl); } restUrl.append('/'); restUrl.append(PortalContainer.getCurrentPortalContainerName()); restUrl.append('/'); restUrl.append(PortalContainer.getCurrentRestContextName()); this.restUrl = restUrl.toString(); LOG.info("Default service URL for content links is " + this.restUrl); }
From source file:org.rhq.plugins.jbossas.JBossASDiscoveryComponent.java
private String getBindingHostname(String bindingAddress) { String bindingHostname = null; if (bindingAddress != null) { try {//from w w w . j ava2 s. c o m InetAddress bindAddr = InetAddress.getByName(bindingAddress); if (!bindAddr.isAnyLocalAddress()) { //if the binding address != 0.0.0.0 bindingHostname = bindAddr.getHostName(); } } catch (UnknownHostException e) { //this should not happen? log.warn("Unknown hostname passed in as the binding address for JBoss AS instance: " + bindingAddress); } } return bindingHostname; }
From source file:com.bright.assetbank.application.servlet.ApplicationActionServlet.java
public void init()/* */ throws ServletException /* */ {//w w w. ja v a 2 s. c om /* */ try /* */ { /* 82 */ setupGlobalSettings(); /* */ } /* */ catch (Throwable te) /* */ { /* 87 */ System.out.println("ApplicationActionServlet.init: Bn2Exception: " + te.getMessage()); /* */ } /* */ /* 91 */ String[] noStoreActions = getServletConfig().getInitParameter("noStoreGetActions") .split("[,\t\n ]+"); /* 92 */ this.m_noStoreActionSet = new HashSet((int) ((noStoreActions.length + 1) * 1.5D)); /* 93 */ this.m_noStoreActionSet.addAll(Arrays.asList(noStoreActions)); /* */ /* 95 */ boolean bSuspendLicenseValidation = false; /* 96 */ boolean bLicenseValid = false; /* 97 */ boolean bLicenseException = false; /* 98 */ int iLicenseDaysLeft = 0; /* 99 */ String sLicenseDate = ""; /* 100 */ String sLicenseType = ""; /* 101 */ boolean bLicenseNeverExpires = false; /* 102 */ boolean bLicenseIPUnbound = false; /* 103 */ boolean bLicenseWebappUnbound = false; /* */ /* 106 */ String sLicenseIPs = ""; /* */ /* 109 */ String sLicenseWebapps = ""; /* */ try /* */ { /* 114 */ LicenseManager licManager = LicenseManager.getInstance(); /* 115 */ bLicenseValid = licManager.isValid(); /* 116 */ iLicenseDaysLeft = licManager.daysLeft(); /* 117 */ sLicenseIPs = licManager.getFeature("IP"); /* 118 */ sLicenseWebapps = licManager.getFeature("Webapp"); /* 119 */ sLicenseDate = licManager.getFeature("Expiration"); /* 120 */ sLicenseType = licManager.getFeature("Type"); /* */ } /* */ catch (Throwable e) /* */ { /* 124 */ bLicenseValid = false; /* 125 */ bLicenseException = true; /* */ } /* */ /* 128 */ bLicenseNeverExpires = (iLicenseDaysLeft == 0) && ((sLicenseDate == null) || (sLicenseDate.length() == 0) || (sLicenseDate.compareToIgnoreCase("never") == 0)); /* 129 */ bLicenseIPUnbound = (sLicenseIPs == null) || (sLicenseIPs.length() == 0); /* 130 */ bLicenseWebappUnbound = (sLicenseWebapps == null) || (sLicenseWebapps.length() == 0); /* */ /* 133 */ boolean bIPValid = false; /* 134 */ boolean bIPException = false; /* 135 */ String sLocalIPs = ""; /* 136 */ Vector vecLocalIPs = new Vector(); /* 137 */ String sValidIP = ""; /* */ /* 139 */ if (bLicenseIPUnbound) /* */ { /* 141 */ bIPValid = true; /* */ } /* */ else /* */ { /* */ try /* */ { /* 148 */ Vector vecLicensedIPs = StringUtil.convertToVector(sLicenseIPs, ","); /* */ /* 151 */ InetAddress ipLocalhost = InetAddress.getLocalHost(); /* 152 */ InetAddress[] arrAddress = InetAddress.getAllByName(ipLocalhost.getHostName()); /* 153 */ for (int i = 0; i < arrAddress.length; i++) /* */ { /* 158 */ String sIP = arrAddress[i].getHostAddress().trim(); /* 159 */ vecLocalIPs.add(sIP); /* 160 */ sLocalIPs = sLocalIPs + sIP + ", "; /* */ } /* */ /* 164 */ Iterator it = vecLicensedIPs.iterator(); /* 165 */ while (it.hasNext()) /* */ { /* 167 */ String sLicensedIP = (String) it.next(); /* */ /* 169 */ Iterator itLocal = vecLocalIPs.iterator(); /* 170 */ while (itLocal.hasNext()) /* */ { /* 172 */ String sLocalIP = (String) itLocal.next(); /* */ /* 174 */ if (sLicensedIP.trim().compareToIgnoreCase(sLocalIP) == 0) /* */ { /* 176 */ bIPValid = true; /* 177 */ sValidIP = sLocalIP; /* 178 */ break; /* */ } /* */ } /* */ /* 182 */ if (bIPValid) /* */ { /* */ break; /* */ } /* */ } /* */ /* */ } /* */ catch (UnknownHostException e) /* */ { /* 191 */ bIPValid = false; /* 192 */ bIPException = true; /* */ } /* */ /* */ } /* */ /* 197 */ boolean bWebappValid = false; /* 198 */ String sLocalWebapp = ""; /* */ /* 200 */ if (bLicenseWebappUnbound) /* */ { /* 202 */ bWebappValid = true; /* */ } /* */ else /* */ { /* 207 */ Vector vecLicensedWebapps = StringUtil.convertToVector(sLicenseWebapps, ","); /* */ /* 210 */ String sApplicationPath = getServletContext().getRealPath(""); /* 211 */ File dir = new File(sApplicationPath); /* 212 */ sLocalWebapp = dir.getName(); /* */ /* 215 */ Iterator it = vecLicensedWebapps.iterator(); /* 216 */ while (it.hasNext()) /* */ { /* 218 */ String sLicensedWebapp = (String) it.next(); /* */ /* 220 */ if (sLicensedWebapp.trim().compareToIgnoreCase(sLocalWebapp) == 0) /* */ { /* 222 */ bWebappValid = true; /* 223 */ break; /* */ } /* */ } /* */ /* */ } /* */ /* 229 */ boolean bTypeValid = false; /* */ /* 231 */ bTypeValid = checkLicenseType(sLicenseType); /* */ /* 234 */ if (((!bLicenseValid) || (!bIPValid) || (!bWebappValid) || (!bTypeValid)) && (!bSuspendLicenseValidation)) /* */ { /* 236 */ GlobalApplication.getInstance().suspendWebsite(); /* */ } /* */ /* 240 */ if (AssetBankSettings.isApplicationUpdateInProgress()) /* */ { /* 243 */ GlobalApplication.getInstance().setSkipStartups(true); /* */ } /* */ /* 247 */ if (AssetBankSettings.getRequiresEndorsedLibs()) /* */ { /* 249 */ addEndorsedLibToSystemProperties(); /* */ } /* */ /* 253 */ super.init(); /* */ /* 256 */ if (!bLicenseValid) /* */ { /* 258 */ GlobalApplication.getInstance().getLogger() .error("ApplicationActionServlet.init: License validation failed."); /* */ } /* 260 */ if (bLicenseException) /* */ { /* 262 */ GlobalApplication.getInstance().getLogger().error( "ApplicationActionServlet.init: Error in license validation is most likely due to missing license file. Check under WEB-INF/classes."); /* */ } /* 264 */ if (!bTypeValid) /* */ { /* 266 */ GlobalApplication.getInstance().getLogger().info( "ApplicationActionServlet.init: License validation failed: License is of the incorrect type"); /* */ } /* 268 */ if (bIPValid) /* */ { /* 270 */ GlobalApplication.getInstance().getLogger() .info("ApplicationActionServlet.init: License valid for IP address: " + sValidIP); /* */ } /* */ else /* */ { /* 274 */ GlobalApplication.getInstance().getLogger() .error("ApplicationActionServlet.init: License validation failed: IP address " + sLocalIPs + " not in permitted range: " + sLicenseIPs); /* */ } /* 276 */ if (bIPException) /* */ { /* 278 */ GlobalApplication.getInstance().getLogger() .error("ApplicationActionServlet.init: Error in reading IP address of local host server."); /* */ } /* 280 */ if (bWebappValid) /* */ { /* 282 */ GlobalApplication.getInstance().getLogger() .info("ApplicationActionServlet.init: License valid for webapp: " + sLocalWebapp); /* */ } /* */ else /* */ { /* 286 */ GlobalApplication.getInstance().getLogger() .error("ApplicationActionServlet.init: License validation failed: webapp " + sLocalWebapp + " not in permitted range: " + sLicenseWebapps); /* */ } /* */ /* 289 */ if ((bLicenseNeverExpires) && (bLicenseValid)) /* */ { /* 291 */ GlobalApplication.getInstance().getLogger() .info("ApplicationActionServlet.init: License never expires."); /* */ } /* */ else /* */ { /* 295 */ if (iLicenseDaysLeft < 0) /* */ { /* 297 */ GlobalApplication.getInstance().getLogger() .error("ApplicationActionServlet.init: License expired!"); /* */ } /* 299 */ GlobalApplication.getInstance().getLogger() .info("ApplicationActionServlet.init: License days left: " + iLicenseDaysLeft); /* */ } /* */ /* 303 */ GlobalApplication.getInstance().getLogger().info( "ApplicationActionServlet.init: Application Version: " + AssetBankSettings.getApplicationVersion()); /* */ /* 307 */ ABUserProfile.setUserProfileFactory(new ABUserProfileFactory()); /* */ /* 312 */ HTTPUtil.setProxySettings(); /* */ }
From source file:org.apache.hadoop.hdfs.server.blockmanagement.DatanodeManager.java
/** * Checks if name resolution was successful for the given address. If IP * address and host name are the same, then it means name resolution has * failed. As a special case, local addresses are also considered * acceptable. This is particularly important on Windows, where 127.0.0.1 * does/*from w w w . jav a 2s. c o m*/ * not resolve to "localhost". * * @param address * InetAddress to check * @return boolean true if name resolution successful or address is local */ private static boolean isNameResolved(InetAddress address) { String hostname = address.getHostName(); String ip = address.getHostAddress(); return !hostname.equals(ip) || NetUtils.isLocalAddress(address); }
From source file:org.apache.synapse.commons.datasource.JNDIBasedDataSourceRepository.java
private Properties createJNDIEnvironment(Properties dsProperties, String name) { String namingFactory = DataSourceConstants.DEFAULT_IC_FACTORY; String providerUrl = null;/*from w ww . ja v a2 s . com*/ int port = DataSourceConstants.DEFAULT_PROVIDER_PORT; String providerPort = null; // setting naming provider Properties jndiEvn = new Properties(); //This is needed for PerUserPoolDatasource if (dsProperties != null && !dsProperties.isEmpty()) { if (log.isDebugEnabled()) { log.debug("Using properties " + dsProperties + " to create JNDI Environment"); } StringBuffer buffer = new StringBuffer(); buffer.append(DataSourceConstants.PROP_SYNAPSE_PREFIX_DS); buffer.append(DataSourceConstants.DOT_STRING); if (name != null && !"".equals(name)) { buffer.append(name); buffer.append(DataSourceConstants.DOT_STRING); } // The prefix for root level jndiProperties String rootPrefix = buffer.toString(); namingFactory = MiscellaneousUtil.getProperty(dsProperties, rootPrefix + DataSourceConstants.PROP_IC_FACTORY, DataSourceConstants.DEFAULT_IC_FACTORY); //Provider URL providerUrl = MiscellaneousUtil.getProperty(dsProperties, rootPrefix + DataSourceConstants.PROP_PROVIDER_URL, null); providerPort = MiscellaneousUtil.getProperty(dsProperties, rootPrefix + DataSourceConstants.PROP_PROVIDER_PORT, String.valueOf(DataSourceConstants.DEFAULT_PROVIDER_PORT)); } jndiEvn.put(Context.INITIAL_CONTEXT_FACTORY, namingFactory); if (providerUrl != null && !"".equals(providerUrl)) { if (log.isDebugEnabled()) { log.debug("Using provided initial context provider url :" + providerUrl); } } else { if (log.isDebugEnabled()) { log.debug("No initial context provider url...creaeting a new one"); } String providerHost = "localhost"; try { InetAddress addr = InetAddress.getLocalHost(); if (addr != null) { String hostname = addr.getHostName(); if (hostname == null) { String ipAddr = addr.getHostAddress(); if (ipAddr != null) { providerHost = ipAddr; } } else { providerHost = hostname; } } } catch (UnknownHostException e) { log.warn("Unable to determine hostname or IP address.. Using localhost", e); } // default port for RMI registry if (providerPort != null) { try { port = Integer.parseInt(providerPort); } catch (NumberFormatException ignored) { } } // Create a RMI local registry RMIRegistryController.getInstance().createLocalRegistry(port); cachedPorts.add(port); providerUrl = "rmi://" + providerHost + ":" + port; } jndiEvn.put(Context.PROVIDER_URL, providerUrl); log.info("DataSources will be registered in the JNDI context with provider PROP_URL : " + providerUrl); return jndiEvn; }
From source file:com.cloud.utils.net.NetUtils.java
public static String getHostName() { try {// w w w . j a v a2s . c o m final InetAddress localAddr = InetAddress.getLocalHost(); if (localAddr != null) { return localAddr.getHostName(); } } catch (final UnknownHostException e) { s_logger.warn("UnknownHostException when trying to get host name. ", e); } return "localhost"; }
From source file:org.jboss.dashboard.profiler.Profiler.java
protected StringBuffer appendServerSettings(StringBuffer buffer) { buffer.append("<h4>SERVER SETTINGS</h4>"); buffer.append("<table border=\"0\" cellpadding=\"1\" cellspacing=\"2\">"); try {/*from w w w . j a va2s.c o m*/ InetAddress localhost = InetAddress.getLocalHost(); buffer.append("<tr><td align=\"left\">Host name</td>"); buffer.append("<td align=\"left\">= ").append(localhost.getHostName()).append("</td></tr>"); buffer.append("<tr><td align=\"left\">Host IP </td>"); buffer.append("<td align=\"left\">= ").append(localhost.getHostAddress()).append("</td></tr>"); } catch (UnknownHostException e) { buffer.append("<tr><td align=\"left\">Host name</td>"); buffer.append("<td align=\"left\">= Unknown</td></tr>"); } buffer.append("</table>"); return buffer; }