List of usage examples for java.net URL toString
public String toString()
From source file:com.google.android.apps.picview.request.CachedWebRequestFetcher.java
/** * Fetches the given URL from the web./* ww w . j a v a 2s . c o m*/ */ public String fetchFromWeb(URL url) { Log.d(TAG, "Fetching from web: " + url.toString()); HttpsURLConnection conn = null; HttpResponse resp = null; try { conn = (HttpsURLConnection) url.openConnection(); conn.setUseCaches(false); conn.setReadTimeout(30000); // 30 seconds. conn.setDoInput(true); conn.addRequestProperty("GData-Version", "2"); conn.connect(); InputStream is = conn.getInputStream(); return readStringFromStream(is); } catch (Exception e) { Log.v(TAG, readStringFromStream(conn.getErrorStream())); e.printStackTrace(); } return null; }
From source file:org.opencastproject.remotetest.server.IngestRestEndpointTest.java
protected String postCall(String method, String mediaFile, String flavor, String mediaPackage) throws ClientProtocolException, IOException { HttpPost post = new HttpPost(BASE_URL + method); List<NameValuePair> formParams = new ArrayList<NameValuePair>(); if (mediaFile != null) { URL url = getClass().getClassLoader().getResource(mediaFile); formParams.add(new BasicNameValuePair("url", url.toString())); }/* w ww. j ava 2s .c o m*/ if (flavor != null) { formParams.add(new BasicNameValuePair("flavor", flavor)); } formParams.add(new BasicNameValuePair("mediaPackage", mediaPackage)); post.setEntity(new UrlEncodedFormEntity(formParams, "UTF-8")); HttpResponse response = client.execute(post); Assert.assertEquals(200, response.getStatusLine().getStatusCode()); return EntityUtils.toString(response.getEntity()); }
From source file:es.itecban.deployment.executionmanager.web.controller.UnitInverseDependenciesController.java
private String getXMLDependencyGraphURL(DeploymentUnitType unit, HttpServletRequest request) throws Exception { String file = request.getRequestURI(); if (request.getQueryString() != null) { file += '?' + request.getQueryString() + "&justGraph=true"; }/*from w ww.j ava 2 s.c om*/ URL reconstructedURL = new URL(request.getScheme(), request.getServerName(), request.getServerPort(), file); return reconstructedURL.toString(); }
From source file:com.openshift.internal.restclient.URLBuilder.java
/** * /*from w w w. j av a 2s . c o m*/ * @param baseUrl * @param typeMappings the map of kinds to endpoint */ URLBuilder(URL baseUrl, Map<String, String> typeMappings) { this.baseUrl = baseUrl.toString().replaceAll("/*$", ""); this.typeMappings = typeMappings; }
From source file:fr.free.movierenamer.stream.VideoDetective.java
@Override public Map<Quality, URL> getLinks(URL url) throws Exception { Map<Quality, URL> links = new EnumMap<Quality, URL>(Quality.class); String strUrl = url.toString(); String id = strUrl.substring(strUrl.lastIndexOf("/") + 1); String uri = "http://video.internetvideoarchive.net/player/6/configuration.ashx?customerid=" + id + "&publishedid=7299&reporttag=vdbetatitle&playerid=641&autolist=0&domain=www.videodetective.com&maxrate=high&minrate=low&socialplayer=false"; JSONObject json = URIRequest.getJsonDocument(new URL(uri).toURI()); String error = JSONUtils.selectString("/error", json); if (error != null && !error.equals("")) { return links; }//from w ww.ja v a 2s . c o m List<JSONObject> sources = JSONUtils.selectList("//sources", json); for (JSONObject source : sources) { String label = JSONUtils.selectString("label", source); if (label == null) { continue; } if (label.equals("2500 kbs") || label.equals("1500 kbs")) { if (links.get(Quality.HD) == null) { links.put(Quality.HD, new URL(JSONUtils.selectString("file", source))); } } else if (label.equals("750 kbs") || label.equals("450 kbs")) { if (links.get(Quality.SD) == null) { links.put(Quality.SD, new URL(JSONUtils.selectString("file", source))); } } else if (label.equals("212 kbs") || label.equals("80 kbs")) { if (links.get(Quality.SD) == null) { links.put(Quality.LD, new URL(JSONUtils.selectString("file", source))); } } } return links; }
From source file:com.apigee.sdk.apm.http.impl.client.cache.CacheInvalidator.java
protected void flushUriIfSameHost(URL requestURL, URL targetURL) throws IOException { URL canonicalTarget = new URL(uriExtractor.canonicalizeUri(targetURL.toString())); if (canonicalTarget.getAuthority().equalsIgnoreCase(requestURL.getAuthority())) { storage.removeEntry(canonicalTarget.toString()); }//w w w.jav a 2 s . co m }
From source file:com.sittinglittleduck.DirBuster.GenBaseCase.java
/** * Generates the base case/*w ww . ja v a 2 s. co m*/ * * @param manager the manager class * @param url The directy or file we need a base case for * @param isDir true if it's dir, else false if it's a file * @param fileExtention File extention to be scanned, set to null if it's a dir that is to be * tested * @return A BaseCase Object */ public static BaseCase genBaseCase(Manager manager, String url, boolean isDir, String fileExtention) throws MalformedURLException, IOException { String type; if (isDir) { type = "Dir"; } else { type = "File"; } /* * markers for using regex instead */ boolean useRegexInstead = false; String regex = null; BaseCase tempBaseCase = manager.getBaseCase(url, isDir, fileExtention); if (tempBaseCase != null) { // System.out.println("Using prestored basecase"); return tempBaseCase; } // System.out.println("DEBUG GenBaseCase: URL to get baseCase for: " + url + " (" + type + // ")"); if (Config.debug) { System.out.println("DEBUG GenBaseCase: URL to get baseCase for:" + url); } BaseCase baseCase = null; int failcode = 0; String failString = Config.failCaseString; String baseResponce = ""; URL failurl = null; if (isDir) { failurl = new URL(url + failString + "/"); } else { if (manager.isBlankExt()) { fileExtention = ""; failurl = new URL(url + failString + fileExtention); } else { if (!fileExtention.startsWith(".")) { fileExtention = "." + fileExtention; } failurl = new URL(url + failString + fileExtention); } } // System.out.println("DEBUG GenBaseCase: Getting :" + failurl + " (" + type + ")"); if (Config.debug) { System.out.println("DEBUG GenBaseCase: Getting:" + failurl); } GetMethod httpget = new GetMethod(failurl.toString()); // set the custom HTTP headers Vector HTTPheaders = manager.getHTTPHeaders(); for (int a = 0; a < HTTPheaders.size(); a++) { HTTPHeader httpHeader = (HTTPHeader) HTTPheaders.elementAt(a); /* * Host header has to be set in a different way! */ if (httpHeader.getHeader().startsWith("Host")) { httpget.getParams().setVirtualHost(httpHeader.getValue()); } else { httpget.setRequestHeader(httpHeader.getHeader(), httpHeader.getValue()); } } httpget.setFollowRedirects(Config.followRedirects); // save the http responce code for the base case failcode = manager.getHttpclient().executeMethod(httpget); manager.workDone(); // we now need to get the content as we need a base case! if (failcode == 200) { if (Config.debug) { System.out.println("DEBUG GenBaseCase: base case for " + failurl.toString() + "came back as 200!"); } BufferedReader input = new BufferedReader(new InputStreamReader(httpget.getResponseBodyAsStream())); String tempLine; StringBuffer buf = new StringBuffer(); while ((tempLine = input.readLine()) != null) { buf.append("\r\n" + tempLine); } baseResponce = buf.toString(); input.close(); // HTMLparse.parseHTML(); // HTMLparse htmlParse = new HTMLparse(baseResponce, null); // Thread parse = new Thread(htmlParse); // parse.start(); // clean up the base case, based on the basecase URL baseResponce = FilterResponce.CleanResponce(baseResponce, failurl, failString); httpget.releaseConnection(); /* * get the base case twice more, for consisitency checking */ String baseResponce1 = baseResponce; String baseResponce2 = getBaseCaseAgain(manager, failurl, failString); String baseResponce3 = getBaseCaseAgain(manager, failurl, failString); if (baseResponce1 != null && baseResponce2 != null && baseResponce3 != null) { /* * check that all the responces are same, if they are do nothing if not enter the if statement */ if (!baseResponce1.equalsIgnoreCase(baseResponce2) || !baseResponce1.equalsIgnoreCase(baseResponce3) || !baseResponce2.equalsIgnoreCase(baseResponce3)) { if (manager.getFailCaseRegexes().size() != 0) { /* * for each saved regex see if it will work, if it does then use that one * if not then give the uses the dialog */ Vector<String> failCaseRegexes = manager.getFailCaseRegexes(); for (int a = 0; a < failCaseRegexes.size(); a++) { Pattern regexFindFile = Pattern.compile(failCaseRegexes.elementAt(a)); Matcher m1 = regexFindFile.matcher(baseResponce1); Matcher m2 = regexFindFile.matcher(baseResponce2); Matcher m3 = regexFindFile.matcher(baseResponce3); boolean test1 = m1.find(); boolean test2 = m2.find(); boolean test3 = m3.find(); if (test1 && test2 && test3) { regex = failCaseRegexes.elementAt(a); useRegexInstead = true; break; } } } } else { /* * We have a big problem as now we have different responce codes for the same request * //TODO think of a way to deal with is */ } if (Config.debug) { System.out.println("DEBUG GenBaseCase: base case was set to :" + baseResponce); } } } httpget.releaseConnection(); baseCase = new BaseCase(new URL(url), failcode, isDir, failurl, baseResponce, fileExtention, useRegexInstead, regex); // add the new base case to the manager list manager.addBaseCase(baseCase); manager.addNumberOfBaseCasesProduced(); return baseCase; }
From source file:au.csiro.casda.sodalint.ValidateCapabilities.java
private String getCapabilities(final Reporter reporter, URL serviceUrl) { String baseUrl = serviceUrl.toString(); if (!baseUrl.endsWith("/")) { baseUrl += "/"; }//from w ww. j a va2 s .c o m String address = baseUrl + "capabilities"; try { reporter.report(SodaCode.I_VURL, "Validating URL: " + address); String content = getXmlContentFromUrl(address); if (content == null) { reporter.report(SodaCode.E_CPRS, "Capabilities response contains no content"); } return content; } catch (HttpResponseException e) { reporter.report(SodaCode.E_CPRS, "Unexpected http response: " + e.getStatusCode() + " Reason: " + e.getMessage()); } catch (UnsupportedEncodingException e) { reporter.report(SodaCode.E_CPRS, "Capabilities response has an unexpected content type:" + e.getMessage()); } catch (IOException e) { reporter.report(SodaCode.E_CPRS, "Unable to read capabilities response: " + e.getMessage()); } return null; }
From source file:com.apigee.sdk.apm.http.impl.client.cache.URIExtractor.java
public String canonicalizeUri(String uri) { try {//from w w w. j a v a 2 s . c o m URL u = new URL(uri); String protocol = u.getProtocol().toLowerCase(); String hostname = u.getHost().toLowerCase(); int port = canonicalizePort(u.getPort(), protocol); String path = canonicalizePath(u.getPath()); if ("".equals(path)) path = "/"; String query = u.getQuery(); String file = (query != null) ? (path + "?" + query) : path; URL out = new URL(protocol, hostname, port, file); return out.toString(); } catch (MalformedURLException e) { return uri; } }
From source file:eu.eubrazilcc.lvl.storage.GravatarTest.java
@Test public void test() { System.out.println("GravatarTest.test()"); try {/*from w ww.j a v a 2 s. co m*/ final String email = "username@example.com"; // test image Gravatar gravatar = Gravatar.builder().email(email).build(); URL url = gravatar.imageUrl(); assertThat("image URL is not null", url, notNullValue()); assertThat("image URL is not empty", isNotBlank(url.toString())); System.out.println(url.toString()); // test JSON profile url = gravatar.jsonProfileUrl(); assertThat("JSON profile URL is not null", url, notNullValue()); assertThat("JSON profile is not empty", isNotBlank(url.toString())); System.out.println(url.toString()); // test JSON profile with callback function gravatar = Gravatar.builder().email(email).profileCallback("alert").build(); url = gravatar.jsonProfileUrl(); assertThat("JSON profile with callback URL is not null", url, notNullValue()); assertThat("JSON profile with callback is not empty", isNotBlank(url.toString())); System.out.println(url.toString()); } catch (Exception e) { e.printStackTrace(System.err); fail("GravatarTest.test() failed: " + e.getMessage()); } finally { System.out.println("GravatarTest.test() has finished"); } }