List of usage examples for java.net URL getHost
public String getHost()
From source file:com.frostwire.ImageCache.java
private File getCacheFile(URL url) { String host = url.getHost(); String path = url.getPath();//w w w .j a v a2s . co m if (host == null || host.length() == 0) { // dealing with local resource images, not perfect host = "localhost"; path = new File(path).getName(); } return new File(SharingSettings.getImageCacheDirectory(), File.separator + host + File.separator + path); }
From source file:org.uiautomation.ios.inspector.controllers.SessionGuesserController.java
private Session getSession() throws Exception { HttpClient client = HttpClientFactory.getClient(); String url = cache.getEndPoint() + "/status"; URL u = new URL(url); BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest("GET", url); HttpHost h = new HttpHost(u.getHost(), u.getPort()); HttpResponse response = client.execute(h, r); JSONObject o = Helper.extractObject(response); String id = o.optString("sessionId"); if (id == null) { throw new WebDriverException("cannot guess the sessionId for the IDE to use."); }//from ww w . j a v a 2 s .c o m return new Session(id); }
From source file:com.textuality.keybase.lib.prover.Prover.java
public String getPresenceLabel() throws KeybaseException { String answer = mProof.getServiceUrl(); try {/*from w w w . ja v a2 s .c o m*/ URL u = new URL(answer); answer = u.getHost() + u.getPath(); } catch (MalformedURLException e) { } return answer; }
From source file:com.brightcove.com.zartan.verifier.video.StreamingFLVURLVerifier.java
@ZartanCheck(value = "Primary Rendition is on the streaming cdn") public ResultEnum assertPrimaryRenditionCDNCorrect(UploadData upData) throws Throwable { URL u = getPrimaryRenditionUrl(upData); assertEquals("Primary Rendition should be on the streaming cdn", u.getHost(), upData.getmAccount().getStreamingCdn().getHostName()); return ResultEnum.PASS; }
From source file:io.fabric8.maven.enricher.fabric8.DocLinkEnricher.java
protected String findDocumentationUrl() { DistributionManagement distributionManagement = findProjectDistributionManagement(); if (distributionManagement != null) { Site site = distributionManagement.getSite(); if (site != null) { String url = site.getUrl(); if (StringUtils.isNotBlank(url)) { // lets replace any properties... MavenProject project = getProject(); if (project != null) { url = replaceProperties(url, project.getProperties()); }// w w w. j a v a 2 s . c o m // lets convert the internal dns name to a public name try { String urlToParse = url; int idx = url.indexOf("://"); if (idx > 0) { // lets strip any previous schemes such as "dav:" int idx2 = url.substring(0, idx).lastIndexOf(':'); if (idx2 >= 0 && idx2 < idx) { urlToParse = url.substring(idx2 + 1); } } URL u = new URL(urlToParse); String serviceName = u.getHost(); String protocol = u.getProtocol(); if (isOnline()) { // lets see if the host name is a service name in which case we'll resolve to the public URL String publicUrl = getExternalServiceURL(serviceName, protocol); if (StringUtils.isNotBlank(publicUrl)) { return String.format("%s/%s", publicUrl, u.getPath()); } } } catch (MalformedURLException e) { getLog().error("Failed to parse URL: %s. %s", url, e); } return url; } } } return null; }
From source file:com.textuality.keybase.lib.prover.Website.java
@Override public boolean fetchProofData() { try {/* w w w . j a v a2s . c om*/ JSONObject sigJSON = readSig(mProof.getSigId()); // find the .well-known URL String wellKnownUrl = JWalk.getString(sigJSON, "api_url"); // fetch the proof Fetch fetch = new Fetch(wellKnownUrl); String problem = fetch.problem(); if (problem != null) { mLog.add(problem); return false; } String actualUrl = fetch.getActualUrl(); // Paranoid Interlude: // A bad guy who cant post to the site might still be able to squeeze in a redirect // to somewhere else, so lets ensure that the data is really coming from the site // String nametag = mProof.getNametag(); URL url = new URL(actualUrl); String scheme = url.getProtocol(); String host = url.getHost(); if (!(scheme.equals("http") || scheme.equals("https")) && host.equals(nametag)) { mLog.add("Proof either doesnt come from " + nametag + " or isnt at an HTTP URL"); return false; } // verify that message appears in gist if (!fetch.getBody().contains(mPgpMessage)) { mLog.add("Website claiming post doesnt contain signed PGP message"); return false; } return true; } catch (KeybaseException e) { mLog.add("Keybase API problem: " + e.getLocalizedMessage()); } catch (JSONException e) { mLog.add("Broken JSON message: " + e.getLocalizedMessage()); } catch (MalformedURLException e) { mLog.add("Malformed proof URL"); } return false; }
From source file:net.sourceforge.subsonic.backend.controller.RedirectionController.java
private String getRedirectTo(HttpServletRequest request, Redirection redirection) { // If the request comes from within the same LAN as the destination Subsonic // server, redirect using the local IP address of the server. String localRedirectTo = redirection.getLocalRedirectTo(); if (localRedirectTo != null) { try {/*w w w. j a v a 2 s .c om*/ URL url = new URL(redirection.getRedirectTo()); if (url.getHost().equals(request.getRemoteAddr())) { return localRedirectTo; } } catch (Throwable x) { LOG.error("Malformed local redirect URL.", x); } } return redirection.getRedirectTo(); }
From source file:com.comcast.cats.config.ui.recording.MediaInfoBean.java
private String substituteFilePath(String filePath) { String retVal = filePath;// ww w .j av a 2 s . c o m try { URL filePathURL = new URL(filePath); String host = filePathURL.getHost(); retVal = StringUtils.replaceOnce(filePath, host, AuthController.getHostAddress()); } catch (MalformedURLException e) { logger.debug("Provider doesnt know how to parse this syntax"); } return retVal; }
From source file:net.sourceforge.subsonic.backend.controller.RedirectionController.java
private String getRedirectFrom(HttpServletRequest request) throws MalformedURLException { URL url = new URL(request.getRequestURL().toString()); String host = url.getHost(); String redirectFrom;/*from w w w . j a v a 2 s .c o m*/ if (host.contains(".")) { redirectFrom = StringUtils.substringBefore(host, "."); } else { // For testing. redirectFrom = request.getParameter("redirectFrom"); } return StringUtils.lowerCase(redirectFrom); }
From source file:com.gargoylesoftware.htmlunit.util.URLCreator.java
protected URL toNormalUrl(final String url) throws MalformedURLException { final URL response = new URL(url); if (response.getProtocol().startsWith("http") && StringUtils.isEmpty(response.getHost())) { throw new MalformedURLException("Missing host name in url: " + url); }// ww w . ja v a2s .c o m return response; }