List of usage examples for java.net URLDecoder decode
public static String decode(String s, Charset charset)
From source file:com.spartasystems.holdmail.mime.MimeUtils.java
/** * Perform a {@link URLDecoder#decode(String, String)} but provide some null safety * @param value The value to decode/*from w ww. j a va2 s. co m*/ * @param encoding The enconding * @return The decoded string, or the original string if either the value or encoding were invalid. */ public static String safeURLDecode(final String value, final String encoding) { if (StringUtils.isBlank(value)) { logger.warn("No value was provided for decoding"); return value; } if (StringUtils.isBlank(encoding)) { logger.warn("No encoding name was provided for decoding, returning original value"); return value; } try { return URLDecoder.decode(value, encoding); } catch (UnsupportedEncodingException e) { logger.error("Couldn't decode value with encoding '" + encoding + "': " + e.getMessage() + ", value was:" + value); return value; } }
From source file:org.ocpsoft.redoculous.tests.git.hooks.GithubPostCommitRealTest.java
@Test public void testPostUpdateRealHook() throws Exception { WebTest test = new WebTest(baseUrl); String repositoryURL = "https://github.com/ocpsoft/rewrite.git"; // String repositoryURL = "file:///Users/lb3/projects/ocpsoft/rewrite"; 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 w ww. ja v a2s . c o m HttpAction<HttpGet> document = test .get("/api/v1/serve?repo=" + repositoryURL + "&ref=master&path=/documentation/src/main/asciidoc/"); Assert.assertEquals(200, document.getStatusCode()); Assert.assertTrue(document.getResponseContent().contains("Learn Rewrite")); 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=/documentation/src/main/asciidoc/"); Assert.assertEquals(200, document.getStatusCode()); Assert.assertTrue(document.getResponseContent().contains("Learn Rewrite")); }
From source file:model.SentinelHttpParamVirt.java
@Override public String getDecodedValue() { String mutatedValue = ""; switch (encoderType) { case Base64://from w w w. jav a 2s . com byte[] mutated = BurpCallbacks.getInstance().getBurp().getHelpers().base64Decode(value); mutatedValue = "BASE64: " + new String(mutated); break; case URL: try { BurpCallbacks.getInstance().print("A: " + value); mutatedValue = "URL: " + URLDecoder.decode(value, "UTF-8"); } catch (UnsupportedEncodingException ex) { Logger.getLogger(SentinelHttpParamVirt.class.getName()).log(Level.SEVERE, null, ex); } break; case HTML: mutatedValue = "HTML: " + StringEscapeUtils.unescapeHtml4(value); break; default: mutatedValue = value; } return mutatedValue; }
From source file:it.marcoberri.mbfasturl.helper.ConfigurationHelper.java
private ConfigurationHelper() { try {/*from w ww . j a v a2 s . c o m*/ final URL main = getClass().getProtectionDomain().getCodeSource().getLocation(); final String path = URLDecoder.decode(main.getPath(), "utf-8"); final String webInfFolderPosition = new File(path).getPath(); final String webInfFolder = webInfFolderPosition.substring(0, webInfFolderPosition.indexOf("classes")); prop = new Properties(); prop.load(FileUtils.openInputStream(new File(webInfFolder + File.separator + "config.properties"))); final JSONParser parser = new JSONParser(); final Object obj = parser.parse(new FileReader(webInfFolder + File.separator + "cron.json")); final JSONObject jsonObject = (JSONObject) obj; ConfigurationHelper.cron = (JSONArray) jsonObject.get("cron"); } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } catch (ParseException ex) { throw new RuntimeException(ex.getMessage(), ex); } }
From source file:com.google.youtube.captions.AuthSubLogin.java
@Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { try {//from w ww .java2 s .c o m String authSubToken = AuthSubUtil.getTokenFromReply(req.getQueryString()); if (authSubToken == null) { throw new IllegalStateException("Could not parse token from AuthSub response."); } else { authSubToken = URLDecoder.decode(authSubToken, "UTF-8"); } authSubToken = AuthSubUtil.exchangeForSessionToken(authSubToken, null); YouTubeService service = new YouTubeService(SystemProperty.applicationId.get(), Util.DEVELOPER_KEY); service.setAuthSubToken(authSubToken); UserProfileEntry profileEntry = service.getEntry(new URL(PROFILE_URL), UserProfileEntry.class); String username = profileEntry.getUsername(); String authSubCookie = Util.getCookie(req, Util.AUTH_SUB_COOKIE); JSONObject cookieAsJSON = new JSONObject(); if (!Util.isEmptyOrNull(authSubCookie)) { try { cookieAsJSON = new JSONObject(authSubCookie); } catch (JSONException e) { LOG.log(Level.WARNING, "Unable to parse JSON from the existing cookie: " + authSubCookie, e); } } try { cookieAsJSON.put(username, authSubToken); } catch (JSONException e) { LOG.log(Level.WARNING, String.format("Unable to add account '%s' and AuthSub token '%s'" + " to the JSON object.", username, authSubToken), e); } Cookie cookie = new Cookie(Util.AUTH_SUB_COOKIE, cookieAsJSON.toString()); cookie.setMaxAge(Util.COOKIE_LIFETIME); resp.addCookie(cookie); cookie = new Cookie(Util.CURRENT_AUTHSUB_TOKEN, authSubToken); cookie.setMaxAge(Util.COOKIE_LIFETIME); resp.addCookie(cookie); cookie = new Cookie(Util.CURRENT_USERNAME, username); cookie.setMaxAge(Util.COOKIE_LIFETIME); resp.addCookie(cookie); } catch (IllegalStateException e) { LOG.log(Level.WARNING, "", e); } catch (AuthenticationException e) { LOG.log(Level.WARNING, "", e); } catch (GeneralSecurityException e) { LOG.log(Level.WARNING, "", e); } catch (ServiceException e) { LOG.log(Level.WARNING, "", e); } resp.sendRedirect("/"); }
From source file:com.us.util.FileHelper.java
/** * //ww w .ja v a 2 s. c o m * * @param packName ?? * @param fileName ?? * @return */ public static InputStream getFileInPackage(String packName, String fileName) { try { String packdir = packName.replace('.', '/'); Enumeration<URL> dirs = Thread.currentThread().getContextClassLoader().getResources(packdir); while (dirs.hasMoreElements()) { URL url = dirs.nextElement(); if (url.getProtocol().equals("file")) { String filePath = URLDecoder.decode(url.getFile(), "UTF-8"); return new FileInputStream(filePath + "/" + fileName); } else if (url.getProtocol().equals("jar")) { return FileHelper.class.getClassLoader() .getResourceAsStream(packdir.concat("/").concat(fileName)); } } } catch (IOException e) { throw UsMsgException.newInstance(String.format(":%s.%s", packName, fileName), e); } return null; }
From source file:neembuu.httpserver.VFSHandler.java
@Override public void handle(final HttpRequest request, final HttpResponse response, final HttpContext context) throws HttpException, IOException { String method = request.getRequestLine().getMethod().toUpperCase(Locale.ENGLISH); if (!method.equals("GET") && !method.equals("HEAD") && !method.equals("POST")) { throw new MethodNotSupportedException(method + " method not supported"); }/*from w w w . j a va2 s .com*/ String target = request.getRequestLine().getUri(); if (request instanceof HttpEntityEnclosingRequest) { HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity(); byte[] entityContent = EntityUtils.toByteArray(entity); System.out.println("Incoming entity content (bytes): " + entityContent.length); } String filePath = URLDecoder.decode(target, "UTF-8"); FileAttributesProvider fap = fs.open(filePath.split("/")); if (fap == null) { response.setStatusCode(HttpStatus.SC_NOT_FOUND); StringEntity entity = new StringEntity( "<html><body><h1>File" + filePath + " not found</h1></body></html>", ContentType.create("text/html", "UTF-8")); response.setEntity(entity); System.out.println("File " + filePath + " not found"); } else if (fap.getFileType() != FileType.FILE || !(fap instanceof AbstractFile)) { response.setStatusCode(HttpStatus.SC_FORBIDDEN); StringEntity entity = new StringEntity("<html><body><h1>Access denied</h1></body></html>", ContentType.create("text/html", "UTF-8")); response.setEntity(entity); System.out.println("Cannot read file " + filePath + " fap=" + fap); } else { long offset = Utils.standardOffsetResponse(request, response, fap.getFileSize()); response.setStatusCode(HttpStatus.SC_OK); VFileEntity body = new VFileEntity((AbstractFile) fap, offset); response.setEntity(body); System.out.println("Serving file " + filePath); } }
From source file:edu.jhu.pha.vospace.node.VospaceId.java
public VospaceId(String idStr) throws URISyntaxException { URI voURI = new URI(idStr); if (!validId(voURI)) { throw new URISyntaxException(idStr, "InvalidURI"); }// w w w .ja v a 2 s . c om if (!StringUtils.contains(idStr, "vospace")) { throw new URISyntaxException(idStr, "InvalidURI"); } this.uri = StringUtils.substringBetween(idStr, "vos://", "!vospace"); if (this.uri == null) throw new URISyntaxException(idStr, "InvalidURI"); try { String pathStr = URLDecoder.decode(StringUtils.substringAfter(idStr, "!vospace"), "UTF-8"); this.nodePath = new NodePath(pathStr); } catch (UnsupportedEncodingException e) { // should not happen logger.error(e.getMessage()); } }
From source file:com.pfw.popsicle.common.Encodes.java
/** * URL ?, EncodeUTF-8. // ww w. j av a 2s. co m */ public static String urlDecode(String part) { try { return URLDecoder.decode(part, DEFAULT_URL_ENCODING); } catch (UnsupportedEncodingException e) { } return part; }
From source file:fr.putnami.pwt.plugin.ajaxbot.filter.AjaxPageFilter.java
private static String rewriteQueryString(String queryString) throws UnsupportedEncodingException { StringBuilder queryStringSb = new StringBuilder(queryString); int i = queryStringSb.indexOf("&" + QUERY_PARAM_ESCAPED_FRAGMENT); if (i != -1) { StringBuilder tmpSb = new StringBuilder(queryStringSb.substring(0, i)); tmpSb.append("#!"); tmpSb.append(URLDecoder.decode(queryStringSb.substring(i + 20, queryStringSb.length()), "UTF-8")); queryStringSb = tmpSb;// w w w .ja v a 2 s . c o m } i = queryStringSb.indexOf(QUERY_PARAM_ESCAPED_FRAGMENT); if (i != -1) { StringBuilder tmpSb = new StringBuilder(queryStringSb.substring(0, i)); tmpSb.append("#!"); tmpSb.append(URLDecoder.decode(queryStringSb.substring(i + 19, queryStringSb.length()), "UTF-8")); queryStringSb = tmpSb; } if (queryStringSb.indexOf("#!") != 0) { queryStringSb.insert(0, '?'); } return queryStringSb.toString(); }