List of usage examples for java.net URI getPort
public int getPort()
From source file:org.hawkular.client.RestFactory.java
public T createAPI(URI uri, String userName, String password) { HttpClient httpclient = null;//from ww w . j av a 2 s .c o m if (uri.toString().startsWith("https")) { httpclient = getHttpClient(); } else { httpclient = HttpClientBuilder.create().build(); } ResteasyClient client = null; if (userName != null) { HttpHost targetHost = new HttpHost(uri.getHost(), uri.getPort()); CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials(userName, password)); // Create AuthCache instance AuthCache authCache = new BasicAuthCache(); // Generate BASIC scheme object and add it to the local auth cache BasicScheme basicAuth = new BasicScheme(); authCache.put(targetHost, basicAuth); // Add AuthCache to the execution context HttpClientContext context = HttpClientContext.create(); context.setCredentialsProvider(credsProvider); context.setAuthCache(authCache); ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpclient, context); client = new ResteasyClientBuilder().httpEngine(engine).build(); } else { ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(getHttpClient()); client = new ResteasyClientBuilder().httpEngine(engine).build(); } client.register(JacksonJaxbJsonProvider.class); client.register(JacksonObjectMapperProvider.class); client.register(RestRequestFilter.class); client.register(RestResponseFilter.class); client.register(HCJacksonJson2Provider.class); ProxyBuilder<T> proxyBuilder = client.target(uri).proxyBuilder(apiClassType); if (classLoader != null) { proxyBuilder = proxyBuilder.classloader(classLoader); } return proxyBuilder.build(); }
From source file:cn.isif.util_plus.http.client.util.URIBuilder.java
private void digestURI(final URI uri) { this.scheme = uri.getScheme(); this.encodedSchemeSpecificPart = uri.getRawSchemeSpecificPart(); this.encodedAuthority = uri.getRawAuthority(); this.host = uri.getHost(); this.port = uri.getPort(); this.encodedUserInfo = uri.getRawUserInfo(); this.userInfo = uri.getUserInfo(); this.encodedPath = uri.getRawPath(); this.path = uri.getPath(); this.encodedQuery = uri.getRawQuery(); this.queryParams = parseQuery(uri.getRawQuery()); this.encodedFragment = uri.getRawFragment(); this.fragment = uri.getFragment(); }
From source file:com.intuit.karate.http.apache.ApacheHttpClient.java
@Override public void configure(HttpConfig config) { clientBuilder = HttpClientBuilder.create(); cookieStore = new BasicCookieStore(); clientBuilder.setDefaultCookieStore(cookieStore); AtomicInteger counter = new AtomicInteger(); clientBuilder.addInterceptorLast(new RequestLoggingInterceptor(counter)); clientBuilder.addInterceptorLast(new ResponseLoggingInterceptor(counter)); if (config.isSslEnabled()) { // System.setProperty("jsse.enableSNIExtension", "false"); String sslAlgorithm = config.getSslAlgorithm(); logger.info("ssl enabled, initializing generic trusted certificate / key-store with algorithm: {}", sslAlgorithm);// w w w. j a va2 s . c om SSLContext sslContext = HttpUtils.getSslContext(sslAlgorithm); SSLConnectionSocketFactory socketFactory = new LenientSslConnectionSocketFactory(sslContext, new NoopHostnameVerifier()); clientBuilder.setSSLSocketFactory(socketFactory); } RequestConfig.Builder configBuilder = RequestConfig.custom().setConnectTimeout(config.getConnectTimeout()) .setSocketTimeout(config.getReadTimeout()); clientBuilder.setDefaultRequestConfig(configBuilder.build()); if (config.getProxyUri() != null) { try { URI proxyUri = new URIBuilder(config.getProxyUri()).build(); clientBuilder.setProxy(new HttpHost(proxyUri.getHost(), proxyUri.getPort(), proxyUri.getScheme())); if (config.getProxyUsername() != null && config.getProxyPassword() != null) { CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(proxyUri.getHost(), proxyUri.getPort()), new UsernamePasswordCredentials(config.getProxyUsername(), config.getProxyPassword())); clientBuilder.setDefaultCredentialsProvider(credsProvider); } } catch (Exception e) { throw new RuntimeException(e); } } }
From source file:org.soyatec.windowsazure.authenticate.SharedKeyCredentialsWrapper.java
/** * Replace the uri container name.//from w ww. j a va 2 s. c o m * * @param uri * @param containerName * @return The uri after be replaced the container name with the input * containerName. */ private URI replaceContainerName(URI uri, String containerName) { if (containerName == null) { return uri; } try { String host = uri.getPath(); String[] temp = host.split("/"); temp[0] = containerName; return URIUtils.createURI(uri.getScheme(), uri.getHost(), uri.getPort(), join("/", temp), (uri.getQuery() == null ? Utilities.emptyString() : uri.getQuery()), uri.getFragment()); } catch (URISyntaxException e) { Logger.error("", e); } return uri; }
From source file:com.cloudant.client.api.CloudantClient.java
private Map<String, String> parseAccount(String account) { assertNotEmpty(account, "accountName"); this.accountName = account; Map<String, String> h = new HashMap<String, String>(); if (account.startsWith("http://") || account.startsWith("https://")) { // user is specifying a uri try {/*from ww w . j a v a2 s. c om*/ URI uri = new URI(account); uri.getPort(); h.put("scheme", uri.getScheme()); h.put("hostname", uri.getHost()); h.put("port", new Integer(uri.getPort()).toString()); } catch (URISyntaxException e) { } } else { h.put("scheme", "https"); h.put("hostname", account + ".cloudant.com"); h.put("port", "443"); } return h; }
From source file:org.fao.geonet.utils.AbstractHttpRequest.java
protected ClientHttpResponse doExecute(final HttpRequestBase httpMethod) throws IOException { return requestFactory.execute(httpMethod, new Function<HttpClientBuilder, Void>() { @Nullable/*from w w w .j av a 2 s. c om*/ @Override public Void apply(@Nonnull HttpClientBuilder input) { final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); if (credentials != null) { final URI uri = httpMethod.getURI(); HttpHost hh = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); credentialsProvider.setCredentials(new AuthScope(hh), credentials); // Preemptive authentication if (isPreemptiveBasicAuth()) { // Create AuthCache instance AuthCache authCache = new BasicAuthCache(); // Generate BASIC scheme object and add it to the local auth cache BasicScheme basicAuth = new BasicScheme(); authCache.put(hh, basicAuth); // Add AuthCache to the execution context httpClientContext = HttpClientContext.create(); httpClientContext.setCredentialsProvider(credentialsProvider); httpClientContext.setAuthCache(authCache); } else { input.setDefaultCredentialsProvider(credentialsProvider); } } else { input.setDefaultCredentialsProvider(credentialsProvider); } if (useProxy) { final HttpHost proxy = new HttpHost(proxyHost, proxyPort); input.setProxy(proxy); if (proxyCredentials != null) { credentialsProvider.setCredentials(new AuthScope(proxy), proxyCredentials); } } input.setRedirectStrategy(new LaxRedirectStrategy()); return null; } }, this); }
From source file:com.microsoftopentechnologies.azchat.web.mediaservice.AzureChatMediaService.java
/** * This method retrieve the MP4 streaming URL from assetInfoFile. * //from ww w . j a va 2 s .c o m * @param streaming * @param streamingAssetFile * @param streamingAsset * @return * @throws Exception */ private String getMP4StreamngURL(AccessPolicyInfo streaming, AssetFileInfo streamingAssetFile, AssetInfo streamingAsset) throws Exception { String streamingURL = null; LocatorInfo locator = mediaService .create(Locator.create(streaming.getId(), streamingAsset.getId(), LocatorType.SAS)); URI mp4Uri = new URI(locator.getPath()); mp4Uri = new URI(mp4Uri.getScheme(), mp4Uri.getUserInfo(), mp4Uri.getHost(), mp4Uri.getPort(), mp4Uri.getPath() + AzureChatConstants.CONSTANT_BACK_SLASH + streamingAssetFile.getName(), mp4Uri.getQuery(), mp4Uri.getFragment()); streamingURL = mp4Uri.toString(); return streamingURL; }
From source file:org.carrot2.workbench.vis.FlashViewPage.java
/** * Construct a HTTP GET. // ww w . j ava2 s. c o m */ private String createGetURI(String uriString, Map<String, Object> customParams) { try { List<NameValuePair> pairs = Lists.newArrayList(); for (Map.Entry<String, Object> e : customParams.entrySet()) { pairs.add(new BasicNameValuePair(e.getKey(), e.getValue().toString())); } URI uri = new URI(uriString); uri = URIUtils.createURI(uri.getScheme(), uri.getHost(), uri.getPort(), uri.getPath(), URLEncodedUtils.format(pairs, "UTF-8"), null); return uri.toString(); } catch (URISyntaxException e) { throw new RuntimeException(e); } }
From source file:com.gistlabs.mechanize.util.apache.URIBuilder.java
private void digestURI(final URI uri) { this.scheme = uri.getScheme(); this.encodedSchemeSpecificPart = uri.getRawSchemeSpecificPart(); this.encodedAuthority = uri.getRawAuthority(); this.host = uri.getHost(); this.port = uri.getPort(); this.encodedUserInfo = uri.getRawUserInfo(); this.userInfo = uri.getUserInfo(); this.encodedPath = uri.getRawPath(); this.path = uri.getPath(); this.encodedQuery = uri.getRawQuery(); this.queryParams = parseQuery(uri.getRawQuery(), Consts.UTF_8); this.encodedFragment = uri.getRawFragment(); this.fragment = uri.getFragment(); }