List of usage examples for java.net URLDecoder decode
public static String decode(String s, Charset charset)
From source file:Main.java
private static String decode(String filespec) { try {/*from w ww . j a va2s.c o m*/ return URLDecoder.decode(filespec, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException("Error decoding filespec: " + filespec, e); } }
From source file:com.openbravo.pos.forms.AppConfig.java
public String getConfigFile(String rootPath, String fileName, int level) throws Exception { if (level < 2) { String path = rootPath;/*from ww w . ja v a2 s. com*/ if (path == null) { path = AppConfig.class.getProtectionDomain().getCodeSource().getLocation().getPath(); } logger.info(">>>>>>>>>>>>>>> current path : " + level + " : " + path); path = new File(URLDecoder.decode(path, "UTF-8")).getAbsolutePath(); if (StringUtils.isNotEmpty(path)) { int i = path.lastIndexOf(File.separator); if (i > 0) { path = path.substring(0, i); String npath = path + File.separator + fileName; File f = new File(npath); if (f.exists()) { return f.getAbsolutePath(); } else { //try 1 uplevel return getConfigFile(path, fileName, ++level); } } } } return null; }
From source file:ru.apertum.qsystem.reports.net.NetUtil.java
public static synchronized HashMap<String, String> getParameters(HttpRequest request) { final String method = request.getRequestLine().getMethod().toUpperCase(Locale.ENGLISH); final HashMap<String, String> res = new HashMap<>(); final String data; if (method.equals("GET")) { String[] ss = request.getRequestLine().getUri().split("\\?"); if (ss.length == 2) { try { data = URLDecoder.decode(request.getRequestLine().getUri().split("\\?")[1], "utf-8"); } catch (UnsupportedEncodingException ex) { throw new ReportException(ex.toString()); }// ww w.j av a 2 s .c om } else { data = ""; } } else { data = getEntityContent(request); } String[] ss = data.split("&"); for (String str : ss) { String[] ss1 = str.split("="); if (!ss1[0].isEmpty()) { res.put(ss1[0], ss1.length == 1 ? "" : ss1[1]); } } return res; }
From source file:org.ednovo.gooru.controller.ScreenshotController.java
/** * Get and check parameters//from w w w . jav a 2 s . co m * * @param sourceUrl * (URL should be encoded) * @param width * @param height * @param request * @param response * @throws Exception */ @RequestMapping(method = RequestMethod.GET, value = "/snapshot/generate/{width}/{height}") public void getScreenshot(@PathVariable(value = "width") int width, @PathVariable(value = "height") int height, @RequestParam(value = "SourceUrl", required = true) String sourceUrl, HttpServletRequest request, HttpServletResponse response) throws Exception { sourceUrl = URLDecoder.decode(sourceUrl, ENCODE_FORMAT); if (checkUrl(sourceUrl)) { response.setStatus(400); response.getWriter().append(INVALID_URL); return; } else { response.getOutputStream().write(getWebDriverUtil().generateScreenshot(sourceUrl, width, height)); } }
From source file:com.microsoft.alm.plugin.idea.starters.SimpleCheckoutStarter.java
/** * Creates a SimpleCheckoutStarter object after parsing the URI attributes for the Git Url and Url encoding if provided * * @param args Uri attributes/*w ww. j a v a2s . com*/ * @return SimpleCheckoutStarter with URI's decoded Git Url * @throws RuntimeException * @throws UnsupportedEncodingException */ public static SimpleCheckoutStarter createWithUriAttributes(Map<String, String> args) throws RuntimeException, UnsupportedEncodingException { String url = args.get(URL_ARGUMENT); String encoding = args.get(ENCODING_ARGUMENT); if (StringUtils.isEmpty(url)) { throw new RuntimeException( TfPluginBundle.message(TfPluginBundle.STARTER_ERRORS_SIMPLECHECKOUT_URI_MISSING_GIT_URL)); } // if an encoding scheme is found then decode the url if (StringUtils.isNotEmpty(encoding)) { url = URLDecoder.decode(url, encoding); } return createWithGitUrl(url); }
From source file:net.shopxx.util.CookieUtils.java
/** * ?cookie/* w w w . j a v a 2 s.c o m*/ * * @param request * HttpServletRequest * @param name * cookie?? * @return ?null */ public static String getCookie(HttpServletRequest request, String name) { Assert.notNull(request); Assert.hasText(name); Cookie[] cookies = request.getCookies(); if (cookies != null) { try { for (Cookie cookie : cookies) { if (name.equals(cookie.getName())) { return URLDecoder.decode(cookie.getValue(), "UTF-8"); } } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } return null; }
From source file:com.envision.envservice.filter.AccessLogFilter.java
private void logAccessAPI(HttpServletRequest request) { try {// w w w . j a v a 2 s. c om UserBo user = (UserBo) request.getSession().getAttribute(Constants.SESSION_USER); String userId = user != null ? user.getUser_id() : "NOT_LOGIN"; String remoteAddr = IPUtil.getRemoteAddr(request); String method = request.getMethod(); String requestURI = request.getRequestURI(); String userAgent = StringUtils.defaultString(request.getHeader("User-Agent")); String queryString = request.getQueryString(); if (queryString != null) { queryString = URLDecoder.decode(request.getQueryString(), Constants.CHARSET); } requestURI = requestURI + (StringUtils.isNotEmpty(queryString) ? ("?" + queryString) : StringUtils.EMPTY); EnvLog.getAccessAPILogger().info( String.format("[%s] [%s] [%s] %s [%s]", userId, remoteAddr, method, requestURI, userAgent)); } catch (Exception e) { EnvLog.getAccessAPILogger().warn("AccessAPI logger error: " + e.getMessage(), e); } }
From source file:mitm.common.net.NetUtils.java
/** * Parses the provided URL query and returns a map with all names to values. The values are URL decoded. If * toLowercase is true the keys of the map will be converted to lowecase. * /*from ww w . j a v a 2 s. c o m*/ * Example: * test=123&value=%27test%27&value=abc maps to test -> [123] and value -> ["test", abc] * @throws IOException */ public static Map<String, String[]> parseQuery(String query, boolean toLowercase) throws IOException { Map<String, String[]> map = new HashMap<String, String[]>(); if (query == null) { return map; } String[] elements = StringUtils.split(query, '&'); for (String element : elements) { element = element.trim(); if (StringUtils.isEmpty(element)) { continue; } String name; String value; int i = element.indexOf('='); if (i > -1) { name = StringUtils.substring(element, 0, i); value = StringUtils.substring(element, i + 1); } else { name = element; value = ""; } name = StringUtils.trimToEmpty(name); value = StringUtils.trimToEmpty(value); if (toLowercase) { name = name.toLowerCase(); } value = URLDecoder.decode(value, CharacterEncoding.UTF_8); String[] updated = (String[]) ArrayUtils.add(map.get(name), value); map.put(name, updated); } return map; }
From source file:org.apache.servicecomb.it.schema.DownloadSchema.java
public DownloadSchema() throws IOException { FileUtils.deleteQuietly(tempDir);//from w ww . j a va 2s .c o m FileUtils.forceMkdir(tempDir); // for download from net stream case server = ServerBootstrap.bootstrap().setListenerPort(0) .registerHandler("/download/netInputStream", (req, resp, context) -> { String uri = req.getRequestLine().getUri(); String query = URI.create(uri).getQuery(); int idx = query.indexOf('='); String content = query.substring(idx + 1); content = URLDecoder.decode(content, StandardCharsets.UTF_8.name()); resp.setEntity(new StringEntity(content, StandardCharsets.UTF_8.name())); }).create(); server.start(); }
From source file:com.navercorp.pinpoint.web.filter.DefaultFilterBuilder.java
private String decode(String value) { if (value == null) { return null; }//from w w w . j av a2s . c o m try { return URLDecoder.decode(value, StandardCharsets.UTF_8.name()); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException("UTF8 decodeFail. value:" + value); } }