List of usage examples for java.net URI getPort
public int getPort()
From source file:org.springframework.cloud.stream.binder.rabbit.admin.RabbitManagementUtils.java
public static RestTemplate buildRestTemplate(String adminUri, String user, String password) { BasicCredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(user, password)); HttpClient httpClient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build(); // Set up pre-emptive basic Auth because the rabbit plugin doesn't currently support challenge/response for PUT // Create AuthCache instance AuthCache authCache = new BasicAuthCache(); // Generate BASIC scheme object and add it to the local; from the apache docs... // auth cache BasicScheme basicAuth = new BasicScheme(); URI uri; try {//from w ww. ja v a2s . c o m uri = new URI(adminUri); } catch (URISyntaxException e) { throw new RabbitAdminException("Invalid URI", e); } authCache.put(new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()), basicAuth); // Add AuthCache to the execution context final HttpClientContext localContext = HttpClientContext.create(); localContext.setAuthCache(authCache); RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory(httpClient) { @Override protected HttpContext createHttpContext(HttpMethod httpMethod, URI uri) { return localContext; } }); restTemplate.setMessageConverters( Collections.<HttpMessageConverter<?>>singletonList(new MappingJackson2HttpMessageConverter())); return restTemplate; }
From source file:com.google.cloud.hadoop.util.HttpTransportFactory.java
/** * Parse an HTTP proxy from a String address. * @param proxyAddress The address of the proxy of the form (https?://)HOST:PORT. * @return The URI of the proxy./* w w w. ja v a 2 s .c o m*/ * @throws IllegalArgumentException If the address is invalid. */ @VisibleForTesting static URI parseProxyAddress(@Nullable String proxyAddress) { if (Strings.isNullOrEmpty(proxyAddress)) { return null; } String uriString = proxyAddress; if (!uriString.contains("//")) { uriString = "//" + uriString; } try { URI uri = new URI(uriString); String scheme = uri.getScheme(); String host = uri.getHost(); int port = uri.getPort(); if (!Strings.isNullOrEmpty(scheme) && !scheme.matches("https?")) { throw new IllegalArgumentException( String.format("HTTP proxy address '%s' has invalid scheme '%s'.", proxyAddress, scheme)); } else if (Strings.isNullOrEmpty(host)) { throw new IllegalArgumentException(String.format("Proxy address '%s' has no host.", proxyAddress)); } else if (port == -1) { throw new IllegalArgumentException(String.format("Proxy address '%s' has no port.", proxyAddress)); } else if (!uri.equals(new URI(scheme, null, host, port, null, null, null))) { throw new IllegalArgumentException(String.format("Invalid proxy address '%s'.", proxyAddress)); } return uri; } catch (URISyntaxException e) { throw new IllegalArgumentException(String.format("Invalid proxy address '%s'.", proxyAddress), e); } }
From source file:org.elasticsearch.client.sniff.ElasticsearchHostsSniffer.java
private static HttpHost readHost(String nodeId, JsonParser parser, Scheme scheme) throws IOException { HttpHost httpHost = null;//w w w . ja v a2 s . c o m String fieldName = null; while (parser.nextToken() != JsonToken.END_OBJECT) { if (parser.getCurrentToken() == JsonToken.FIELD_NAME) { fieldName = parser.getCurrentName(); } else if (parser.getCurrentToken() == JsonToken.START_OBJECT) { if ("http".equals(fieldName)) { while (parser.nextToken() != JsonToken.END_OBJECT) { if (parser.getCurrentToken() == JsonToken.VALUE_STRING && "publish_address".equals(parser.getCurrentName())) { URI boundAddressAsURI = URI.create(scheme + "://" + parser.getValueAsString()); httpHost = new HttpHost(boundAddressAsURI.getHost(), boundAddressAsURI.getPort(), boundAddressAsURI.getScheme()); } else if (parser.getCurrentToken() == JsonToken.START_OBJECT) { parser.skipChildren(); } } } else { parser.skipChildren(); } } } //http section is not present if http is not enabled on the node, ignore such nodes if (httpHost == null) { logger.debug("skipping node [" + nodeId + "] with http disabled"); return null; } return httpHost; }
From source file:org.koiroha.jyro.workers.crawler.Crawler.java
/** * Determine the port number of specified uri. Return negative value if * URI scheme is not supported./*w w w. j av a2s.co m*/ * * @param uri URI * @return port number */ private static int getPort(URI uri) { int port = uri.getPort(); if (port >= 0) { return port; } String scheme = uri.getScheme(); if (scheme.equals("http")) { return 80; } else if (scheme.equals("https")) { return 443; } else if (scheme.equals("ftp")) { return 21; } return -1; }
From source file:ee.ria.xroad.proxy.clientproxy.FastestConnectionSelectingSSLSocketFactory.java
private static InetSocketAddress toAddress(URI uri) { return new InetSocketAddress(uri.getHost(), uri.getPort()); }
From source file:io.syndesis.credential.BaseCredentialProvider.java
protected static String callbackUrlFor(final URI baseUrl, final MultiValueMap<String, String> additionalParams) { final String path = baseUrl.getPath(); final String callbackPath = path + "credentials/callback"; try {/* ww w . j a v a 2 s. com*/ final URI base = new URI(baseUrl.getScheme(), null, baseUrl.getHost(), baseUrl.getPort(), callbackPath, null, null); return UriComponentsBuilder.fromUri(base).queryParams(additionalParams).build().toUriString(); } catch (final URISyntaxException e) { throw new IllegalStateException("Unable to generate callback URI", e); } }
From source file:com.opengamma.engine.calcnode.CalculationNodeProcess.java
private static void setConnectionDefaults(final String url) { try {//w ww . j a v a 2 s. c om final URI uri = new URI(url); if (uri.getHost() != null) { System.setProperty("opengamma.engine.calcnode.host", uri.getHost()); } if (uri.getPort() != -1) { System.setProperty("opengamma.engine.calcnode.port", Integer.toString(uri.getPort())); } } catch (URISyntaxException e) { s_logger.warn("Couldn't set connection defaults", e); } }
From source file:com.ibm.ecod.watson.RetrieveAndRankSolrJExample.java
private static HttpClient createHttpClient(String uri, String username, String password) { final URI scopeUri = URI.create(uri); final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(new AuthScope(scopeUri.getHost(), scopeUri.getPort()), new UsernamePasswordCredentials(username, password)); final HttpClientBuilder builder = HttpClientBuilder.create().setMaxConnTotal(128).setMaxConnPerRoute(32) .setDefaultRequestConfig(//from w ww .j a v a 2 s . co m RequestConfig.copy(RequestConfig.DEFAULT).setRedirectsEnabled(true).build()); builder.setDefaultCredentialsProvider(credentialsProvider); return builder.build(); }
From source file:org.kurento.test.services.KurentoServicesTestHelper.java
public static KurentoControlServerManager startKurentoControlServer(String wsUriProp) { JsonRpcClient client = KurentoClientTestFactory.createJsonRpcClient("kcs"); try {/*w w w. j a va 2 s . c o m*/ URI wsUri = new URI(wsUriProp); int port = wsUri.getPort(); String path = wsUri.getPath(); kcs = new KurentoControlServerManager(client, port, path); return kcs; } catch (URISyntaxException e) { throw new KurentoException(KCS_WS_URI_PROP + " invalid format: " + wsUriProp); } }
From source file:io.syndesis.rest.v1.handler.credential.CredentialHandler.java
static URI addFragmentTo(final URI uri, final CallbackStatus status) { try {/*from w ww. j a va 2s.c om*/ final String fragment = SERIALIZER.writeValueAsString(status); return new URI(uri.getScheme(), null, uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), fragment); } catch (JsonProcessingException | URISyntaxException e) { throw new IllegalStateException("Unable to add fragment to URI: " + uri + ", for state: " + status, e); } }