List of usage examples for java.net URI getHost
public String getHost()
From source file:android.net.Proxy.java
/** * Return the proxy object to be used for the URL given as parameter. * @param ctx A Context used to get the settings for the proxy host. * @param url A URL to be accessed. Used to evaluate exclusion list. * @return Proxy (java.net) object containing the host name. If the * user did not set a hostname it returns the default host. * A null value means that no host is to be used. * {@hide}/* w ww . ja va2 s. c o m*/ */ public static final java.net.Proxy getProxy(Context ctx, String url) { String host = ""; if (url != null) { URI uri = URI.create(url); host = uri.getHost(); } if (!isLocalHost(host)) { if (sConnectivityManager == null) { sConnectivityManager = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE); } if (sConnectivityManager == null) return java.net.Proxy.NO_PROXY; ProxyProperties proxyProperties = sConnectivityManager.getProxy(); if (proxyProperties != null) { if (!proxyProperties.isExcluded(host)) { return proxyProperties.makeProxy(); } } } return java.net.Proxy.NO_PROXY; }
From source file:com.silverpeas.ical.FeedUtilities.java
public static Calendar convertFeedToCalendar(SyndFeed feed, long eventLength) throws Exception { // Create new calendar Calendar calendar = new Calendar(); PropertyList props = calendar.getProperties(); props.add(new ProdId("-//Silverpeas//iCal4j 1.0//FR")); props.add(Version.VERSION_2_0);//from w ww.j a v a 2 s . com props.add(CalScale.GREGORIAN); // Convert events SyndEntry[] entries = getFeedEntries(feed); ComponentList events = calendar.getComponents(); java.util.Date now = new java.util.Date(); SyndEntry entry; for (SyndEntry entry1 : entries) { entry = entry1; // Convert feed link to iCal URL String url = entry.getLink(); if (url == null || url.length() == 0) { continue; } // Convert feed published date to iCal dates Date date = entry.getPublishedDate(); if (date == null) { date = now; } DateTime startDate = new DateTime(date); // Calculate iCal end date DateTime endDate = new DateTime(date.getTime() + eventLength); // Convert feed title to iCal summary String title = entry.getTitle(); if (title == null || title.length() == 0) { title = url; } else { title = title.trim(); } VEvent event = new VEvent(startDate, endDate, title); // Set event URL PropertyList args = event.getProperties(); URI uri = new URI(url); args.add(new Url(uri)); // Generate location by URL Location location = new Location(uri.getHost()); args.add(location); // Generate UID by URL Uid uid = new Uid(url); args.add(uid); // Convert feed description to iCal description SyndContent syndContent = entry.getDescription(); String content = null; if (syndContent != null) { content = syndContent.getValue(); } if (content == null) { content = url; } Description desc = new Description(content); args.add(desc); // Add converted event events.add(event); } return calendar; }
From source file:org.jboss.as.test.integration.domain.AbstractSSLMasterSlaveTestCase.java
private static CloseableHttpClient createHttpClient(URI mgmtURI) { UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(SLAVE_HOST_USERNAME, SLAVE_HOST_PASSWORD);//from www. j a v a2 s.c om AuthScope authScope = new AuthScope(mgmtURI.getHost(), mgmtURI.getPort()); CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(authScope, credentials); return HttpClients.custom().setDefaultCredentialsProvider(credentialsProvider).build(); }
From source file:gov.nasa.jpl.analytics.util.CommonUtil.java
public static String getHost(String url) { //return InternetDomainName.from(url).topPrivateDomain().toString(); /*if () {/*from www . java 2 s .c o m*/ return InternetDomainName.from(url).topPrivateDomain().toString(); } else { System.out.println("Omg, It's not a valid URL: " + url); return ""; }*/ URI uri = null; try { uri = new URI(url); } catch (URISyntaxException e) { System.out.println("Omg, It's not a valid URL: " + url); // Do Nothing & Return Empty "" return ""; } String host = uri.getHost(); if (host != null) { if (host.startsWith("www.")) { return host.substring(4); } else { return host; } } else { System.out.println("Omg, www not present: " + url); return ""; } }
From source file:annis.libgui.Helper.java
public static String generateCitation(String aql, Set<String> corpora, int contextLeft, int contextRight, String segmentation, int start, int limit) { try {// w ww . ja v a 2s . c o m URI appURI = UI.getCurrent().getPage().getLocation(); return new URI(appURI.getScheme(), null, appURI.getHost(), appURI.getPort(), getContext(), null, StringUtils.join( citationFragment(aql, corpora, contextLeft, contextRight, segmentation, start, limit), "&")).toASCIIString(); } catch (URISyntaxException ex) { log.error(null, ex); } return "ERROR"; }
From source file:URISupport.java
/** * Creates a URI with the given query//w w w . j av a2 s .c om */ public static URI createURIWithQuery(URI uri, String query) throws URISyntaxException { return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), query, uri.getFragment()); }
From source file:URISupport.java
public static URI changeScheme(URI bindAddr, String scheme) throws URISyntaxException { return new URI(scheme, bindAddr.getUserInfo(), bindAddr.getHost(), bindAddr.getPort(), bindAddr.getPath(), bindAddr.getQuery(), bindAddr.getFragment()); }
From source file:com.sun.jersey.client.apache4.ApacheHttpClient4.java
/** * Create a default Apache HTTP client handler. * * @param cc ClientConfig instance. Might be null. * * @return a default Apache HTTP client handler. */// w ww. ja v a 2 s . c o m private static ApacheHttpClient4Handler createDefaultClientHandler(final ClientConfig cc) { Object connectionManager = null; Object httpParams = null; if (cc != null) { connectionManager = cc.getProperties().get(ApacheHttpClient4Config.PROPERTY_CONNECTION_MANAGER); if (connectionManager != null) { if (!(connectionManager instanceof ClientConnectionManager)) { Logger.getLogger(ApacheHttpClient4.class.getName()).log(Level.WARNING, "Ignoring value of property " + ApacheHttpClient4Config.PROPERTY_CONNECTION_MANAGER + " (" + connectionManager.getClass().getName() + ") - not instance of org.apache.http.conn.ClientConnectionManager."); connectionManager = null; } } httpParams = cc.getProperties().get(ApacheHttpClient4Config.PROPERTY_HTTP_PARAMS); if (httpParams != null) { if (!(httpParams instanceof HttpParams)) { Logger.getLogger(ApacheHttpClient4.class.getName()).log(Level.WARNING, "Ignoring value of property " + ApacheHttpClient4Config.PROPERTY_HTTP_PARAMS + " (" + httpParams.getClass().getName() + ") - not instance of org.apache.http.params.HttpParams."); httpParams = null; } } } final DefaultHttpClient client = new DefaultHttpClient((ClientConnectionManager) connectionManager, (HttpParams) httpParams); CookieStore cookieStore = null; boolean preemptiveBasicAuth = false; if (cc != null) { for (Map.Entry<String, Object> entry : cc.getProperties().entrySet()) client.getParams().setParameter(entry.getKey(), entry.getValue()); if (cc.getPropertyAsFeature(ApacheHttpClient4Config.PROPERTY_DISABLE_COOKIES)) client.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.IGNORE_COOKIES); Object credentialsProvider = cc.getProperty(ApacheHttpClient4Config.PROPERTY_CREDENTIALS_PROVIDER); if (credentialsProvider != null && (credentialsProvider instanceof CredentialsProvider)) { client.setCredentialsProvider((CredentialsProvider) credentialsProvider); } final Object proxyUri = cc.getProperties().get(ApacheHttpClient4Config.PROPERTY_PROXY_URI); if (proxyUri != null) { final URI u = getProxyUri(proxyUri); final HttpHost proxy = new HttpHost(u.getHost(), u.getPort(), u.getScheme()); if (cc.getProperties().containsKey(ApacheHttpClient4Config.PROPERTY_PROXY_USERNAME) && cc.getProperties().containsKey(ApacheHttpClient4Config.PROPERTY_PROXY_PASSWORD)) { client.getCredentialsProvider().setCredentials(new AuthScope(u.getHost(), u.getPort()), new UsernamePasswordCredentials( cc.getProperty(ApacheHttpClient4Config.PROPERTY_PROXY_USERNAME).toString(), cc.getProperty(ApacheHttpClient4Config.PROPERTY_PROXY_PASSWORD).toString())); } client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } preemptiveBasicAuth = cc .getPropertyAsFeature(ApacheHttpClient4Config.PROPERTY_PREEMPTIVE_BASIC_AUTHENTICATION); } if (client.getParams().getParameter(ClientPNames.COOKIE_POLICY) == null || !client.getParams() .getParameter(ClientPNames.COOKIE_POLICY).equals(CookiePolicy.IGNORE_COOKIES)) { cookieStore = new BasicCookieStore(); client.setCookieStore(cookieStore); } return new ApacheHttpClient4Handler(client, cookieStore, preemptiveBasicAuth); }
From source file:com.spectralogic.ds3client.NetworkClientImpl.java
private static HttpHost buildHost(final ConnectionDetails connectionDetails) throws MalformedURLException { final URI proxyUri = connectionDetails.getProxy(); if (proxyUri != null) { return new HttpHost(proxyUri.getHost(), proxyUri.getPort(), proxyUri.getScheme()); } else {//from w w w .j av a 2s . c om final URL url = NetUtils.buildUrl(connectionDetails, "/"); return new HttpHost(url.getHost(), NetUtils.getPort(url), url.getProtocol()); } }
From source file:co.cask.cdap.etl.tool.UpgradeTool.java
private static ClientConfig getClientConfig(CommandLine commandLine) throws IOException { String uriStr = commandLine.hasOption("u") ? commandLine.getOptionValue("u") : "localhost:10000"; if (!uriStr.contains("://")) { uriStr = "http://" + uriStr; }//from www.ja v a 2s . c om URI uri = URI.create(uriStr); String hostname = uri.getHost(); int port = uri.getPort(); boolean sslEnabled = "https".equals(uri.getScheme()); ConnectionConfig connectionConfig = ConnectionConfig.builder().setHostname(hostname).setPort(port) .setSSLEnabled(sslEnabled).build(); int readTimeout = commandLine.hasOption("t") ? Integer.parseInt(commandLine.getOptionValue("t")) : DEFAULT_READ_TIMEOUT_MILLIS; ClientConfig.Builder clientConfigBuilder = ClientConfig.builder().setDefaultReadTimeout(readTimeout) .setConnectionConfig(connectionConfig); if (commandLine.hasOption("a")) { String tokenFilePath = commandLine.getOptionValue("a"); File tokenFile = new File(tokenFilePath); if (!tokenFile.exists()) { throw new IllegalArgumentException("Access token file " + tokenFilePath + " does not exist."); } if (!tokenFile.isFile()) { throw new IllegalArgumentException("Access token file " + tokenFilePath + " is not a file."); } String tokenValue = new String(Files.readAllBytes(tokenFile.toPath()), StandardCharsets.UTF_8).trim(); AccessToken accessToken = new AccessToken(tokenValue, 82000L, "Bearer"); clientConfigBuilder.setAccessToken(accessToken); } return clientConfigBuilder.build(); }