List of usage examples for java.net URL getHost
public String getHost()
From source file:com.textuality.keybase.lib.prover.Twitter.java
@Override public boolean fetchProofData() { String tweetUrl = null;/*from w ww .j av a2 s . co m*/ try { JSONObject sigJSON = readSig(mProof.getSigId()); // the magic string is the base64 of the SHA of the raw message mShortenedMessageHash = JWalk.getString(sigJSON, "sig_id_short"); // find the tweet's url and fetch it tweetUrl = mProof.getProofUrl(); Fetch fetch = new Fetch(tweetUrl); String problem = fetch.problem(); if (problem != null) { mLog.add(problem); return false; } // Paranoid Interlude: // 1. It has to be a tweet https://twitter.com/<nametag>/status/\d+ // 2. the magic string has to appear in the <title>; were worried that // someone could @-reply and fake us out with the magic string down in someone // elses tweet URL suspectUrl = new URL(tweetUrl); String scheme = suspectUrl.getProtocol(); String host = suspectUrl.getHost(); String path = suspectUrl.getPath(); String nametag = mProof.getNametag(); if (!(scheme.equals("https") && host.equals("twitter.com") && path.startsWith("/" + nametag + "/status/") && endsWithDigits(path))) { mLog.add("Unacceptable Twitter proof Url: " + tweetUrl); } // dig through the tweet to find the magic string in the <title> String tweet = fetch.getBody(); // make sure were looking only through the header int index1 = tweet.indexOf("</head>"); if (index1 == -1) { mLog.add("</head> not found in proof tweet"); mLog.add("Proof tweet is malformed."); return false; } tweet = tweet.substring(0, index1); index1 = tweet.indexOf("<title>"); int index2 = tweet.indexOf("</title>"); if (index1 == -1 || index2 == -1 || index1 >= index2) { mLog.add("Bogus head locations: " + index1 + "/" + index2); mLog.add("Unable to find proof tweet header."); return false; } // ensure the magic string appears in the tweets <title> tweet = tweet.substring(index1, index2); if (tweet.contains(mShortenedMessageHash)) { return true; } else { mLog.add("Encoded message not found in proof tweet."); return false; } } 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("Unparsable tweet URL: " + tweetUrl); } return false; }
From source file:org.squashtest.tm.plugin.testautomation.jenkins.internal.net.HttpClientProvider.java
protected void registerServer(TestAutomationServer server) { URL baseURL = server.getBaseURL(); credentialsProvider.setCredentials(new AuthScope(baseURL.getHost(), baseURL.getPort(), AuthScope.ANY_REALM), new UsernamePasswordCredentials(server.getLogin(), server.getPassword())); }
From source file:org.jboss.as.test.integration.web.security.authentication.BasicAuthenticationMechanismPicketboxRemovedTestCase.java
/** * Test checks if correct response is returned after the EJB is called from the secured servlet. * * @param url/*from w w w . ja v a2 s. c o m*/ * @throws Exception */ @Test public void test(@ArquillianResource URL url) throws Exception { CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(new AuthScope(url.getHost(), url.getPort()), new UsernamePasswordCredentials(USER, PASSWORD)); try (CloseableHttpClient httpclient = HttpClients.custom() .setDefaultCredentialsProvider(credentialsProvider).build()) { HttpGet httpget = new HttpGet(url.toExternalForm() + "SecuredEJBServlet/"); HttpResponse response = httpclient.execute(httpget); assertNotNull("Response is 'null', we expected non-null response!", response); String text = Utils.getContent(response); assertEquals(200, response.getStatusLine().getStatusCode()); assertTrue("User principal different from what we expected!", text.contains("Principal: " + USER)); assertTrue("Remote user different from what we expected!", text.contains("Remote User: " + USER)); assertTrue("Authentication type different from what we expected!", text.contains("Authentication Type: BASIC")); } }
From source file:com.esri.gpt.control.webharvest.extensions.localfolder.LocalFolderDataProcessor.java
@Override public void onStart(ExecutionUnit unit) { try {/*from w ww . ja v a2 s. c om*/ URL hostUrl = new URL(unit.getRepository().getHostUrl()); destinationFolder = rootFolder != null ? new File(rootFolder, hostUrl.getHost()) : null; subFolder = splitPath(hostUrl.getPath()); } catch (MalformedURLException ex) { LOG.log(Level.SEVERE, "Error starting harvesting", ex); } }
From source file:fedora.common.http.WebClient.java
public HttpClient getHttpClient(String hostOrURL, UsernamePasswordCredentials creds) throws IOException { String host = null;/*from w ww . j a va2s . co m*/ if (hostOrURL != null) { if (hostOrURL.indexOf("/") != -1) { URL url = new URL(hostOrURL); host = url.getHost(); } else { host = hostOrURL; } } HttpClient client = new HttpClient(m_cManager); if (host != null && creds != null) { client.getState().setCredentials(new AuthScope(host, AuthScope.ANY_PORT), creds); client.getParams().setAuthenticationPreemptive(true); } if (proxy.isHostProxyable(host)) { client.getHostConfiguration().setProxy(proxy.getProxyHost(), proxy.getProxyPort()); if (proxy.hasValidCredentials()) { client.getState().setProxyCredentials( new AuthScope(proxy.getProxyHost(), proxy.getProxyPort(), null), new UsernamePasswordCredentials(proxy.getProxyUser(), proxy.getProxyPassword())); } } return client; }
From source file:com.asual.summer.core.faces.FacesResourceResolver.java
public URL resolveUrl(String path) { if (!resources.containsKey(path)) { URL url = ResourceUtils .getClasspathResource("/".equals(path) ? "META-INF/" : path.replaceAll("^/", "")); if (url != null) { try { url = new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getFile(), new FacesStreamHandler(url)); } catch (AccessControlException e) { } catch (NoClassDefFoundError e) { } catch (MalformedURLException e) { throw new FacesException(e); }//ww w . j ava 2 s . c om } else { logger.warn("The requested resource [" + path + "] cannot be resolved."); } resources.put(path, url); } return resources.get(path); }
From source file:com.microsoft.aad.adal.Discovery.java
/** * add this host as valid to skip another query to server. * //ww w . j a v a 2s .c o m * @param validhost */ private void addValidHostToList(URL validhost) { String validHost = validhost.getHost(); if (!StringExtensions.IsNullOrBlank(validHost)) { // for comparisons it uses Locale.US, so it needs to be same // here sValidHosts.add(validHost.toLowerCase(Locale.US)); } }
From source file:com.blackducksoftware.tools.scmconnector.integrations.mercurial.MercurialConnector.java
/** * Constructs a valid HTTP url if a user *and* password is provided. * * @throws Exception//from w ww. ja v a 2 s .c o m */ private void buildURL() throws Exception { if (StringUtils.isNotEmpty(user) && StringUtils.isNotEmpty(password)) { URL url = new URL(repositoryURL); String protocol = url.getProtocol(); int port = url.getPort(); String host = url.getHost(); String path = url.getPath(); URIBuilder builder = new URIBuilder(); builder.setScheme(protocol); builder.setHost(host); builder.setPort(port); builder.setPath(path); builder.setUserInfo(user, password); repositoryURL = builder.toString(); // log.info("Using path: " + repositoryURL); // Reveals password } }
From source file:sachin.spider.Page.java
/** * This function is called to get the list of external outgoing links from * the page//from www . ja v a2 s . c om * * @return List of all external outgoing links */ public List<String> getExternalLinks() { List<String> externalLinks = new ArrayList<String>(); if (outgoingLinks == null) { outgoingLinks = getOutgoingLinks(); } try { URL url = new URL(address); String host = url.getHost(); String baseHref = address.substring(0, address.indexOf(host, 0) + host.length()); for (String link : outgoingLinks) { if (!link.startsWith(baseHref)) { externalLinks.add(link); } } } catch (MalformedURLException ex) { Logger.getLogger(Page.class.getName()).log(Level.SEVERE, null, ex); } return externalLinks; }
From source file:org.uiautomation.ios.inspector.model.IDESessionModelImpl.java
@Override public JSONObject getStatus() { try {//from w w w. j a v a 2s . c om HttpClient client = HttpClientFactory.getClient(); String url = 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); return o; } catch (Exception e) { throw new WebDriverException(e.getMessage(), e); } }