List of usage examples for java.net URL toString
public String toString()
From source file:com.sudhirkhanger.app.popularmovies.FetchTasks.FetchReviews.java
@Override protected ArrayList<Review> doInBackground(String... params) { // These two need to be declared outside the try/catch // so that they can be closed in the finally block. HttpURLConnection urlConnection = null; BufferedReader reader = null; // Will contain the raw JSON response as a string. String reviewJsonStr = null;/*from w w w. jav a 2s . c o m*/ try { // Construct the URL for the MovieDB query final String MDB_BASE_URL = "http://api.themoviedb.org/3/movie/"; final String PATH_REVIEWS = "reviews"; final String QUERY_API_KEY = "api_key"; // http://api.themoviedb.org/3/movie/{movie_id}/reviews?api_key={API_KEY} Uri builtUri = Uri.parse(MDB_BASE_URL).buildUpon().appendPath(params[0]).appendPath(PATH_REVIEWS) .appendQueryParameter(QUERY_API_KEY, BuildConfig.THE_MOVIE_DB_API_KEY).build(); URL url = new URL(builtUri.toString()); Log.d(LOG_TAG, url.toString()); // Create the request to OpenWeatherMap, and open the connection urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestMethod("GET"); urlConnection.connect(); // Read the input stream into a String InputStream inputStream = urlConnection.getInputStream(); StringBuffer buffer = new StringBuffer(); if (inputStream == null) { // Nothing to do. reviewJsonStr = null; } reader = new BufferedReader(new InputStreamReader(inputStream)); String line; while ((line = reader.readLine()) != null) { // Since it's JSON, adding a newline isn't necessary (it won't affect parsing) // But it does make debugging a *lot* easier if you print out the completed // buffer for debugging. buffer.append(line + "\n"); } if (buffer.length() == 0) { // Stream was empty. No point in parsing. reviewJsonStr = null; } reviewJsonStr = buffer.toString(); } catch (IOException e) { Log.e(LOG_TAG, "Error ", e); // If the code didn't successfully get the weather data, there's no point in attempting // to parse it. reviewJsonStr = null; } finally { if (urlConnection != null) { urlConnection.disconnect(); } if (reader != null) { try { reader.close(); } catch (final IOException e) { Log.e(LOG_TAG, "Error closing stream", e); } } } try { return getReviewsFromJson(reviewJsonStr); } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); } return null; }
From source file:net.jakubholy.jeeutils.jsfelcheck.beanfinder.jsf11.Jsf11FacesConfigXmlBeanFinder.java
protected Digester digester(boolean validateXml) { Digester digester = new Digester(); digester.setNamespaceAware(false);/*from www .j a va 2 s .com*/ digester.setUseContextClassLoader(true); digester.setValidating(validateXml); digester.addRuleSet(new FacesConfigRuleSet(false, false, true)); for (int i = 0; i < DTD_INFO.length; i++) { URL url = getClass().getResource(DTD_INFO[i][0]); if (url != null) { digester.register(DTD_INFO[i][1], url.toString()); } else { throw new RuntimeException("NO_DTD_FOUND_ERROR: " + DTD_INFO[i][1] + "," + DTD_INFO[i][0]); } } digester.push(new FacesConfigBean()); return digester; }
From source file:com.samebug.clients.search.api.client.SamebugClient.java
public @NotNull ClientResponse<MarkResponse> retractMark(@NotNull final Integer voteId) { final URL url = urlBuilder.cancelMark(); HttpPost post = new HttpPost(url.toString()); List<BasicNameValuePair> form = Collections .singletonList(new BasicNameValuePair("mark", voteId.toString())); post.setEntity(new UrlEncodedFormEntity(form, Consts.UTF_8)); return rawClient.execute(post, new HandleAuthenticatedJsonRequest<MarkResponse>(MarkResponse.class)); }
From source file:net.hillsdon.reviki.wiki.plugin.PluginClassLoader.java
private void cacheClassPathEntries(final URL jarUrl, final String classPath) throws IOException { for (String entry : classPath.split("\\s")) { URL entryUrl = new URL("jar:" + jarUrl.toString() + "!/" + entry); File file = File.createTempFile("cached-", entry); file.deleteOnExit();//from w w w .jav a 2 s . c o m InputStream in = entryUrl.openStream(); FileOutputStream out = null; try { out = new FileOutputStream(file); IOUtils.copy(in, out); } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); } addURL(file.toURI().toURL()); } }
From source file:com.releasequeue.server.ReleaseQueueServer.java
private void deleteRequest(URL url) throws IOException { HttpDelete request = new HttpDelete(url.toString()); setAuthHeader(request);//from w ww. j a v a 2 s. c o m CloseableHttpClient httpClient = HttpClients.createDefault(); try { HttpResponse response = httpClient.execute(request); StatusLine statusLine = response.getStatusLine(); int statusCode = statusLine.getStatusCode(); if (statusCode >= 400) { throw new HttpException(statusLine.getReasonPhrase()); } } finally { httpClient.getConnectionManager().shutdown(); } }
From source file:com.samebug.clients.search.api.client.SamebugClient.java
public @NotNull ClientResponse<Solutions> getSolutions(@NotNull final Integer searchId) { final URL url = urlBuilder.search(searchId); HttpGet request = new HttpGet(url.toString()); return rawClient.execute(request, new HandleAuthenticatedJsonRequest<Solutions>(Solutions.class)); }
From source file:org.openxrd.discovery.impl.HtmlLinkDiscoveryMethod.java
/** {@inheritDoc} */ public URI getXRDLocation(URI uri) throws DiscoveryException { try {/*from w w w .j a v a 2 s . co m*/ HttpResponse response = fetch(uri); HttpEntity entity = response.getEntity(); if (entity == null) { entity.consumeContent(); return null; } String content = EntityUtils.toString(entity); Parser htmlParser = Parser.createParser(content, null); LinkVisitor linkVisitor = new LinkVisitor(); htmlParser.visitAllNodesWith(linkVisitor); for (Tag tag : linkVisitor.getLinks()) { if (!XRDConstants.XRD_MIME_TYPE.equals(tag.getAttribute("type"))) { continue; } if (!XRDConstants.XRD_REL_DESCRIBEDBY.equalsIgnoreCase(tag.getAttribute("rel"))) { continue; } try { URL xrdLocation = new URL(uri.toURL(), tag.getAttribute("href")); LOG.debug("Found XRD location: {}", xrdLocation.toString()); return xrdLocation.toURI(); } catch (URISyntaxException e) { continue; } } return null; } catch (IOException e) { throw new DiscoveryException(e); } catch (ParserException e) { throw new DiscoveryException(e); } }
From source file:com.samebug.clients.search.api.client.SamebugClient.java
public @NotNull ClientResponse<RestHit<Tip>> postTip(@NotNull final Integer searchId, @NotNull final String tip, @Nullable final String source) { final URL url = urlBuilder.tip(); HttpPost post = new HttpPost(url.toString()); List<BasicNameValuePair> form = new ArrayList<BasicNameValuePair>(); // TODO checkstyle fails if there are only spaces before the next two lines if (tip != null) form.add(new BasicNameValuePair("message", tip)); if (searchId != null) form.add(new BasicNameValuePair("searchId", searchId.toString())); if (source != null) form.add(new BasicNameValuePair("sourceUrl", source)); post.setEntity(new UrlEncodedFormEntity(form, Consts.UTF_8)); // NOTE: posting a tip includes downloading the source on the server side, which might take a while, hence we let it work a bit more. post.setConfig(rawClient.requestConfigBuilder .setSocketTimeout(config.requestTimeout + TipSourceLoadingTime_Handicap_Millis).build()); Type typeToken = new TypeToken<RestHit<Tip>>() { }.getType();/* w w w.j ava2 s . com*/ return rawClient.execute(post, new HandleAuthenticatedJsonRequest<RestHit<Tip>>(typeToken)); }
From source file:com.sudhirkhanger.app.popularmovies.FetchTasks.FetchTrailers.java
@Override protected ArrayList<Trailer> doInBackground(String... params) { // These two need to be declared outside the try/catch // so that they can be closed in the finally block. HttpURLConnection urlConnection = null; BufferedReader reader = null; // Will contain the raw JSON response as a string. String trailerJsonStr = null; try {//w w w. j a va 2 s .c o m // Construct the URL for the MovieDB query final String MDB_BASE_URL = "http://api.themoviedb.org/3/movie/"; final String PATH_VIDEO = "videos"; final String QUERY_API_KEY = "api_key"; // http://api.themoviedb.org/3/movie/209112/videos?api_key={API_KEY} Uri builtUri = Uri.parse(MDB_BASE_URL).buildUpon().appendPath(params[0]).appendPath(PATH_VIDEO) .appendQueryParameter(QUERY_API_KEY, BuildConfig.THE_MOVIE_DB_API_KEY).build(); URL url = new URL(builtUri.toString()); Log.d(LOG_TAG, url.toString()); // Create the request to OpenWeatherMap, and open the connection urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestMethod("GET"); urlConnection.connect(); // Read the input stream into a String InputStream inputStream = urlConnection.getInputStream(); StringBuffer buffer = new StringBuffer(); if (inputStream == null) { // Nothing to do. trailerJsonStr = null; } reader = new BufferedReader(new InputStreamReader(inputStream)); String line; while ((line = reader.readLine()) != null) { // Since it's JSON, adding a newline isn't necessary (it won't affect parsing) // But it does make debugging a *lot* easier if you print out the completed // buffer for debugging. buffer.append(line + "\n"); } if (buffer.length() == 0) { // Stream was empty. No point in parsing. trailerJsonStr = null; } trailerJsonStr = buffer.toString(); } catch (IOException e) { Log.e(LOG_TAG, "Error ", e); // If the code didn't successfully get the weather data, there's no point in attempting // to parse it. trailerJsonStr = null; } finally { if (urlConnection != null) { urlConnection.disconnect(); } if (reader != null) { try { reader.close(); } catch (final IOException e) { Log.e(LOG_TAG, "Error closing stream", e); } } } try { return getTrailerFromJson(trailerJsonStr); } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); } return null; }
From source file:cn.bidaround.ytcore.util.HurlStack.java
/** * Create an {@link HttpURLConnection} for the specified {@code url}. */// w ww . ja v a2s . c o m protected HttpURLConnection createConnection(URL url) throws IOException { if (url.toString().contains("https")) { HTTPSTrustManager.allowAllSSL(); } return (HttpURLConnection) url.openConnection(); }