List of usage examples for java.net InetSocketAddress getHostName
public final String getHostName()
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(); }// ww w . j a va 2s. co m InetAddress ia = address.getAddress(); // getCanonicalHostName would either return FQDN, or an IP. return (ia == null) ? address.getHostName() : ia.getCanonicalHostName(); }
From source file:com.googlecode.android_scripting.jsonrpc.JsonBuilder.java
private static Object buildInetSocketAddress(InetSocketAddress data) { JSONArray address = new JSONArray(); address.put(data.getHostName()); address.put(data.getPort());//www. j av a 2s.c o m return address; }
From source file:com.github.brandtg.discovery.TestHelixServiceDiscoveryBundle.java
private static void checkServices(List<InetSocketAddress> services) throws Exception { for (InetSocketAddress service : services) { HttpURLConnection conn = (HttpURLConnection) new URL( String.format("http://%s:%d/hello-world", service.getHostName(), service.getPort())) .openConnection(); String result = IOUtils.toString(conn.getInputStream()); Assert.assertEquals(result, "Hello World!"); }//from ww w. j ava 2 s . co m }
From source file:com.yahoo.gondola.container.Utils.java
public static String getAppUri(Config config, String hostId) { InetSocketAddress address = config.getAddressForHost(hostId); Map<String, String> attrs = config.getAttributesForHost(hostId); String appUri = String.format("%s://%s:%s", attrs.get(APP_SCHEME), address.getHostName(), attrs.get(APP_PORT));/*from w ww. j a v a 2 s .co m*/ if (!attrs.containsKey(APP_PORT) || !attrs.containsKey(APP_SCHEME)) { throw new IllegalStateException( String.format("gondola.hosts[%s] is missing either the %s or %s config values", hostId, APP_PORT, APP_SCHEME)); } return appUri; }
From source file:org.openflamingo.remote.thrift.thriftfs.ThriftUtils.java
public static ThriftDelegationToken toThrift(Token<? extends AbstractDelegationTokenIdentifier> delegationToken, InetSocketAddress address) throws java.io.IOException { String serviceAddress = InetAddress.getByName(address.getHostName()).getHostAddress() + ":" + address.getPort();// w w w. ja va 2 s .com delegationToken.setService(new Text(serviceAddress)); DataOutputBuffer out = new DataOutputBuffer(); Credentials ts = new Credentials(); ts.addToken(new Text(serviceAddress), delegationToken); ts.writeTokenStorageToStream(out); byte[] tokenData = new byte[out.getLength()]; System.arraycopy(out.getData(), 0, tokenData, 0, tokenData.length); return new ThriftDelegationToken(ByteBuffer.wrap(tokenData)); }
From source file:org.apache.hadoop.hdfs.qjournal.server.JournalNodeJspHelper.java
/** * Returns the address of the host minimizing DNS lookups. * @param addr/*from w w w . j a v a 2 s . c om*/ * @return */ private static String getHostAddress(InetSocketAddress addr) { String hostToAppend = ""; if (addr.isUnresolved()) { hostToAppend = addr.getHostName(); } else { hostToAppend = addr.getAddress().getHostAddress(); } return hostToAppend; }
From source file:org.apache.tajo.cli.tools.TajoDump.java
private static Pair<String, Integer> getConnectionAddr(TajoConf conf, CommandLine cmd) { String hostName = null;/* w ww. j ava2 s .c o m*/ Integer port = null; if (cmd.hasOption("h")) { hostName = cmd.getOptionValue("h"); } if (cmd.hasOption("p")) { port = Integer.parseInt(cmd.getOptionValue("p")); } InetSocketAddress address = conf.getSocketAddrVar(TajoConf.ConfVars.TAJO_MASTER_CLIENT_RPC_ADDRESS, TajoConf.ConfVars.TAJO_MASTER_UMBILICAL_RPC_ADDRESS); if (hostName == null) { hostName = address.getHostName(); } if (port == null) { port = address.getPort(); } return new Pair<>(hostName, port); }
From source file:android.net.Proxy.java
/** * Returns the preferred proxy to be used by clients. This is a wrapper * around {@link android.net.Proxy#getHost()}. * * @param context the context which will be passed to * {@link android.net.Proxy#getHost()}/* w w w .ja va 2s . c om*/ * @param url the target URL for the request * @note Calling this method requires permission * android.permission.ACCESS_NETWORK_STATE * @return The preferred proxy to be used by clients, or null if there * is no proxy. * {@hide} */ public static final HttpHost getPreferredHttpHost(Context context, String url) { java.net.Proxy prefProxy = getProxy(context, url); if (prefProxy.equals(java.net.Proxy.NO_PROXY)) { return null; } else { InetSocketAddress sa = (InetSocketAddress) prefProxy.address(); return new HttpHost(sa.getHostName(), sa.getPort(), "http"); } }
From source file:com.zimbra.common.httpclient.HttpProxyConfig.java
public static ProxyHostConfiguration getProxyConfig(HostConfiguration hc, String uriStr) { if (!LC.client_use_system_proxy.booleanValue()) return null; URI uri = null;//w w w . ja va 2s . co m try { uri = new URI(uriStr); } catch (URISyntaxException x) { ZimbraLog.net.info(uriStr, x); return null; } //no need to filter out localhost as the DefaultProxySelector will do that. List<Proxy> proxies = ProxySelectors.defaultProxySelector().select(uri); for (Proxy proxy : proxies) { switch (proxy.type()) { case DIRECT: return null; case HTTP: InetSocketAddress addr = (InetSocketAddress) proxy.address(); if (ZimbraLog.net.isDebugEnabled()) { ZimbraLog.net.debug("URI %s to use HTTP proxy %s", safePrint(uri), addr.toString()); } ProxyHostConfiguration nhc = new ProxyHostConfiguration(hc); nhc.setProxy(addr.getHostName(), addr.getPort()); if (proxy instanceof AuthProxy) { nhc.setUsername(((AuthProxy) proxy).getUsername()); nhc.setPassword(((AuthProxy) proxy).getPassword()); } return nhc; case SOCKS: //socks proxy can be handled at socket factory level default: continue; } } return null; }
From source file:es.eucm.eadventure.editor.plugin.vignette.ProxySetup.java
private static void init() { proxyConfig = null;/*from w ww .j a v a 2 s . c om*/ log = Logger.getLogger("es.eucm.eadventure.tracking.prv.service.ProxyConfig"); handler = null; try { handler = new FileHandler("proxy.log"); log.addHandler(handler); } catch (SecurityException e) { handler = null; e.printStackTrace(); } catch (IOException e) { handler = null; e.printStackTrace(); } //Log log = LogFactory.getLog( "es.eucm.eadventure.tracking.prv.service.ProxyConfig" ); log("Setting prop java.net.useSystemProxies=true"); System.setProperty("java.net.useSystemProxies", "true"); Proxy proxy = getProxy(); if (proxy != null) { InetSocketAddress addr = (InetSocketAddress) proxy.address(); if (addr == null) { log("No proxy detected"); System.out.println("NO PROXY"); } else { String host = addr.getHostName(); int port = addr.getPort(); proxyConfig = new ProxyConfig(); proxyConfig.setHostName(host); proxyConfig.setPort("" + port); proxyConfig.setProtocol("http"); log("Proxy detected: host=" + host + " port=" + port); System.setProperty("java.net.useSystemProxies", "false"); System.setProperty("http.proxyHost", host); System.setProperty("http.proxyPort", "" + port); log("Setting up system proxy host & port"); } } System.setProperty("java.net.useSystemProxies", "false"); log("Setting prop java.net.useSystemProxies=false"); init = true; }