List of usage examples for java.net URL toString
public String toString()
From source file:com.magnet.android.mms.request.ResponsePrimitiveTest.java
@SmallTest public void testGenericUrlResponse() throws MobileException { ParserFactory pf = new ParserFactory(URL.class); ResponseParser parser = pf.createInstance(GenericRestConstants.CONTENT_TYPE_JSON, GenericRestConstants.MIME_ENCODING_NONE); String strUrl = "http://www.wellsfargo.com:9090"; String parseStr = "\"" + strUrl + "\""; URL result = (URL) parser.parseResponse(parseStr.getBytes()); assertEquals(strUrl, result.toString()); }
From source file:dip.world.variant.VariantManager.java
/** Get the webstart plugin name */ private static String getWSPluginName(URL url) { final String s = url.toString(); final int idxExclam = s.indexOf('!'); if (idxExclam >= 0) { return s.substring(s.lastIndexOf("/", idxExclam) + 1, idxExclam); } else {/*w w w .jav a 2 s . co m*/ return s; } }
From source file:com.wavemaker.commons.io.ResourceURLTest.java
@Test public void shouldGetJailedURL() throws Exception { Folder jail = this.root.getFolder("jail").jail(); URL url = ResourceURL.get(jail.getFile("/a/b/c.txt")); assertThat(url.toString(), Matchers.is(Matchers.equalTo("rfs:/a/b/c.txt"))); }
From source file:net.sasasin.sreader.batch.ContentHeaderDriver.java
@SuppressWarnings("unchecked") private void fetchByRome(FeedUrl f, Set<ContentHeader> c) { try {//from ww w.j ava 2 s.co m // ?RSS InputStream is = IOUtils.toInputStream(new WgetHttpComponentsImpl(new URL(f.getUrl())).read()); // Rome SyndFeed feed = new SyndFeedInput().build(new XmlReader(is)); for (SyndEntry entry : (List<SyndEntry>) feed.getEntries()) { logger.info(this.getClass().getSimpleName() + " processing " + entry.getLink()); ContentHeader ch = new ContentHeader(); // HTTP 30xmoved?URL?? // 30x???????new URL(entry.getLink())???? URL entryUrl = new WgetHttpComponentsImpl(new URL(entry.getLink())).getOriginalUrl(); ch.setUrl(entryUrl.toString()); ch.setId(Md5Util.crypt(ch.getUrl())); ch.setTitle(entry.getTitle()); ch.setFeedUrl(f); c.add(ch); } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (FeedException e) { e.printStackTrace(); } }
From source file:com.google.android.apps.picview.request.CachedWebRequestFetcher.java
private URL getSynchronizableInstance(URL url) { if (urls.containsKey(url.toString())) { url = urls.get(url.toString());//from w w w. ja v a2 s .c om } else { urls.put(url.toString(), url); } return url; }
From source file:org.jboss.additional.testsuite.jdkall.present.web.servlet.headers.CookieHeaderServletTestCase.java
@ATTest({ "modules/testcases/jdkAll/Wildfly/web/src/main/java#13.0.0", "modules/testcases/jdkAll/Eap71x-Proposed/web/src/main/java#7.1.4", "modules/testcases/jdkAll/Eap71x/web/src/main/java#7.1.4" }) @OperateOnDeployment(DEPLOYMENT)//from ww w .j a v a 2 s. c o m public void headerProtocolTest(@ArquillianResource URL url) throws Exception { URL testURL = new URL(url.toString() + "cookieHeaderServlet"); final HttpGet request = new HttpGet(testURL.toString()); request.setProtocolVersion(HttpVersion.HTTP_1_0); CloseableHttpClient httpClient = HttpClientBuilder.create().build(); CloseableHttpResponse response = null; response = httpClient.execute(request); System.out.println("Protocol Version : " + response.getProtocolVersion()); Assert.assertTrue("Protocol Version should be HTTP/1.1.", response.getProtocolVersion().toString().contains("HTTP/1.1")); IOUtils.closeQuietly(response); httpClient.close(); }
From source file:com.omertron.tvmazeapi.TvMazeApi.java
/** * Get the API information/*from w w w . ja v a 2 s.com*/ * * @param url * @return * @throws TvMazeException */ private String requestWebPage(URL url) throws TvMazeException { LOG.trace("Requesting: {}", url.toString()); try { final HttpGet httpGet = new HttpGet(url.toURI()); httpGet.addHeader("accept", "application/json"); final DigestedResponse response = DigestedResponseReader.requestContent(httpClient, httpGet, charset); if (response.getStatusCode() >= HTTP_STATUS_500) { throw new TvMazeException(ApiExceptionType.HTTP_503_ERROR, response.getContent(), response.getStatusCode(), url); } else if (response.getStatusCode() >= HTTP_STATUS_300) { throw new TvMazeException(ApiExceptionType.HTTP_404_ERROR, response.getContent(), response.getStatusCode(), url); } return response.getContent(); } catch (URISyntaxException ex) { throw new TvMazeException(ApiExceptionType.INVALID_URL, "Invalid URL", url, ex); } catch (IOException ex) { throw new TvMazeException(ApiExceptionType.CONNECTION_ERROR, "Error retrieving URL", url, ex); } }
From source file:org.jboss.additional.testsuite.jdkall.present.web.servlet.buffersize.ResponseBufferSizeTestCase.java
@Test @OperateOnDeployment(DEPLOYMENT)//w w w. j a v a 2s .c o m public void increaseBufferSizeTest(@ArquillianResource URL url) throws Exception { URL testURL = new URL( url.toString() + "ResponseBufferSizeServlet?" + ResponseBufferSizeServlet.SIZE_CHANGE_PARAM_NAME + "=1.5" + "&" + ResponseBufferSizeServlet.DATA_LENGTH_IN_PERCENTS_PARAM_NAME + "=0.8"); // more than original size, less than new buffer size final HttpGet request = new HttpGet(testURL.toString()); CloseableHttpClient httpClient = HttpClientBuilder.create().build(); CloseableHttpResponse response = null; try { response = httpClient.execute(request); Assert.assertEquals("Failed to access " + testURL, HttpURLConnection.HTTP_OK, response.getStatusLine().getStatusCode()); String content = EntityUtils.toString(response.getEntity()); Assert.assertFalse(content.contains(ResponseBufferSizeServlet.RESPONSE_COMMITED_MESSAGE)); final Header[] transferEncodingHeaders = response.getHeaders("Transfer-Encoding"); final Header[] contentLengthHeader = response.getHeaders("Content-Length"); for (Header transferEncodingHeader : transferEncodingHeaders) { Assert.assertNotEquals( "Transfer-Encoding shouldn't be chunked as set BufferSize shouldn't be filled yet, " + "probably caused due https://bugzilla.redhat.com/show_bug.cgi?id=1212566", "chunked", transferEncodingHeader.getValue()); } Assert.assertFalse("Content-Length header not specified", contentLengthHeader.length == 0); } finally { IOUtils.closeQuietly(response); httpClient.close(); } }
From source file:com.norconex.commons.lang.url.QueryString.java
/** * Constructor.//from w ww .j a v a2 s.c om * @param urlWithQueryString a URL from which to extract a query string. * @param encoding character encoding */ public QueryString(URL urlWithQueryString, String encoding) { this(urlWithQueryString.toString(), encoding); }
From source file:podd.triples.SesameRepositoryFactory.java
public SesameRepoWrapper createRemoteSesameRepo(String serverAddress, String repoID) throws IOException, RepositoryException { try {//from w w w . ja va 2 s. c o m URL repoURL = new URL(new URL(serverAddress), repoID); if (map.containsKey(repoURL.toString())) { return map.get(repoURL.toString()); } else { SesameRepoWrapper wrapper = new SesameRemoteRepoWrapperImpl(serverAddress, repoID); map.put(repoURL.toString(), wrapper); return wrapper; } } catch (MalformedURLException e) { throw new IOException("Invalid Sesame remote repository address: <" + serverAddress + ", " + repoID, e); } }