List of usage examples for java.net InetSocketAddress getHostName
public final String getHostName()
From source file:fr.cls.atoll.motu.processor.wps.TestServiceMetadata.java
public static void DetectProxy() throws Exception { System.setProperty("proxyHost", "proxy.cls.fr"); // adresse IP System.setProperty("proxyPort", "8080"); System.setProperty("socksProxyHost", "proxy.cls.fr"); // System.setProperty("http.proxyHost", "http-proxy.ece.fr"); // System.setProperty("http.proxyPort", "3128"); // System.setProperty("java.net.useSystemProxies", "true"); // List<Proxy> proxyList = ProxySelector.getDefault().select(new URI("http://schemas.opengis.net")); List<Proxy> proxyList = ProxySelector.getDefault().select(new URI("http://opendap.aviso.oceanobs.com")); for (Proxy proxy : proxyList) { System.out.println("Proxy type : " + proxy.type()); InetSocketAddress addr = (InetSocketAddress) proxy.address(); if (addr == null) { System.out.println("DIRECT CONXN"); } else {//from w ww.java2 s . c om System.out.println("Proxy hostname : " + addr.getHostName() + ":" + addr.getPort()); } } }
From source file:org.eclipse.mylyn.commons.net.WebUtil.java
private static void configureHttpClientProxy(HttpClient client, HostConfiguration hostConfiguration, AbstractWebLocation location) {/*from w w w .ja va 2 s . c om*/ String host = WebUtil.getHost(location.getUrl()); Proxy proxy; if (WebUtil.isRepositoryHttps(location.getUrl())) { proxy = location.getProxyForHost(host, IProxyData.HTTPS_PROXY_TYPE); } else { proxy = location.getProxyForHost(host, IProxyData.HTTP_PROXY_TYPE); } if (proxy != null && !Proxy.NO_PROXY.equals(proxy)) { InetSocketAddress address = (InetSocketAddress) proxy.address(); hostConfiguration.setProxy(address.getHostName(), address.getPort()); if (proxy instanceof AuthenticatedProxy) { AuthenticatedProxy authProxy = (AuthenticatedProxy) proxy; Credentials credentials = getCredentials(authProxy.getUserName(), authProxy.getPassword(), address.getAddress()); AuthScope proxyAuthScope = new AuthScope(address.getHostName(), address.getPort(), AuthScope.ANY_REALM); client.getState().setProxyCredentials(proxyAuthScope, credentials); } } else { hostConfiguration.setProxyHost(null); } }
From source file:com.servoy.extensions.plugins.http.HttpProvider.java
public static void setHttpClientProxy(DefaultHttpClient client, String url, String proxyUser, String proxyPassword) {//w w w . j a va 2s. co m String proxyHost = null; int proxyPort = 8080; try { System.setProperty("java.net.useSystemProxies", "true"); URI uri = new URI(url); List<Proxy> proxies = ProxySelector.getDefault().select(uri); if (proxies != null && client != null) { for (Proxy proxy : proxies) { if (proxy.address() != null && proxy.address() instanceof InetSocketAddress) { InetSocketAddress address = (InetSocketAddress) proxy.address(); proxyHost = address.getHostName(); HttpHost host = new HttpHost(address.getHostName(), address.getPort()); client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, host); break; } } } } catch (Exception ex) { Debug.log(ex); } if (proxyHost == null && System.getProperty("http.proxyHost") != null && !"".equals(System.getProperty("http.proxyHost"))) { proxyHost = System.getProperty("http.proxyHost"); try { proxyPort = Integer.parseInt(System.getProperty("http.proxyPort")); } catch (Exception ex) { //ignore } HttpHost host = new HttpHost(proxyHost, proxyPort); client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, host); } if (proxyUser != null) { BasicCredentialsProvider bcp = new BasicCredentialsProvider(); bcp.setCredentials(new AuthScope(proxyHost, proxyPort), new UsernamePasswordCredentials(proxyUser, proxyPassword)); client.setCredentialsProvider(bcp); } }
From source file:davmail.http.DavGatewayHttpClientFacade.java
/** * Update http client configuration (proxy) * * @param httpClient current Http client * @param url target url//from w ww.ja v a 2 s . c o m * @throws DavMailException on error */ public static void configureClient(HttpClient httpClient, String url) throws DavMailException { setClientHost(httpClient, url); /*if (Settings.getBooleanProperty("davmail.enableKerberos", false)) { AuthPolicy.registerAuthScheme("Negotiate", NegotiateScheme.class); ArrayList<String> authPrefs = new ArrayList<String>(); authPrefs.add("Negotiate"); httpClient.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); } else */if (!needNTLM) { ArrayList<String> authPrefs = new ArrayList<String>(); authPrefs.add(AuthPolicy.DIGEST); authPrefs.add(AuthPolicy.BASIC); // exclude NTLM authentication scheme httpClient.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); } boolean enableProxy = Settings.getBooleanProperty("davmail.enableProxy"); boolean useSystemProxies = Settings.getBooleanProperty("davmail.useSystemProxies", Boolean.FALSE); String proxyHost = null; int proxyPort = 0; String proxyUser = null; String proxyPassword = null; try { java.net.URI uri = new java.net.URI(url); if (isNoProxyFor(uri)) { LOGGER.debug("no proxy for " + uri.getHost()); } else if (useSystemProxies) { // get proxy for url from system settings System.setProperty("java.net.useSystemProxies", "true"); List<Proxy> proxyList = getProxyForURI(uri); if (!proxyList.isEmpty() && proxyList.get(0).address() != null) { InetSocketAddress inetSocketAddress = (InetSocketAddress) proxyList.get(0).address(); proxyHost = inetSocketAddress.getHostName(); proxyPort = inetSocketAddress.getPort(); // we may still need authentication credentials proxyUser = Settings.getProperty("davmail.proxyUser"); proxyPassword = Settings.getProperty("davmail.proxyPassword"); } } else if (enableProxy) { proxyHost = Settings.getProperty("davmail.proxyHost"); proxyPort = Settings.getIntProperty("davmail.proxyPort"); proxyUser = Settings.getProperty("davmail.proxyUser"); proxyPassword = Settings.getProperty("davmail.proxyPassword"); } } catch (URISyntaxException e) { throw new DavMailException("LOG_INVALID_URL", url); } // configure proxy if (proxyHost != null && proxyHost.length() > 0) { httpClient.getHostConfiguration().setProxy(proxyHost, proxyPort); if (proxyUser != null && proxyUser.length() > 0) { AuthScope authScope = new AuthScope(proxyHost, proxyPort, AuthScope.ANY_REALM); // detect ntlm authentication (windows domain name in user name) int backslashindex = proxyUser.indexOf('\\'); if (backslashindex > 0) { httpClient.getState().setProxyCredentials(authScope, new NTCredentials(proxyUser.substring(backslashindex + 1), proxyPassword, "UNKNOWN", proxyUser.substring(0, backslashindex))); } else { httpClient.getState().setProxyCredentials(authScope, new NTCredentials(proxyUser, proxyPassword, "UNKNOWN", "")); } } } }
From source file:org.apache.hadoop.mapreduce.v2.MiniMRYarnCluster.java
public static String getResolvedMRHistoryWebAppURLWithoutScheme(Configuration conf, boolean isSSLEnabled) { InetSocketAddress address = null; if (isSSLEnabled) { address = conf.getSocketAddr(JHAdminConfig.MR_HISTORY_WEBAPP_HTTPS_ADDRESS, JHAdminConfig.DEFAULT_MR_HISTORY_WEBAPP_HTTPS_ADDRESS, JHAdminConfig.DEFAULT_MR_HISTORY_WEBAPP_HTTPS_PORT); } else {// w w w .j a va 2 s .c o m address = conf.getSocketAddr(JHAdminConfig.MR_HISTORY_WEBAPP_ADDRESS, JHAdminConfig.DEFAULT_MR_HISTORY_WEBAPP_ADDRESS, JHAdminConfig.DEFAULT_MR_HISTORY_WEBAPP_PORT); } address = NetUtils.getConnectAddress(address); StringBuffer sb = new StringBuffer(); InetAddress resolved = address.getAddress(); if (resolved == null || resolved.isAnyLocalAddress() || resolved.isLoopbackAddress()) { String lh = address.getHostName(); try { lh = InetAddress.getLocalHost().getCanonicalHostName(); } catch (UnknownHostException e) { //Ignore and fallback. } sb.append(lh); } else { sb.append(address.getHostName()); } sb.append(":").append(address.getPort()); return sb.toString(); }
From source file:org.apache.hadoop.fs.TestFileSystem.java
static void checkPath(MiniDFSCluster cluster, FileSystem fileSys) throws IOException { InetSocketAddress add = cluster.getNameNode().getNameNodeAddress(); // Test upper/lower case fileSys.checkPath(new Path("hdfs://" + add.getHostName().toUpperCase() + ":" + add.getPort())); }
From source file:org.apache.hadoop.hdfsproxy.ProxyHttpServer.java
public ProxyHttpServer(InetSocketAddress addr, Configuration conf) throws IOException { super("", addr.getHostName(), addr.getPort(), 0 <= addr.getPort(), conf); }
From source file:org.fedoraproject.copr.client.impl.RpcTest.java
@Before public void setUp() throws Exception { server = new LocalTestServer(null, null); server.register("/api/*", new HttpMock(this)); server.start();/*from ww w . j av a2 s . c o m*/ InetSocketAddress address = server.getServiceAddress(); url = "http://" + address.getHostName() + ":" + address.getPort(); CoprConfiguration configuration = getConfiguration(); configuration.setUrl(url); CoprService copr = new DefaultCoprService(); session = copr.newSession(configuration); }
From source file:com.googlecode.jmxtrans.connections.SocketFactory.java
/** * Creates the socket and the writer to go with it. *//*from w w w.j av a 2s . c om*/ @Override public Socket makeObject(InetSocketAddress address) throws Exception { Socket socket = new Socket(address.getHostName(), address.getPort()); socket.setKeepAlive(true); return socket; }
From source file:alluxio.cli.job.command.LeaderCommand.java
@Override public int run(CommandLine cl) { try {/*from ww w . j a v a2 s .c om*/ InetSocketAddress address = JobContext.INSTANCE.getJobMasterAddress(); System.out.println(address.getHostName()); } catch (Exception e) { LOG.error("Failed to get the primary job master", e); System.out.println("Failed to get the primary job master."); return -1; } return 0; }