List of usage examples for java.net URL getHost
public String getHost()
From source file:com.openteach.diamond.metadata.ServiceURL.java
/** * //w w w.ja v a 2s. c om * @throws MalformedURLException */ private void parse() throws MalformedURLException { int index = strURL.indexOf("://"); URL url = new URL(String.format("http%s", strURL.substring(index))); protocol = strURL.substring(0, index); host = url.getHost(); port = url.getPort(); serviceName = url.getFile(); query = url.getQuery(); }
From source file:juzu.impl.plugin.amd.AmdMaxAgeTestCase.java
@Test @RunAsClient// w w w . j ava 2s. c om public void test() throws Exception { URL applicationURL = applicationURL(); driver.get(applicationURL.toString()); WebElement elt = driver.findElement(By.id("Foo")); URL url = new URL(applicationURL.getProtocol(), applicationURL.getHost(), applicationURL.getPort(), elt.getText()); HttpGet get = new HttpGet(url.toURI()); HttpResponse response = HttpClientBuilder.create().build().execute(get); Header[] cacheControl = response.getHeaders("Cache-Control"); assertEquals(1, cacheControl.length); assertEquals("max-age=1000", cacheControl[0].getValue()); }
From source file:com.predic8.membrane.core.interceptor.swagger.SwaggerRewriterInterceptor.java
@Override public Outcome handleRequest(Exchange exc) throws Exception { ((ServiceProxy) exc.getRule()).setTargetHost(swagger.getHost()); URL url = new URL(swaggerUrl); exc.getDestinations().set(0, url.getProtocol() + "://" + url.getHost() + (url.getPort() < 0 ? "" : ":" + url.getPort()) + exc.getOriginalRequestUri()); return super.handleRequest(exc); }
From source file:web.analyzer.utils.Utils.java
public LinkResult getLinks(Document doc, String hostName) throws IOException { List<Link> linksInfo = new ArrayList<Link>(); int totalInternalLink = 0; int totalExternalLink = 0; Elements links = doc.select("a[href]"); for (Element link : links) { String href = link.attr("abs:href"); if (isValidUrl(href)) { URL url = new URL(href); String linkHostName = url.getHost(); String linkType = ""; if (linkHostName.equalsIgnoreCase(hostName)) { linkType = "internal"; totalInternalLink++;/*from w ww. ja v a2 s.co m*/ } else { linkType = "external"; totalExternalLink++; } linksInfo.add(new Link(href, linkType)); } } return new LinkResult(linksInfo, totalInternalLink, totalExternalLink); }
From source file:org.apache.cxf.fediz.service.idp.STSPortFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { Assert.isTrue(applicationContext != null, "Application context must not be null"); STSAuthenticationProvider authProvider = authenticationProvider; if (authProvider == null) { authProvider = applicationContext.getBean(STSAuthenticationProvider.class); }/*from ww w. ja v a 2 s .co m*/ Assert.isTrue(authProvider != null, "STSAuthenticationProvider must be configured"); //Only update the port if HTTPS is used, otherwise ignored (like retrieving the WADL over HTTP) if (!isPortSet && request.isSecure()) { try { URL url = new URL(authProvider.getWsdlLocation()); if (url.getPort() == 0) { URL updatedUrl = new URL(url.getProtocol(), url.getHost(), request.getLocalPort(), url.getFile()); setSTSWsdlUrl(authProvider, updatedUrl.toString()); LOG.info("STSAuthenticationProvider.wsdlLocation set to " + updatedUrl.toString()); } else { setSTSWsdlUrl(authProvider, url.toString()); } } catch (MalformedURLException e) { LOG.error("Invalid Url '" + authProvider.getWsdlLocation() + "': " + e.getMessage()); } } chain.doFilter(request, response); }
From source file:org.deegree.protocol.ows.http.OwsHttpClientImpl.java
private void setProxies(URL url, DefaultHttpClient client) { String host = url.getHost(); String protocol = url.getProtocol().toLowerCase(); handleProxies(protocol, client, host); }
From source file:it.pronetics.madstore.crawler.publisher.impl.AtomPublisherImpl.java
private String getOrGenerateCollectionTitle(Page page, Element feed) throws Exception { String key = feed.getAttribute(AtomConstants.ATOM_KEY); if (key == null || key.equals("")) { URL url = new URL(page.getLink().getLink()); return url.getHost(); } else {// w w w . j a v a2 s. c o m return feed.getElementsByTagName(AtomConstants.ATOM_COLLECTION_TITLE).item(0).getTextContent(); } }
From source file:cc.arduino.net.CustomProxySelector.java
private String callFindProxyForURL(URI uri, ScriptEngine nashorn) throws ScriptException, NoSuchMethodException { Invocable script = (Invocable) nashorn; URL url = toUrl(uri); return (String) script.invokeFunction("FindProxyForURL", url.toExternalForm(), url.getHost()); }
From source file:com.tasktop.c2c.server.common.service.HttpProxySetup.java
public void setupProxyFromEnvironment() { String http_proxy = System.getenv().get("http_proxy"); if (http_proxy != null) { if (!http_proxy.startsWith("http://")) { http_proxy = "http://" + http_proxy; }//from w w w. j a v a2 s . c om logger.info("Configuring http proxy as: " + http_proxy); try { URL proxyUrl = new URL(http_proxy); httpProxyHost = proxyUrl.getHost(); System.setProperty("http.proxyHost", httpProxyHost); httpProxyPort = proxyUrl.getPort(); if (httpProxyPort != 80) { System.setProperty("http.proxyPort", httpProxyPort + ""); } } catch (MalformedURLException e) { logger.error("Error configuring proxy", e); } } else { logger.info("No http proxy defined"); } String https_proxy = System.getenv().get("https_proxy"); if (https_proxy != null) { if (!https_proxy.startsWith("https://")) { https_proxy = "https://" + https_proxy; } logger.info("Configuring https proxy as: " + https_proxy); try { URL proxyUrl = new URL(https_proxy); System.setProperty("https.proxyHost", proxyUrl.getHost()); if (proxyUrl.getPort() != 443) { System.setProperty("https.proxyPort", proxyUrl.getPort() + ""); } } catch (MalformedURLException e) { logger.error("Error configuring proxy", e); } } else { logger.info("No https proxy defined"); } String no_proxy = System.getenv().get("no_proxy"); if (no_proxy != null) { no_proxy = no_proxy.replace(",", "|"); } if (dontProxyToProfile) { if (no_proxy == null) { no_proxy = ""; } else { no_proxy = no_proxy + "|"; } no_proxy = no_proxy + profileConfiguration.getBaseWebHost() + "|*." + profileConfiguration.getBaseWebHost(); } if (no_proxy != null && !no_proxy.isEmpty()) { logger.info("Configuring no_proxy as: " + no_proxy); System.setProperty("http.nonProxyHosts", no_proxy); System.setProperty("https.nonProxyHosts", no_proxy); } }
From source file:com.brightcove.com.zartan.verifier.video.PdFlvUrlVerifier.java
@ZartanCheck(value = "Primary Rendition is on the pd cdn") public ResultEnum assertPrimaryRenditionCDNCorrect(UploadData upData) throws Throwable { mLog.info("Verifying Primary Rendition cdn is correct."); URL u = getPrimaryRenditionUrl(upData); assertEquals("Primary Rendition should be on the pd cdn", upData.getmAccount().getPdCdn().getHostName(), u.getHost()); return ResultEnum.PASS; }