List of usage examples for java.net URLDecoder decode
public static String decode(String s, Charset charset)
From source file:com.topsem.common.utils.Encodes.java
/** * URL ?, EncodeUTF-8.// w w w . j a v a 2 s .c om */ public static String urlDecode(String part) { try { return URLDecoder.decode(part, DEFAULT_URL_ENCODING); } catch (UnsupportedEncodingException e) { throw Throwables.propagate(e); } }
From source file:org.springframework.social.facebook.api.impl.PagedListUtils.java
private static String extractEncodedParameterValueFromUrl(String url, String paramName) { try {/* w ww. j a v a 2 s . c om*/ String value = extractParameterValueFromUrl(url, paramName); return value != null ? URLDecoder.decode(value, "UTF-8") : null; } catch (UnsupportedEncodingException e) { // shouldn't happen return null; } }
From source file:nl.flotsam.calendar.web.UriHttpMessageConverter.java
@Override protected URI readInternal(Class<? extends URI> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException { InputStream in = null;/* w ww .j a v a 2s . c o m*/ try { in = inputMessage.getBody(); String uri = IOUtils.toString(in); if (inputMessage.getHeaders().getContentType() == MediaType.APPLICATION_FORM_URLENCODED) { uri = URLDecoder.decode(uri, "UTF-8"); } return new URI(uri); } catch (URISyntaxException urie) { throw new HttpMessageNotReadableException("Failed to parse incoming String into a URI.", urie); } finally { IOUtils.closeQuietly(in); } }
From source file:com.anybuy.util.EncodeUtil.java
/** * URL ?, EncodeUTF-8.//from www . ja v a 2 s. co m */ public static String urlDecode(String part) { try { return URLDecoder.decode(part, DEFAULT_URL_ENCODING); } catch (UnsupportedEncodingException e) { throw ExceptionUtil.unchecked(e); } }
From source file:cn.tonghao.remex.business.core.util.security.Encodes.java
/** * URL ?, EncodeUTF-8./* w ww.j a v a2s.co m*/ */ public static String urlDecode(String part) { try { return URLDecoder.decode(part, DEFAULT_URL_ENCODING); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
From source file:me.smoe.lzy.filter.AccessLogFilter.java
private void logAccessAPI(HttpServletRequest request) { try {/*from w w w . j a v a2 s . c o m*/ User user = (User) request.getSession().getAttribute(Constants.SESSION_USER); String userId = user != null ? user.getId() : "NOT_LOGIN"; String remoteAddr = request.getRemoteAddr(); 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); Logger.getRestAccessLogger().info( String.format("[%s] [%s] [%s] %s [%s]", userId, remoteAddr, method, requestURI, userAgent)); } catch (Exception e) { Logger.getRestAccessLogger().warn("AccessAPI logger error: " + e.getMessage(), e); } }
From source file:com.hurence.logisland.utils.HttpUtils.java
public static void populateKeyValueListFromUrlQuery(String urlQuery, List<String> keys, List<String> values) { try {//from ww w . j av a2s . co m if (urlQuery == null) { return; } for (String param : urlQuery.split("&")) { try { QueryParam queryParam = new QueryParam(); String[] pair = param.split("="); if (pair.length == 0) { continue; } String value = ""; String key = URLDecoder.decode(pair[0], "UTF-8"); if (key != null && !key.equals("null")) { keys.add(key); } if (pair.length > 1) { value = URLDecoder.decode(pair[1], "UTF-8"); } if (value != null && !value.equals("null")) { values.add(value); } } catch (IllegalArgumentException ex) { log.debug("error decoding value : " + ex); } } } catch (UnsupportedEncodingException ex) { throw new AssertionError(ex); } }
From source file:acromusashi.stream.component.json.camel.JsonExtractor.java
/** * Exchange?Value?<br>/*from www . ja va 2 s . c om*/ * Value???????????<br> * isDoValidate==true???JSON??????????? * * @param exchange ?Exchange */ public void extractJson(Exchange exchange) { InputStreamCache iscache = exchange.getIn().getBody(InputStreamCache.class); String postStr = null; try { postStr = IOUtils.toString(iscache); postStr = URLDecoder.decode(postStr, "utf-8"); } catch (IOException ioex) { logger.warn("Failed to extract string from Request. Dispose request.", ioex); return; } int firstSeparatorIndex = postStr.indexOf(KEYVALUE_SEPARATOR); if (firstSeparatorIndex == -1) { String logFormat = "Received request is invalid. Dispose request. : Request={0}"; String logMessage = MessageFormat.format(logFormat, postStr); logger.warn(logMessage); return; } String jsonStr = postStr.substring(firstSeparatorIndex + 1); if (this.isDoValidate == false) { exchange.getOut().setBody(jsonStr); return; } JSONObject jsonObj = null; try { jsonObj = JSONObject.fromObject(jsonStr); } catch (JSONException jsonex) { logger.warn("Received request is invalid. Dispose request.", jsonex); return; } exchange.getOut().setBody(jsonObj.toString()); }
From source file:de.dfki.km.perspecting.obie.corpus.BBCNatureCorpus.java
public Reader getGroundTruth(final URI uri) throws Exception { if (labelFileMediaType == MediaType.DIRECTORY) { return new StringReader(FileUtils.readFileToString(new File(uri))); } else if (labelFileMediaType == MediaType.ZIP) { ZipFile zipFile = new ZipFile(labelFolder); String[] entryName = uri.toURL().getFile().split("/"); ZipEntry entry = zipFile//from w w w.j a v a 2s . co m .getEntry(URLDecoder.decode(entryName[entryName.length - 1], "utf-8").replace("text", "rdf")); if (entry != null) { log.info("found labels for: " + uri.toString()); } else { throw new Exception("did not found labels for: " + uri.toString()); } return new InputStreamReader(zipFile.getInputStream(entry)); } else { throw new Exception("Unsupported media format for labels: " + labelFileMediaType + ". " + "Please use zip or plain directories instead."); } }
From source file:com.baidu.stqa.signet.web.action.StoryAction.java
/** * story/* www . ja va 2s . c om*/ * @param projectId * @param projectName * @param conditions * @param searchFlag * @return * @throws UnsupportedEncodingException */ @RequestMapping(value = "/project/{projectId}/story", method = RequestMethod.GET) @ResponseBody public ResponseEntity<Map<String, Object>> queryStory(@PathVariable long projectId, String projectName, String conditions, boolean searchFlag) throws UnsupportedEncodingException { doLog(projectId); String user = getUser(); if (!searchFlag) { conditions = conditionService.queryUserCondition(user, projectId); } else { conditionService.saveUserCondition(user, projectId, URLDecoder.decode(conditions, "utf-8")); } List<Story> storyList = storyService.listStory(projectId, projectName, conditions); List<Long> ids = new ArrayList<Long>(); for (Story story : storyList) { ids.add(story.getId()); } Map<Long, Statistics> statisticsMap = statisticsService.queryTestProgress(ids, projectId); for (Story story : storyList) { story.setTestedCaseNum(statisticsMap.get(story.getId()).getTestedCaseNum()); story.setTotalCaseNum(statisticsMap.get(story.getId()).getTotalCaseNum()); } Map<String, Object> resultMap = new HashMap<String, Object>(); resultMap.put("storyList", storyList); resultMap.put("conditions", conditions); return new ResponseEntity<Map<String, Object>>(resultMap, HttpStatus.OK); }