List of usage examples for java.net URLDecoder decode
public static String decode(String s, Charset charset)
From source file:io.wcm.caravan.io.http.impl.servletclient.HttpServletRequestMapper.java
/** * @param request/* w w w . jav a2 s.c o m*/ */ public HttpServletRequestMapper(CaravanHttpRequest request) throws NotSupportedByRequestMapperException { this.request = request; try { uri = new URI(request.getUrl()); serviceId = URLDecoder.decode(request.getServiceId(), Charsets.UTF_8.toString()); } catch (URISyntaxException | UnsupportedEncodingException ex) { throw new NotSupportedByRequestMapperException(); } }
From source file:org.ocpsoft.redoculous.tests.markdown.MarkdownRenderTest.java
@Test public void testServeMarkdown() throws Exception { WebTest test = new WebTest(baseUrl); String repositoryURL = "file://" + repository.getAbsolutePath(); HttpAction<HttpPost> action = test.post("/api/v1/manage?repo=" + repositoryURL); Assert.assertEquals(201, action.getResponse().getStatusLine().getStatusCode()); String location = URLDecoder.decode(action.getResponseHeaderValue("location"), "UTF8"); Assert.assertEquals(test.getBaseURL() + test.getContextPath() + "/api/v1/serve?repo=" + repositoryURL, location);/*from ww w .java 2 s . com*/ HttpAction<HttpGet> document = test .get("/api/v1/serve?repo=" + repositoryURL + "&ref=master&path=document"); Assert.assertTrue(document.getResponseContent().contains("<h1")); Assert.assertTrue(document.getResponseContent().contains("A First Level Header")); }
From source file:me.zhuoran.amoeba.netty.server.http.HttpRequestHandler.java
/** * sanitize url//from w w w. j a v a 2s.co m * @param uri * @return * @throws URISyntaxException */ public static String sanitizeUri(String uri) throws URISyntaxException { try { uri = URLDecoder.decode(uri, "UTF-8"); } catch (UnsupportedEncodingException var4) { try { uri = URLDecoder.decode(uri, "ISO-8859-1"); } catch (UnsupportedEncodingException var3) { throw new Error(); } } if (!uri.startsWith("/")) { return null; } else { URI uriObject = new URI(uri); for (uri = uriObject.getPath(); uri != null && uri.startsWith("/"); uri = uri.substring(1)) { } return uri.toLowerCase(); } }
From source file:org.yamj.core.service.artwork.online.YahooPosterScanner.java
@Override public List<ArtworkDetailDTO> getPosters(VideoData videoData) { List<ArtworkDetailDTO> dtos = new ArrayList<>(); try {//from w w w . ja v a2 s .co m StringBuilder sb = new StringBuilder("http://fr.images.search.yahoo.com/search/images?p="); sb.append(URLEncoder.encode(videoData.getTitle(), "UTF-8")); sb.append("+poster&fr=&ei=utf-8&js=1&x=wrt"); DigestedResponse response = httpClient.requestContent(sb.toString()); if (ResponseTools.isOK(response)) { // TODO scan more posters at once int beginIndex = response.getContent().indexOf("imgurl="); if (beginIndex > 0) { int endIndex = response.getContent().indexOf("rurl=", beginIndex); if (endIndex > 0) { String url = URLDecoder .decode(response.getContent().substring(beginIndex + 7, endIndex - 1), "UTF-8"); dtos.add(new ArtworkDetailDTO(getScannerName(), url)); } else { String url = URLDecoder.decode(response.getContent().substring(beginIndex + 7), "UTF-8"); dtos.add(new ArtworkDetailDTO(getScannerName(), url)); } } } else { LOG.warn("Requesting yahoo poster for '{}' failed with status {}", videoData.getTitle(), response.getStatusCode()); } } catch (Exception ex) { LOG.error("Failed retrieving poster URL from yahoo images '{}': {}", videoData.getTitle(), ex.getMessage()); LOG.trace("Yahoo poster scanner error", ex); } return dtos; }
From source file:org.ocpsoft.redoculous.tests.git.InitializeRepositoryTest.java
@Test public void testInitializeRepositoryAndServeAsciidoc() throws Exception { WebTest test = new WebTest(baseUrl); String repositoryURL = "file://" + repository.getAbsolutePath(); HttpAction<HttpPost> action = test.post("/api/v1/manage?repo=" + repositoryURL); Assert.assertEquals(201, action.getResponse().getStatusLine().getStatusCode()); String location = URLDecoder.decode(action.getResponseHeaderValue("location"), "UTF8"); Assert.assertEquals(test.getBaseURL() + test.getContextPath() + "/api/v1/serve?repo=" + repositoryURL, location);//from www .ja v a2 s . c om HttpAction<HttpGet> document = test .get("/api/v1/serve?repo=" + repositoryURL + "&ref=master&path=document"); HttpAction<HttpGet> documentFull = test .get("/api/v1/serve?repo=" + repositoryURL + "&ref=master&path=document"); Assert.assertTrue(document.getResponseContent().startsWith("<h1")); Assert.assertTrue(documentFull.getResponseContent().startsWith("<h1")); }
From source file:googleranking.processing.GoogleData.java
public List<String> getLinksInPage() { Document doc = getGoogleHtml(); List<String> ret = new ArrayList<String>(); try {//ww w . j a va 2 s .c o m Elements links = doc.select(".g>.r>a"); for (Element link : links) { String url = link.absUrl("href"); url = URLDecoder.decode(url.substring(url.indexOf("=") + 1, url.indexOf("&")), "UTF-8"); if (url.startsWith("http") || url.startsWith("https")) { ret.add(getDomain(url)); // Ads/news/etc } } } catch (Exception e) { Logger.getLogger(GoogleData.class.getName()).log(Level.SEVERE, null, e); } return ret; }
From source file:org.ocpsoft.redoculous.tests.git.hooks.GithubPostCommitTest.java
@Test public void testPostUpdateHook() throws Exception { WebTest test = new WebTest(baseUrl); String repositoryURL = "file://" + repository.getAbsolutePath(); HttpAction<HttpPost> post = test.post("/api/v1/manage?repo=" + repositoryURL); Assert.assertEquals(201, post.getResponse().getStatusLine().getStatusCode()); String location = URLDecoder.decode(post.getResponseHeaderValue("location"), "UTF8"); Assert.assertEquals(test.getBaseURL() + test.getContextPath() + "/api/v1/serve?repo=" + repositoryURL, location);/*from ww w . j a v a2 s .c om*/ HttpAction<HttpGet> document = test .get("/api/v1/serve?repo=" + repositoryURL + "&ref=master&path=document"); Assert.assertTrue( document.getResponseContent().contains("The following sections will describe both ways in detail")); Files.write(this.document, getClass().getClassLoader().getResourceAsStream("asciidoc/notoc.asciidoc")); repo.add().addFilepattern("document.asciidoc").call(); repo.commit().setMessage("No table of contents.").call(); HttpAction<HttpPost> postCommit = test.post("/api/v1/hooks/github?repo=" + repositoryURL); Assert.assertEquals(200, postCommit.getStatusCode()); document = test.get("/api/v1/serve?repo=" + repositoryURL + "&ref=master&path=document"); Assert.assertTrue(document.getResponseContent().contains("This is a simple document.")); }
From source file:arena.utils.URLUtils.java
public static String decodeURLToken(String in, String encoding) { if (encoding == null) { encoding = "UTF-8"; }/*from w ww . ja v a2 s.co m*/ try { return URLDecoder.decode(in, encoding); } catch (UnsupportedEncodingException err) { throw new RuntimeException("Error url encoding: " + encoding + " input=" + in, err); } }
From source file:de.metanome.backend.algorithm_loading.AlgorithmFinder.java
/** * @param pathToFolder Path to search for jar files * @return an array of Files with ".jar" ending * @throws java.io.UnsupportedEncodingException if the file path could not be decoded in utf-8 *//*from w ww. j a v a2 s. c o m*/ private File[] retrieveJarFiles(String pathToFolder) throws UnsupportedEncodingException { File folder = new File(URLDecoder.decode(pathToFolder, "utf-8")); File[] jars = folder.listFiles(new FilenameFilter() { @Override public boolean accept(File file, String name) { return name.endsWith(".jar"); } }); if (jars == null) { jars = new File[0]; } return jars; }
From source file:com.thinkbiganalytics.metadata.modeshape.user.JcrUserGroup.java
@Nonnull @Override/*from www . j av a 2 s .c o m*/ public String getSystemName() { try { return URLDecoder.decode(JcrPropertyUtil.getName(this.node), ENCODING); } catch (UnsupportedEncodingException e) { throw new IllegalStateException("Unsupported encoding for system name of user: " + this.node, e); } }