List of usage examples for java.net URI getHost
public String getHost()
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 a va 2 s .c o m 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(); }
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.//ww w .j av a 2s .c o m * * @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.jaeksoft.searchlib.util.LinkUtils.java
public final static URL getLink(URL currentURL, String href, UrlFilterItem[] urlFilterList, boolean removeFragment) { if (href == null) return null; href = href.trim();//w w w. ja v a 2s . c o m if (href.length() == 0) return null; String fragment = null; try { URI u = URIUtils.resolve(currentURL.toURI(), href); href = u.toString(); href = UrlFilterList.doReplace(u.getHost(), href, urlFilterList); URI uri = URI.create(href); uri = uri.normalize(); String p = uri.getPath(); if (p != null) if (p.contains("/./") || p.contains("/../")) return null; if (!removeFragment) fragment = uri.getRawFragment(); return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), fragment).normalize().toURL(); } catch (MalformedURLException e) { Logging.info(e.getMessage()); return null; } catch (URISyntaxException e) { Logging.info(e.getMessage()); return null; } catch (IllegalArgumentException e) { Logging.info(e.getMessage()); return null; } }
From source file:com.mindquarry.desktop.workspace.SVNProxyHandler.java
public static void applyProxySettings(List<Profile> profiles, String proxyURL, String proxyLogin, String proxyPwd) throws Exception { removeProxySettings();//from w ww. j a v a 2 s . c om Ini ini = getParser(); Ini.Section groups = ini.get("groups"); int number = 0; for (Profile profile : profiles) { URI uri = new URI(profile.getServerURL()); String groupID = GROUP_PREFIX + number++; groups.put(groupID, uri.getHost()); uri = new URI(proxyURL); Ini.Section section = ini.add(groupID); section.put(PROXY_HOST, uri.getHost()); if (uri.getPort() != -1) { section.put(PROXY_PORT, String.valueOf(uri.getPort())); } if (!proxyLogin.equals("")) { section.put(PROXY_USERNAME, proxyLogin); } if (!proxyPwd.equals("")) { section.put(PROXY_PASSWORD, proxyPwd); } } storeConfig(ini); }
From source file:com.microsoft.azure.keyvault.authentication.KeyVaultCredentials.java
private static String getAuthority(URI uri) { String scheme = uri.getScheme(); String host = uri.getHost(); int port = uri.getPort(); StringBuilder builder = new StringBuilder(); if (scheme != null) { builder.append(scheme).append("://"); }//w ww. j a va 2s . c o m builder.append(host); if (port >= 0) { builder.append(':').append(port); } return builder.toString(); }
From source file:de.shadowhunt.subversion.RepositoryFactory.java
private static URI sanitise(final URI uri, final Resource path) { try {//from w w w . jav a 2 s. c o 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.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//from w w w. ja va 2 s.com * @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: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:org.gradle.caching.http.internal.HttpBuildCache.java
/** * Create a safe URI from the given one by stripping out user info. * * @param uri Original URI//from www. j av a 2 s. com * @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:de.shadowhunt.subversion.internal.URIUtils.java
private static URI createURI0(final URI repository, final Resource... resources) throws URISyntaxException { final URIBuilder builder = new URIBuilder(); builder.setScheme(repository.getScheme()); builder.setHost(repository.getHost()); builder.setPort(repository.getPort()); final StringBuilder completePath = new StringBuilder(repository.getPath()); for (final Resource resource : resources) { completePath.append(resource.getValue()); }/*from www.j a v a 2 s .c o m*/ builder.setPath(completePath.toString()); return builder.build(); }