List of usage examples for java.net InetAddress getCanonicalHostName
public String getCanonicalHostName()
From source file:com.cosmicpush.pub.push.EmailPush.java
public static EmailPush newPush(String toAddress, String fromAddress, String emailSubject, String htmlContent, String callbackUrl, String... traits) { InetAddress remoteAddress = PushUtils.getLocalHost(); return new EmailPush(toAddress, fromAddress, emailSubject, htmlContent, callbackUrl, remoteAddress.getCanonicalHostName(), remoteAddress.getHostAddress(), BeanUtils.toMap(traits)); }
From source file:com.cosmicpush.pub.push.EmailPush.java
public static EmailPush newPush(String toAddress, String fromAddress, String emailSubject, String htmlContent, String callbackUrl, Map<String, String> traits) { InetAddress remoteAddress = PushUtils.getLocalHost(); return new EmailPush(toAddress, fromAddress, emailSubject, htmlContent, callbackUrl, remoteAddress.getCanonicalHostName(), remoteAddress.getHostAddress(), traits); }
From source file:io.fabric8.apiman.gateway.ApimanGatewayStarter.java
public static URL resolveServiceEndpoint(String scheme, String serviceName, String defaultPort) { URL endpoint = null;//from w w w . j a v a 2 s. c o m String host = null; String port = defaultPort; try { //lookup in the current namespace log.info("Looking up service " + serviceName); InetAddress initAddress = InetAddress.getByName(serviceName); host = initAddress.getCanonicalHostName(); log.debug("Resolved host using DNS: " + host); } catch (UnknownHostException e) { log.debug("Could not resolve DNS for " + serviceName + ", trying ENV settings next."); host = KubernetesServices.serviceToHostOrBlank(serviceName); if ("".equals(host)) { return null; } else { log.debug("Resolved " + serviceName + " host using ENV: " + host); } } port = KubernetesServices.serviceToPortOrBlank(serviceName); if ("".equals(port)) { port = defaultPort; log.debug("Defaulting " + serviceName + " port to: " + port); } else { log.debug("Resolved " + serviceName + " port using ENV: " + port); } if (scheme == null) { if (port.endsWith("443")) scheme = "https"; else scheme = "http"; } try { endpoint = new URL(scheme, host, Integer.valueOf(port), ""); } catch (Exception e) { log.error(e.getMessage(), e); } return endpoint; }
From source file:org.apache.hive.hcatalog.templeton.ProxyUserSupport.java
private static String normalizeHostname(String name) { try {/*from w w w . j ava 2 s.com*/ InetAddress address = InetAddress.getByName("localhost".equalsIgnoreCase(name) ? null : name); return address.getCanonicalHostName(); } catch (UnknownHostException ex) { LOG.warn(MessageFormat.format("Unable to normalize hostname [{0}]", name)); return null; } }
From source file:ch.qos.logback.audit.client.ImprovedAuditorFactory.java
public static void setApplicationName(String name) throws AuditException { if (clientApplication != null && clientApplication.getName().equals(name)) { // don't configure again return;//from w ww .j a v a 2s. c o m } if (clientApplication != null && !clientApplication.getName().equals(name)) { throw new IllegalStateException( "Application name " + clientApplication.getName() + " once set cannot be renamed."); } if (OptionHelper.isEmpty(name)) { throw new IllegalArgumentException("Application name cannot be null or empty"); } else { // logger.info("Naming client application as [" + name + "]"); } try { InetAddress address = InetAddress.getLocalHost(); String fqdn = address.getCanonicalHostName(); // logger("Client application host is ["+fqdn+"]."); Application aplication = new Application(name, fqdn); // all is nice and dandy clientApplication = aplication; } catch (UnknownHostException e) { throw new IllegalStateException("Failed to determine the hostname for this host", e); } // defaultAuditor.close(); defaultAuditor = new Auditor(); defaultAuditor.setClientApplication(clientApplication); defaultAuditor.setName(DEFAULT_AUDITOR_NAME); autoConfig(defaultAuditor); checkSanity(defaultAuditor); AuditorFactory.defaultAuditor = defaultAuditor; }
From source file:io.fabric8.apiman.ApimanStarter.java
public static URL resolveServiceEndpoint(String scheme, String serviceName, String defaultPort) { URL endpoint = null;/*w w w . ja v a 2 s . c om*/ String host = null; String port = defaultPort; try { //lookup in the current namespace InetAddress initAddress = InetAddress.getByName(serviceName); host = initAddress.getCanonicalHostName(); log.debug("Resolved host using DNS: " + host); } catch (UnknownHostException e) { log.debug("Could not resolve DNS for " + serviceName + ", trying ENV settings next."); host = KubernetesServices.serviceToHostOrBlank(serviceName); if ("".equals(host)) { return null; } else { log.debug("Resolved " + serviceName + " host using ENV: " + host); } } port = KubernetesServices.serviceToPortOrBlank(serviceName); if ("".equals(port)) { port = defaultPort; log.debug("Defaulting " + serviceName + " port to: " + port); } else { log.debug("Resolved " + serviceName + " port using ENV: " + port); } if (scheme == null) { if (port.endsWith("443")) scheme = "https"; else scheme = "http"; } try { endpoint = new URL(scheme, host, Integer.valueOf(port), ""); } catch (Exception e) { log.error(e.getMessage(), e); } return endpoint; }
From source file:org.apache.hadoop.hive.llap.LlapUtil.java
public static String getAmHostNameFromAddress(InetSocketAddress address, Configuration conf) { if (!HiveConf.getBoolVar(conf, HiveConf.ConfVars.LLAP_DAEMON_AM_USE_FQDN)) { return address.getHostName(); }/* w w w .ja v a 2 s . com*/ InetAddress ia = address.getAddress(); // getCanonicalHostName would either return FQDN, or an IP. return (ia == null) ? address.getHostName() : ia.getCanonicalHostName(); }
From source file:org.apache.solr.handler.admin.SystemInfoHandler.java
/** * Get system info//from w w w . jav a 2s . c om */ private static SimpleOrderedMap<Object> getCoreInfo(SolrCore core) throws Exception { SimpleOrderedMap<Object> info = new SimpleOrderedMap<Object>(); IndexSchema schema = core.getSchema(); info.add("schema", schema != null ? schema.getSchemaName() : "no schema!"); // Host InetAddress addr = InetAddress.getLocalHost(); info.add("host", addr.getCanonicalHostName()); // Now info.add("now", new Date()); // Start Time info.add("start", new Date(core.getStartTime())); // Solr Home SimpleOrderedMap<Object> dirs = new SimpleOrderedMap<Object>(); dirs.add("instance", new File(core.getResourceLoader().getInstanceDir()).getAbsolutePath()); dirs.add("data", new File(core.getDataDir()).getAbsolutePath()); // dirs.add( "index", new File( core.getIndexDir(UpdateHandler.UPDATEPARTION) ).getAbsolutePath() ); info.add("directory", dirs); return info; }
From source file:org.apache.hadoop.mapreduce.security.token.TestDelegationTokenRenewal.java
@BeforeClass public static void setUp() throws Exception { conf = new Configuration(); conf.set("mapred.job.tracker", trackerService); // create a fake FileSystem (MyFS) and assosiate it // with "hdfs" schema. InetAddress iaddr = InetAddress.getByName("localhost"); String dnsName = iaddr.getCanonicalHostName(); final URI uri = new URI(DelegationTokenRenewal.SCHEME + "://" + dnsName + ":" + "0"); conf.setClass("fs." + uri.getScheme() + ".impl", MyFS.class, DistributedFileSystem.class); FileSystem.setDefaultUri(conf, uri); LOG.info("filesystem uri = " + FileSystem.getDefaultUri(conf).toString()); }
From source file:com.cosmicpush.pub.push.LqNotificationPush.java
public static LqNotificationPush newPush(String topic, String summary, String trackingId, Throwable throwable, Collection<LqAttachment> attachments, String callbackUrl, Map<String, String> traits) { InetAddress remoteAddress = PushUtils.getLocalHost(); LqExceptionInfo exceptionInfo = (throwable == null) ? null : LqExceptionInfo.create(throwable); return new LqNotificationPush(topic, summary, trackingId, ZonedDateTime.now(), exceptionInfo, attachments, callbackUrl, remoteAddress.getCanonicalHostName(), remoteAddress.getHostAddress(), traits); }