List of usage examples for java.net URI getPort
public int getPort()
From source file:oracle.custom.ui.oauth.vo.OpenIdConfiguration.java
public static OpenIdConfiguration getInstance(String tenantName) throws Exception { if (configMap.containsKey(tenantName.toLowerCase())) { return configMap.get(tenantName.toLowerCase()); }//from w w w . j a va 2 s. c o m String url = ServerUtils.getIDCSBaseURL(tenantName) + endpoint; System.out.println("URL for tenant '" + tenantName + "' is '" + url + "'"); HttpClient client = ServerUtils.getClient(tenantName); URI uri = new URI(url); HttpGet get = new HttpGet(uri); HttpHost host = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); HttpResponse response = client.execute(host, get); try { HttpEntity entity2 = response.getEntity(); String res = EntityUtils.toString(entity2); EntityUtils.consume(entity2); ObjectMapper mapper = new ObjectMapper(); //res = res.replaceAll("secureoracle.idcs.internal.oracle.com:443", "oc-140-86-12-131.compute.oraclecloud.com"); OpenIdConfiguration openIdConfigInstance = mapper.readValue(res, OpenIdConfiguration.class); configMap.put(tenantName.toLowerCase(), openIdConfigInstance); return openIdConfigInstance; } finally { if (response instanceof CloseableHttpResponse) { ((CloseableHttpResponse) response).close(); } } }
From source file:org.lightcouch.URIBuilder.java
public static URIBuilder buildUri(URI uri) { URIBuilder builder = URIBuilder.buildUri().scheme(uri.getScheme()).host(uri.getHost()).port(uri.getPort()) .path(uri.getPath());/*from w ww . j a v a2 s. c o m*/ return builder; }
From source file:org.ow2.bonita.facade.rest.apachehttpclient.ApacheHttpClientUtil.java
public static HttpClient getHttpClient(String serverAddress, String username, String password) throws URISyntaxException { URI serverURI = new URI(serverAddress); DefaultHttpClient client = new DefaultHttpClient(); AuthScope authScope = new AuthScope(serverURI.getHost(), serverURI.getPort(), AuthScope.ANY_REALM, AuthScope.ANY_SCHEME);//from w ww . ja v a 2 s . com UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password); client.getCredentialsProvider().setCredentials(authScope, credentials); return client; }
From source file:com.sap.prd.mobile.ios.mios.SCMUtil.java
public static String getConnectionString(final Properties versionInfo, final boolean hideConfidentialInformation) throws IOException { final String type = versionInfo.getProperty("type"); final StringBuilder connectionString = new StringBuilder(128); if (type != null && type.equals("git")) { final String repo = versionInfo.getProperty("repo"); if (StringUtils.isBlank(repo)) { if (!StringUtils.isBlank(versionInfo.getProperty("repo_1"))) { throw new IllegalStateException( "Multipe git repositories provided. This use case is not supported. Provide only one git repository."); }/*from w w w.ja va 2 s. c o m*/ throw new IllegalStateException("No git repository provided. "); } if (hideConfidentialInformation) { try { URI uri = new URI(repo); int port = uri.getPort(); if (port == -1) { final String scheme = uri.getScheme(); if (scheme != null && gitDefaultPorts.containsKey(scheme)) { port = gitDefaultPorts.get(scheme); } } connectionString.append(port); if (uri.getHost() != null) { connectionString.append(uri.getPath()); } } catch (URISyntaxException e) { throw new IllegalStateException(String.format("Invalid repository uri: %s", repo)); } } else { connectionString.append(PROTOCOL_PREFIX_GIT).append(repo); } } else { final String port = versionInfo.getProperty("port"); if (StringUtils.isBlank(port)) throw new IllegalStateException("No SCM port provided."); final String depotPath = versionInfo.getProperty("depotpath"); if (hideConfidentialInformation) { try { URI perforceUri = new URI("perforce://" + port); int _port = perforceUri.getPort(); if (_port == -1) { _port = PERFORCE_DEFAULT_PORT; } connectionString.append(_port); connectionString.append(depotPath); } catch (URISyntaxException e) { throw new IllegalStateException(String.format("Invalid port: %s", port)); } } else { if (StringUtils.isBlank(depotPath)) throw new IllegalStateException("No depot path provided."); connectionString.append(PROTOCOL_PREFIX_PERFORCE).append(port).append(":") .append(getDepotPath(depotPath)); } } return connectionString.toString(); }
From source file:de.shadowhunt.subversion.RepositoryFactory.java
private static URI sanitise(final URI uri, final Resource path) { try {/*w w w . j a v a 2 s. co m*/ return new URI(uri.getScheme(), DEFAULT_USER_INFO, uri.getHost(), uri.getPort(), path.getValue(), DEFAULT_QUERY, DEFAULT_FRAGMENT); } catch (final URISyntaxException e) { throw new IllegalArgumentException(e.getMessage(), e); } }
From source file:com.microsoft.tfs.core.exceptions.TFSUnauthorizedException.java
/** * Gets a URI string for display, which uses only the scheme, host, and port * from the original URI string./* www . j a va 2s . com*/ * * @param uriString * the original URI string for which authorization failed (must not * be <code>null</code>) * @return a URI string with the display information for the given URI * string (never <code>null</code>) */ private static String getDisplayURIString(final String uriString) { Check.notNull(uriString, "uriString"); //$NON-NLS-1$ String displayURIString; try { final URI serverURI = new URI(uriString); displayURIString = new URI(serverURI.getScheme(), null, serverURI.getHost(), serverURI.getPort(), "/", //$NON-NLS-1$ null, null).toString(); } catch (final URISyntaxException uriSyntaxException) { // This should be very rare. log.error( MessageFormat.format("Could not construct message URI for '{0}', returning raw URI string", //$NON-NLS-1$ uriString), uriSyntaxException); // Fall back to the original URI (with path part and all; better // than nothing for the user) displayURIString = uriString; } return displayURIString; }
From source file:com.ibm.watson.retrieveandrank.app.rest.UtilityFunctions.java
public static CloseableHttpClient createHTTPClient(URI uri, String username, String password) { CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(new AuthScope(uri.getHost(), uri.getPort()), new UsernamePasswordCredentials(username, password)); return HttpClientBuilder.create().setDefaultCredentialsProvider(credentialsProvider) .addInterceptorFirst(new PreemptiveAuthInterceptor()).build(); }
From source file:com.ibm.watson.developer_cloud.retrieve_and_rank.v1.utils.HttpSolrClientUtils.java
/** * Creates the {@link HttpClient} to use with the Solrj * * @param url the Solr server url/* w w w . j a v a2s .c om*/ * @param username the {@link RetrieveAndRank} service username * @param password the {@link RetrieveAndRank} service password * @return the {@link HttpClient} */ public static HttpClient createHttpClient(String url, String username, String password) { URI scopeUri = URI.create(url); BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(new AuthScope(scopeUri.getHost(), scopeUri.getPort()), new UsernamePasswordCredentials(username, password)); HttpClientBuilder builder = HttpClientBuilder.create().setMaxConnTotal(128).setMaxConnPerRoute(32) .setDefaultRequestConfig( RequestConfig.copy(RequestConfig.DEFAULT).setRedirectsEnabled(true).build()) .setDefaultCredentialsProvider(credentialsProvider) .addInterceptorFirst(new PreemptiveAuthInterceptor()); return builder.build(); }
From source file:org.gradle.caching.http.internal.HttpBuildCache.java
/** * Create a safe URI from the given one by stripping out user info. * * @param uri Original URI// w w w . j av a 2s. c o m * @return a new URI with no user info */ private static URI safeUri(URI uri) { try { return new URI(uri.getScheme(), null, uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment()); } catch (URISyntaxException e) { throw UncheckedException.throwAsUncheckedException(e); } }
From source file:io.orchestrate.client.itest.BaseClientTest.java
@BeforeClass public static void setUpClass() { final String apiKey = System.getProperty("orchestrate.apiKey"); if (apiKey == null || apiKey.length() < 1) { throw new IllegalStateException("Cannot run integration tests, 'apiKey' is blank."); }/*from w w w .j av a2 s .com*/ URI uri = URI.create(System.getProperty("orchestrate.host", OrchestrateClient.Builder.DEFAULT_HOST)); String host = uri.getScheme() + "://" + uri.getHost(); int port = uri.getPort(); if (port == -1) { if (uri.getScheme().equals("https")) { port = 443; } else { port = 80; } } boolean ssl = uri.getScheme().equals("https"); client = OrchestrateClient.builder(apiKey).host(host).port(port).useSSL(ssl).build(); }