List of usage examples for java.net InetSocketAddress getPort
public final int getPort()
From source file:com.intellij.util.net.HttpConfigurable.java
public static List<KeyValue<String, String>> getJvmPropertiesList(final boolean withAutodetection, @Nullable final URI uri) { final HttpConfigurable me = getInstance(); if (!me.USE_HTTP_PROXY && !me.USE_PROXY_PAC) { return Collections.emptyList(); }/*from ww w. j a v a2 s . com*/ final List<KeyValue<String, String>> result = new ArrayList<KeyValue<String, String>>(); if (me.USE_HTTP_PROXY) { final boolean putCredentials = me.KEEP_PROXY_PASSWORD && StringUtil.isNotEmpty(me.PROXY_LOGIN); if (me.PROXY_TYPE_IS_SOCKS) { result.add(KeyValue.create(JavaProxyProperty.SOCKS_HOST, me.PROXY_HOST)); result.add(KeyValue.create(JavaProxyProperty.SOCKS_PORT, String.valueOf(me.PROXY_PORT))); if (putCredentials) { result.add(KeyValue.create(JavaProxyProperty.SOCKS_USERNAME, me.PROXY_LOGIN)); result.add(KeyValue.create(JavaProxyProperty.SOCKS_PASSWORD, me.getPlainProxyPassword())); } } else { result.add(KeyValue.create(JavaProxyProperty.HTTP_HOST, me.PROXY_HOST)); result.add(KeyValue.create(JavaProxyProperty.HTTP_PORT, String.valueOf(me.PROXY_PORT))); result.add(KeyValue.create(JavaProxyProperty.HTTPS_HOST, me.PROXY_HOST)); result.add(KeyValue.create(JavaProxyProperty.HTTPS_PORT, String.valueOf(me.PROXY_PORT))); if (putCredentials) { result.add(KeyValue.create(JavaProxyProperty.HTTP_USERNAME, me.PROXY_LOGIN)); result.add(KeyValue.create(JavaProxyProperty.HTTP_PASSWORD, me.getPlainProxyPassword())); } } } else if (me.USE_PROXY_PAC && withAutodetection && uri != null) { final List<Proxy> proxies = CommonProxy.getInstance().select(uri); // we will just take the first returned proxy, but we have an option to test connection through each of them, // for instance, by calling prepareUrl() if (proxies != null && !proxies.isEmpty()) { for (Proxy proxy : proxies) { if (isRealProxy(proxy)) { final SocketAddress address = proxy.address(); if (address instanceof InetSocketAddress) { final InetSocketAddress inetSocketAddress = (InetSocketAddress) address; if (Proxy.Type.SOCKS.equals(proxy.type())) { result.add(KeyValue.create(JavaProxyProperty.SOCKS_HOST, inetSocketAddress.getHostName())); result.add(KeyValue.create(JavaProxyProperty.SOCKS_PORT, String.valueOf(inetSocketAddress.getPort()))); } else { result.add(KeyValue.create(JavaProxyProperty.HTTP_HOST, inetSocketAddress.getHostName())); result.add(KeyValue.create(JavaProxyProperty.HTTP_PORT, String.valueOf(inetSocketAddress.getPort()))); result.add(KeyValue.create(JavaProxyProperty.HTTPS_HOST, inetSocketAddress.getHostName())); result.add(KeyValue.create(JavaProxyProperty.HTTPS_PORT, String.valueOf(inetSocketAddress.getPort()))); } } } } } } return result; }
From source file:com.buaa.cfs.utils.SecurityUtil.java
/** * Construct the service key for a token * * @param addr InetSocketAddress of remote connection with a token * * @return "ip:port" or "host:port" depending on the value of hadoop.security.token.service.use_ip */// w w w .j a va 2 s . c o m public static Text buildTokenService(InetSocketAddress addr) { String host = null; if (useIpForTokenService) { if (addr.isUnresolved()) { // host has no ip address throw new IllegalArgumentException(new UnknownHostException(addr.getHostName())); } host = addr.getAddress().getHostAddress(); } else { host = StringUtils.toLowerCase(addr.getHostName()); } return new Text(host + ":" + addr.getPort()); }
From source file:davmail.http.DavGatewayHttpClientFacade.java
/** * Update http client configuration (proxy) * * @param httpClient current Http client * @param url target url//w w w. j av a 2s. c om * @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:com.servoy.extensions.plugins.http.HttpProvider.java
public static void setHttpClientProxy(DefaultHttpClient client, String url, String proxyUser, String proxyPassword) {//from www. ja va 2 s . c o 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:org.apache.hadoop.yarn.webapp.util.WebAppUtils.java
private static String getResolvedAddress(InetSocketAddress address) { address = NetUtils.getConnectAddress(address); StringBuilder sb = new StringBuilder(); InetAddress resolved = address.getAddress(); if (resolved == null || resolved.isAnyLocalAddress() || resolved.isLoopbackAddress()) { String lh = address.getHostName(); try {// ww w . ja v a 2 s. com 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:com.mastfrog.scamper.Address.java
public Address(InetSocketAddress a) { this(a.getAddress().getHostAddress(), a.getPort()); }
From source file:io.netlibs.bgp.config.nodes.ClientPortConfigurationDecorator.java
@Override public InetSocketAddress getRemoteAddress() { InetSocketAddress sockAddr = decorated.getRemoteAddress(); if (sockAddr.getPort() == 0) sockAddr = new InetSocketAddress(sockAddr.getAddress(), getDefaultPort()); return sockAddr; }
From source file:io.netlibs.bgp.config.nodes.ServerPortConfigurationDecorator.java
@Override public InetSocketAddress getListenAddress() { InetSocketAddress sockAddr = decorated.getListenAddress(); if (sockAddr.getPort() == 0) sockAddr = new InetSocketAddress(sockAddr.getAddress(), getDefaultPort()); return sockAddr; }
From source file:natalia.dymnikova.cluster.scheduler.impl.ConverterAddresses.java
public Address toAkkaAddress(final InetSocketAddress address) { return Address.apply("akka.tcp", actorSystemName, address.getHostString(), address.getPort()); }
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())); }