List of usage examples for java.net URL getHost
public String getHost()
From source file:crawler.java.edu.uci.ics.crawler4j.robotstxt.RobotstxtServer.java
private static String getHost(URL url) { return url.getHost().toLowerCase(); }
From source file:com.moss.appkeep.tools.cache.SimpleAppkeepComponentCache.java
private static String dirNameForUrl(String url) { try {/* w ww . j ava2s. c o m*/ URL u = new URL(url); return u.getProtocol() + "_" + u.getHost() + "_" + u.getPort() + "_" + u.getPath().replaceAll(Pattern.quote("/"), "_"); } catch (MalformedURLException e) { throw new RuntimeException(e); } }
From source file:Main.java
public static String makeGETrequest(String url) throws MalformedURLException { String result = ""; URL requestURL = new URL(url); result += "GET " + requestURL.getFile() + " HTTP/1.1"; result += NEWLINE;//from www . j av a 2s . c o m result += "Host: " + requestURL.getHost() + ":" + (requestURL.getPort() > 0 ? requestURL.getPort() : 80); result += NEWLINE; result += "Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"; result += NEWLINE; result += "Connection: close"; result += NEWLINE; result += NEWLINE; return result; }
From source file:com.sonyericsson.hudson.plugins.gerrit.trigger.utils.HttpUtils.java
/** * @param config Gerrit Server Configuration. * @param url URL to get./*from ww w . java 2 s . c o m*/ * @return httpresponse. * @throws IOException if found. */ public static HttpResponse performHTTPGet(IGerritHudsonTriggerConfig config, String url) throws IOException { DefaultHttpClient httpclient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); if (config.getGerritProxy() != null && !config.getGerritProxy().isEmpty()) { try { URL proxyUrl = new URL(config.getGerritProxy()); HttpHost proxy = new HttpHost(proxyUrl.getHost(), proxyUrl.getPort(), proxyUrl.getProtocol()); httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } catch (MalformedURLException e) { logger.error("Could not parse proxy URL, attempting without proxy.", e); } } httpclient.getCredentialsProvider().setCredentials(new AuthScope(null, -1), config.getHttpCredentials()); HttpResponse execute; return httpclient.execute(httpGet); }
From source file:com.calmio.calm.integration.Helpers.HTTPHandler.java
private static CredentialsProvider getCredentialsProvider(String url, String user, String pwd) throws URISyntaxException, MalformedURLException { CredentialsProvider credsProvider = new BasicCredentialsProvider(); URL uri = new URL(url); String domain = uri.getHost(); domain = domain.startsWith("www.") ? domain.substring(4) : domain; credsProvider.setCredentials(new AuthScope(domain, uri.getPort()), (Credentials) new UsernamePasswordCredentials(user, pwd)); return credsProvider; }
From source file:in.flipbrain.Utils.java
public static String getVideoId(String url) throws MalformedURLException { URL u = new URL(url); String host = u.getHost(); if (host.equals("youtu.be")) { return u.getPath(); } else if (host.equals("www.youtube.com")) { String path = u.getPath(); if (path.contains("embed")) { return path.substring(path.indexOf("/")); } else {/*ww w . j a v a2 s . co m*/ String query = u.getQuery(); String[] parts = query.split("&"); for (String p : parts) { if (p.startsWith("v=")) { return p.substring(2); } } } } return null; }
From source file:de.fhg.iais.asc.ASC.java
private static void setGlobalProxy(List<AscConfiguration> configs) { for (AscConfiguration config : configs) { String proxyUrl = config.get(AscConfiguration.PROXY, ""); try {/*from w ww . j av a 2 s .com*/ if (!Strings.isNullOrEmpty(proxyUrl)) { URL url = new URL(proxyUrl); String host = url.getHost(); String port = String.valueOf(url.getPort()); System.setProperty("http.proxyHost", host); System.setProperty("http.proxyPort", port); System.setProperty("https.proxyHost", host); System.setProperty("https.proxyPort", port); } } catch (Exception e) { System.setProperty("http.proxyHost", null); System.setProperty("http.proxyPort", null); System.setProperty("https.proxyHost", null); System.setProperty("https.proxyPort", null); continue; } } }
From source file:com.threadswarm.imagefeedarchiver.FeedUtils.java
/** * Returns a hierarchical {@code URI} constructed from individual components * of the supplied {@code urlString} argument. * <p>/*from ww w . j av a 2 s. co m*/ * The {@code urlString} argument is first used to instantiate a {@code URL} * which in turn is used to construct a {@code URI} based on the individual * components of the former. This more robust then simply calling {@code URL.toURI()}. * * @param urlString the {@code String} based representation of a URL * @return a {@code URI} constructed from the individual URL components * @throws URISyntaxException if a valid {@code URI} cannot be constructed from the supplied {@code urlString} argument * @throws MalformedURLException if the {@code urlString} cannot be used to instantiate a {@code URL} */ public static URI getUriFromUrlString(String urlString) throws URISyntaxException, MalformedURLException { URL url = new URL(urlString); return new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()); }
From source file:Urls.java
public static String getNoRefForm(URL url) { String host = url.getHost(); int port = url.getPort(); String portText = port == -1 ? "" : ":" + port; String userInfo = url.getUserInfo(); String userInfoText = userInfo == null || userInfo.length() == 0 ? "" : userInfo + "@"; String hostPort = host == null || host.length() == 0 ? "" : "//" + userInfoText + host + portText; return url.getProtocol() + ":" + hostPort + url.getFile(); }
From source file:com.moki.touch.util.UrlUtil.java
/** * This method determines if we are able to download a vimeo video from the current url * @param url a url that redirects to a vimeo video * @return true if it is a downloadable vimeo link */// w w w.j ava 2s .c om public static boolean isCachebleVimeoLink(String url) { boolean isDownloadableVimeoLink = false; try { URL vimeoUrl = new URL(url); isDownloadableVimeoLink = vimeoUrl.getHost().contains("vimeo") && vimeoUrl.getPath().contains("download"); } catch (MalformedURLException e) { Log.i(UrlUtil.class.getSimpleName(), "url passed to isCacheblevimeoLink was malformed"); } return isDownloadableVimeoLink; }