List of usage examples for java.net URLDecoder decode
public static String decode(String s, Charset charset)
From source file:com.reever.humilheme.web.CookieController.java
public String getCookie(HttpServletRequest request) { Cookie[] cookies = request.getCookies(); if (cookies != null) { for (Cookie iterator : cookies) { if (iterator.getName().equals(nomeCookie)) { String value = iterator.getValue(); try { return URLDecoder.decode(value, "UTF-8"); } catch (UnsupportedEncodingException e) { _logger.error("Erro no encode do cookie", e); }/*from w w w . java2 s . com*/ break; } } } return null; }
From source file:org.ala.spatial.web.services.MaxentWSController.java
@RequestMapping(value = "/ws/maxent", method = RequestMethod.POST) public @ResponseBody String maxent(HttpServletRequest req) { try {/*from ww w . java 2 s . co m*/ long currTime = System.currentTimeMillis(); String currentPath = AlaspatialProperties.getBaseOutputDir(); String taxon = URLDecoder.decode(req.getParameter("taxonid"), "UTF-8").replace("__", "."); String taxonlsid = URLDecoder.decode(req.getParameter("taxonlsid"), "UTF-8").replace("__", "."); //String species = req.getParameter("species"); //String removedSpecies = req.getParameter("removedspecies"); String area = req.getParameter("area"); String envlist = req.getParameter("envlist"); String txtTestPercentage = req.getParameter("txtTestPercentage"); String chkJackknife = req.getParameter("chkJackknife"); String chkResponseCurves = req.getParameter("chkResponseCurves"); String speciesq = req.getParameter("speciesq"); String bs = req.getParameter("bs"); String resolution = req.getParameter("res"); if (resolution == null) { resolution = "0.01"; } LayerFilter[] filter = null; SimpleRegion region = null; if (area != null && area.startsWith("ENVELOPE")) { filter = LayerFilter.parseLayerFilters(area); } else { region = SimpleShapeFile.parseWKT(area); } String pid = Long.toString(currTime); writeFile(speciesq + "\n" + bs, currentPath + "output" + File.separator + "maxent" + File.separator + pid + File.separator, "species_query.csv"); AnalysisJobMaxent ajm = new AnalysisJobMaxent(pid, currentPath, taxon, envlist, region, filter, txtTestPercentage, chkJackknife, chkResponseCurves, resolution); StringBuffer inputs = new StringBuffer(); inputs.append("pid:").append(pid); inputs.append(";taxonid:").append(taxon); inputs.append(";taxonlsid:").append(taxonlsid); inputs.append(";area:").append(area); inputs.append(";envlist:").append(envlist); inputs.append(";txtTestPercentage:").append(txtTestPercentage); inputs.append(";chkJackknife:").append(chkJackknife); inputs.append(";chkResponseCurves:").append(chkResponseCurves); inputs.append(";resolution:").append(resolution); ajm.setInputs(inputs.toString()); AnalysisQueue.addJob(ajm); return pid; } catch (Exception e) { System.out.println("Error processing Maxent request:"); e.printStackTrace(System.out); } return ""; }
From source file:net.jforum.plugins.tagging.TagAction.java
/** * Find all topics that use the specified tag *//* w ww . j a v a 2 s .c om*/ public void find(@Parameter(key = "tag") String tag) { try { tag = URLDecoder.decode(tag, URLTag.URL_ENCODE); } catch (UnsupportedEncodingException e) { } List<Topic> topics = this.tagService.search(tag, this.userSession.getRoleManager()); propertyBag.put("topics", topics); propertyBag.put("tag", tag); }
From source file:com.github.reverseproxy.ReverseProxyJettyHandler.java
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String requestPath = request.getRequestURI(); String queryString = request.getQueryString(); String method = request.getMethod(); String requestBody = IOUtils.toString(request.getReader()); requestBody = URLDecoder.decode(requestBody, "UTF-8"); //TODO String urlWithFullPath = StringUtils.isEmpty(queryString) ? requestPath : requestPath + "?" + queryString; String forwardUrl = getForwardUrl(urlWithFullPath); if (forwardUrl == null) { throw new IOException("Invalid forwardurl for : " + requestPath); }/* w ww. j av a2 s . c o m*/ URLConnection urlConnection = getUrlConnection(request, method, requestBody, forwardUrl); writeResponse(urlConnection, response); }
From source file:org.ktunaxa.referral.server.mvc.ProxyController.java
@SuppressWarnings("unchecked") @RequestMapping(value = "/proxy") public final void proxyAjaxCall(@RequestParam(required = true, value = "url") String url, HttpServletRequest request, HttpServletResponse response) throws IOException { // URL needs to be url decoded url = URLDecoder.decode(url, "utf-8"); HttpClient client = new HttpClient(); try {/*from w ww . jav a2s . c om*/ HttpMethod method = null; // Split this according to the type of request if ("GET".equals(request.getMethod())) { method = new GetMethod(url); NameValuePair[] pairs = new NameValuePair[request.getParameterMap().size()]; int i = 0; for (Object name : request.getParameterMap().keySet()) { pairs[i++] = new NameValuePair((String) name, request.getParameter((String) name)); } method.setQueryString(pairs); } else if ("POST".equals(request.getMethod())) { method = new PostMethod(url); // Set any eventual parameters that came with our original // request (POST params, for instance) Enumeration paramNames = request.getParameterNames(); while (paramNames.hasMoreElements()) { String paramName = (String) paramNames.nextElement(); ((PostMethod) method).setParameter(paramName, request.getParameter(paramName)); } } else { throw new NotImplementedException("This proxy only supports GET and POST methods."); } // Execute the method client.executeMethod(method); // Set the content type, as it comes from the server Header[] headers = method.getResponseHeaders(); for (Header header : headers) { if (header.getName().equalsIgnoreCase("Content-Type")) { response.setContentType(header.getValue()); } } // Write the body, flush and close response.getOutputStream().write(method.getResponseBody()); } catch (HttpException e) { // log.error("Oops, something went wrong in the HTTP proxy", null, e); response.getOutputStream().write(e.toString().getBytes("UTF-8")); throw e; } catch (IOException e) { e.printStackTrace(); response.getOutputStream().write(e.toString().getBytes("UTF-8")); throw e; } }
From source file:com.foglyn.fogbugz.Utils.java
static String urlDecode(String s) { try {/*w w w .j av a 2 s. c o m*/ return URLDecoder.decode(s, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new IllegalStateException("Cannot encode to UTF-8? Whoops...", e); } }
From source file:com.rossier.shclechelles.service.MyGcmListenerService.java
/** * Called when message is received./*from ww w. ja v a 2 s . c o m*/ * * @param from SenderID of the sender. * @param data Data bundle containing message data as key/value pairs. * For Set of keys use data.keySet(). */ // [START receive_message] @Override public void onMessageReceived(String from, Bundle data) { String message = data.getString("message"); try { message = URLDecoder.decode(message, "UTF-8"); } catch (UnsupportedEncodingException ex) { Log.e(TAG, "Fail to convert to UTF-8"); } Log.d(TAG, "From: " + from); Log.d(TAG, "Message: " + message); if (from.startsWith("/topics/")) { // message received from some topic. } else { // normal downstream message. } // [START_EXCLUDE] /** * Production applications would usually process the message here. * Eg: - Syncing with server. * - Store message in local database. * - Update UI. */ /** * In some cases it may be useful to show a notification indicating to the user * that a message was received. */ sendNotification(from, message); // [END_EXCLUDE] }
From source file:com.company.vertxstarter.api.util.QueryParam.java
public QueryParam(String query) { if (StringUtils.isEmpty(query)) { return;//from w ww. ja v a 2 s. c o m } String encoded = query; try { encoded = URLDecoder.decode(query, "UTF-8"); } catch (UnsupportedEncodingException ex) { Logger.getLogger(QueryParam.class.getName()).log(Level.SEVERE, null, ex); } boolean sortParsed = false; boolean filterParsed = false; for (String token : encoded.split(QUERY_PARAM_DELIMITER_REGEX)) { String pair[] = token.split(QUERY_PARAM_PAIR_DELIMITER_REGEX); if (pair.length != 2) { fail = new Failure("Bad query string format", 400); break; } if (pair[0].equalsIgnoreCase(QUERY_SORT_NAME)) { //sort field if (sortParsed) { fail = new Failure("Sort field must be used only once", 400); break; } if (!parseSortExpressions(pair[1])) { fail = new Failure("Bad sort field format", 400); break; } sortParsed = true; } else if (pair[0].equalsIgnoreCase(QUERY_FILTER_NAME)) { //filter field if (filterParsed) { fail = new Failure("Filter field must be used only once", 400); break; } if (!parseFilterExpressions(pair[1])) { fail = new Failure("Bad filter field format", 400); break; } filterParsed = true; } } }
From source file:cn.quickj.Setting.java
/** * setting.xml???/*from w w w. j a va 2 s . co m*/ * * @param rootPath * @throws Exception * */ public static void load(String rootPath) throws Exception { if (initFinished == true) return; XMLConfiguration config; String settingPath = ""; if (rootPath == null) { // WebApplication Setting.xml String classPath = Thread.currentThread().getContextClassLoader().getResource("").getPath(); Pattern p = Pattern.compile("([\\S]+/)WEB-INF[\\S]+"); Matcher m = p.matcher(classPath); if (m.find()) webRoot = m.group(1); } else webRoot = rootPath; try { webRoot = URLDecoder.decode(webRoot, "utf-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } if (webRoot.endsWith(".xml")) { settingPath = webRoot; int lastPos = webRoot.lastIndexOf('\\'); if (lastPos == -1) lastPos = webRoot.lastIndexOf('/'); webRoot = webRoot.substring(0, lastPos); } else { if (!webRoot.endsWith("/") && !webRoot.endsWith("\\")) webRoot = webRoot + "/"; settingPath = webRoot + "WEB-INF/setting.xml"; } log.info("Loading setting file:" + settingPath); config = new XMLConfiguration(); // ?????? config.setDelimiterParsingDisabled(true); config.load(settingPath); /* * @Deprecated * ????unittest?runserver? * war?XML? String strRunMode = * config.getString("runmode", "development"); if * (strRunMode.equals("production")) runMode = PROD_MODE; else if * (strRunMode.equals("test")) runMode = TEST_MODE; else runMode = * DEV_MODE; */ String strRunMode = getRunMode(); packageRoot = config.getString("package", packageRoot); fieldBySetter = config.getBoolean("web.fieldBySetter", false); DEFAULT_CHARSET = config.getString("web.charset", "utf-8"); longDateFormat = config.getString("web.long-dateformat", "yyyy-MM-dd HH:mm:ss"); license = config.getString("license"); shortDateFormat = config.getString("web.short-dateformat", "yyyy-MM-dd"); String strLocale = config.getString("web.locale", Locale.getDefault().getDisplayName()); theme = config.getString("web.theme"); locale = new Locale(strLocale); sessionClass = config.getString("web.session.class", "cn.quickj.session.MemHttpSession"); sessionDomain = config.getString("web.session.domain", null); sessionTimeOut = config.getInt("web.session.timeout", 30 * 60); defaultUri = config.getString("web.defaultUri"); uploadDir = config.getString("web.upload.directory", System.getProperty("java.io.tmpdir")); uploadMaxSize = config.getInt("web.upload.max-size", 4096); jdbcDriver = config.getString("database." + strRunMode + ".driver", ""); usedb = (jdbcDriver.length() != 0); jdbcUser = config.getString("database." + strRunMode + ".user", "root"); jdbcUrl = config.getString("database." + strRunMode + ".url", ""); jdbcPassword = config.getString("database." + strRunMode + ".password", ""); maxActive = config.getInt("database." + strRunMode + ".pool.maxActive", 10); initActive = config.getInt("database." + strRunMode + ".pool.initActive", 2); maxIdle = config.getInt("database." + strRunMode + ".pool.maxIdle", 1800); dialect = config.getString("database." + strRunMode + ".dialect", null); tablePrefix = config.getString("database.prefix", ""); cacheClass = config.getString("cache.class", "cn.quickj.cache.SimpleCache"); cacheParam = config.getString("cache.param", "capacity=50000"); // ?? queueEnabled = "true".equalsIgnoreCase(config.getString("queue.enable", "false")); queueParam = config.getString("queue.param", "capacity=50000"); loadPlugin(config); loadApplicationConfig(); initFinished = true; }
From source file:com.github.yongchristophertang.engine.web.response.PrintResultHandler.java
/** * Print the given result to log system. * * @param result the result of the executed request * @throws Exception if a failure occurs *//*from w w w . j av a 2s . c o m*/ @Override public void handle(HttpResult result) throws Exception { RequestLine rl = result.getHttpRequest().getRequestLine(); String body = null; String formatter = "HTTP Request&Response Log: \n\n \t API: {} \n\n\t Request URL: {} \n\n \t "; if (rl.getMethod().equals("POST") || rl.getMethod().equals("PUT") || rl.getMethod().equals("PATCH")) { try { body = URLDecoder.decode( EntityUtils.toString(((HttpEntityEnclosingRequest) result.getHttpRequest()).getEntity()), "UTF-8"); formatter += "Request Body (URL Decoded): {} \n\n \t "; } catch (UnsupportedOperationException e) { formatter += "Multipart Body Cannot Be Displayed which is {}. \n\n \t "; } catch (IllegalArgumentException e) { formatter += "Request Body: {} \n\n \t "; } } else { formatter += "Request Body Not Applicable: {}\n\n \t "; } formatter += "Request Headers: {} \n\n \t Cost Time(ms): {} \n\n \t Response Status: {} \n\n \t Response Headers: {} " + "\n\n \t " + "Response Content: \n {} \n=======================================================================\n"; logger.info(formatter, result.getRequestDescritpion(), rl, body, Lists.newArrayList(result.getHttpRequest().getAllHeaders()), result.getCostTime(), result.getHttpResponse().getStatusLine(), Lists.newArrayList(result.getHttpResponse().getAllHeaders()), getPrettyJsonPrint(result.getResponseStringContent())); }