List of usage examples for java.net URLDecoder decode
public static String decode(String s, Charset charset)
From source file:com.gnamp.struts.action.TerminalSettingAction.java
private static String _ConfigRoot() { try {// ww w .j a va 2 s. c o m String classDirectory = TerminalSettingAction.class.getClassLoader().getResource("/").getPath(); classDirectory = URLDecoder.decode(classDirectory, "UTF-8"); File f = new File(classDirectory); f = f.getParentFile(); f = f.getParentFile(); return f.getAbsolutePath() + File.separatorChar + "gnamp_work" + File.separatorChar + "device"; } catch (Exception ex) { } return ""; }
From source file:com.tops.hotelmanager.util.CommonHttpClient.java
public static String executeGetRequest(String url, Map<String, String> map, Map<String, String> header, int timeOut) { HttpClient client = new HttpClient(); client.getHttpConnectionManager().getParams().setSoTimeout(timeOut); client.getHttpConnectionManager().getParams().setConnectionTimeout(timeOut); StringBuilder sb = new StringBuilder(url); GetMethod get = null;/*from ww w.j av a 2 s . com*/ try { if (map != null && map.size() > 0) { sb.append("?"); int i = 0; for (Map.Entry<String, String> entry : map.entrySet()) { if (i == 0) { sb.append(entry.getKey()).append("=").append(URLEncoder.encode(entry.getValue(), "UTF-8")); i = 1; } else { sb.append("&").append(entry.getKey()).append("=") .append(URLEncoder.encode(entry.getValue(), "UTF-8")); } } } if (logger.isDebugEnabled()) { logger.debug("Requested URL : " + URLDecoder.decode(sb.toString(), "UTF-8")); } get = new GetMethod(sb.toString()); if (header != null && header.size() > 0) { for (Map.Entry<String, String> entry : header.entrySet()) { get.addRequestHeader(entry.getKey(), entry.getValue()); } } int i = client.executeMethod(get); if (i != -1) { String response = get.getResponseBodyAsString(); /* * if (logger.isDebugEnabled()) { logger.debug("Response : " + * response); } */ return response; } } catch (Exception e) { logger.error("HttpClient get method error url: " + url + ", Parameters: " + map, e); } finally { if (get != null) { get.releaseConnection(); } } return "error~Request Failed"; }
From source file:edu.cornell.mannlib.vitro.webapp.filters.VitroURL.java
public VitroURL(String urlStr, String characterEncoding) { this.characterEncoding = characterEncoding; if (urlStr.indexOf("&") > -1) { wasXMLEscaped = true;//from w ww . ja v a 2 s . c om urlStr = StringEscapeUtils.unescapeXml(urlStr); } try { URL url = new URL(urlStr); this.protocol = url.getProtocol(); this.host = url.getHost(); this.port = Integer.toString(url.getPort()); this.pathParts = splitPath(url.getPath()); this.pathBeginsWithSlash = beginsWithSlash(url.getPath()); this.pathEndsInSlash = endsInSlash(url.getPath()); this.queryParams = parseQueryParams(url.getQuery()); this.fragment = url.getRef(); } catch (Exception e) { // Under normal circumstances, this is because the urlStr is relative // We'll assume that we just have a path and possibly a query string. // This is likely to be a bad assumption, but let's roll with it. Matcher m = pathPattern.matcher(urlStr); String[] urlParts = new String[2]; if (m.matches()) { urlParts[0] = m.group(1); if (m.groupCount() == 2) urlParts[1] = m.group(2); } else { //??? } try { this.pathParts = splitPath(URLDecoder.decode(getPath(urlStr), characterEncoding)); this.pathBeginsWithSlash = beginsWithSlash(urlParts[0]); this.pathEndsInSlash = endsInSlash(urlParts[0]); if (urlParts.length > 1) { this.queryParams = parseQueryParams(URLDecoder.decode(urlParts[1], characterEncoding)); } } catch (UnsupportedEncodingException uee) { log.error("Unable to use character encoding " + characterEncoding, uee); } } }
From source file:com.piusvelte.hydra.HydraRequest.java
private HydraRequest(HttpServletRequest request) throws UnsupportedEncodingException { String[] parts = getPathParts(request); database = parts[DATABASE];/*from w w w . j a va2 s .c om*/ target = parts[TARGET]; columns = unpackArray(request.getParameter(PARAM_COLUMNS)); values = unpackArray(request.getParameter(PARAM_VALUES)); arguments = unpackArray(request.getParameter(PARAM_ARGUMENTS)); selection = request.getParameter(PARAM_SELECTION); if (selection != null) { selection = URLDecoder.decode(selection, "UTF-8"); } String q = request.getParameter(PARAM_QUEUEABLE); if (q != null) { queueable = Boolean.parseBoolean(q); } command = request.getParameter(PARAM_COMMAND); if (command != null) { command = URLDecoder.decode(command, "UTF-8"); } }
From source file:org.cee.highlighter.impl.ContentHighlightHandler.java
private String decode(String input) { try {//from w w w. jav a2 s .co m return URLDecoder.decode(input, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
From source file:info.magnolia.cms.util.RequestFormUtil.java
/** * The url is not always properly decoded. This method does the job. * @param request/*from www .jav a 2 s . c o m*/ * @param charset * @return decoded map of all values */ public static Map getURLParametersDecoded(HttpServletRequest request, String charset) { Map map = new HashMap(); String queryString = request.getQueryString(); if (queryString != null) { String[] params = request.getQueryString().split("&"); for (int i = 0; i < params.length; i++) { String name = StringUtils.substringBefore(params[i], "="); String value = StringUtils.substringAfter(params[i], "="); try { value = URLDecoder.decode(value, charset); } catch (UnsupportedEncodingException e) { // nothing: return value as is } map.put(name, value); } } return map; }
From source file:com.github.achatain.catalog.servlet.IndexIdServlet.java
@Override protected void doDelete(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { final String userId = getUserId(req); final String colId = extractCollectionIdFromRequest(req); final String fieldName = URLDecoder.decode(extractFieldNameFromRequest(req), CharEncoding.UTF_8); LOG.info(format("User [%s] to delete the following index [%s] in the collection [%s]", userId, fieldName, colId));//from www . ja va2 s. com final IndexMessage indexMessage = IndexMessage.create().withUserId(userId).withColId(colId) .withFieldName(fieldName).build(); jmsContext.createProducer().send(indexDropDestination, indexMessage); }
From source file:com.hypersocket.auth.json.AuthenticatedController.java
AuthenticationState createAuthenticationState(String scheme, HttpServletRequest request, HttpServletResponse response) throws AccessDeniedException, UnsupportedEncodingException { Map<String, Object> environment = new HashMap<String, Object>(); for (BrowserEnvironment env : BrowserEnvironment.values()) { if (request.getHeader(env.toString()) != null) { environment.put(env.toString(), request.getHeader(env.toString())); }/*from ww w. j av a 2 s. c o m*/ } AuthenticationState state = authenticationService.createAuthenticationState(scheme, request.getRemoteAddr(), environment, sessionUtils.getLocale(request)); Enumeration<?> names = request.getParameterNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); state.addParameter(name, URLDecoder.decode(request.getParameter(name), "UTF-8")); } request.getSession().setAttribute(AUTHENTICATION_STATE_KEY, state); return state; }
From source file:com.liferay.portal.jsonwebservice.JSONWebServiceConfigurator.java
public void configure(ClassLoader classLoader) throws PortalException, SystemException { File[] classPathFiles = null; if (classLoader != null) { URL servicePropertiesURL = classLoader.getResource("service.properties"); String servicePropertiesPath = null; try {// w ww . j a v a2 s.co m servicePropertiesPath = URLDecoder.decode(servicePropertiesURL.getPath(), StringPool.UTF8); } catch (UnsupportedEncodingException uee) { throw new SystemException(uee); } File classPathFile = null; File libDir = null; int pos = servicePropertiesPath.indexOf("_wl_cls_gen.jar!"); if (pos != -1) { String wlClsGenJarPath = servicePropertiesPath.substring(0, pos + 15); classPathFile = new File(wlClsGenJarPath); libDir = new File(classPathFile.getParent()); } else { File servicePropertiesFile = new File(servicePropertiesPath); classPathFile = servicePropertiesFile.getParentFile(); libDir = new File(classPathFile.getParent(), "lib"); } classPathFiles = new File[2]; classPathFiles[0] = classPathFile; FindFile findFile = new WildcardFindFile("*-portlet-service*.jar"); findFile.searchPath(libDir); classPathFiles[1] = findFile.nextFile(); if (classPathFiles[1] == null) { File classesDir = new File(libDir.getParent(), "classes"); classPathFiles[1] = classesDir; } } else { Thread currentThread = Thread.currentThread(); classLoader = currentThread.getContextClassLoader(); File portalImplJarFile = new File(PortalUtil.getPortalLibDir(), "portal-impl.jar"); File portalServiceJarFile = new File(PortalUtil.getGlobalLibDir(), "portal-service.jar"); if (portalImplJarFile.exists() && portalServiceJarFile.exists()) { classPathFiles = new File[2]; classPathFiles[0] = portalImplJarFile; classPathFiles[1] = portalServiceJarFile; } else { classPathFiles = ClassLoaderUtil.getDefaultClasspath(classLoader); } } _classLoader = classLoader; _configure(classPathFiles); }
From source file:com.apigee.sdk.apm.http.impl.client.cache.URIExtractor.java
private String canonicalizePath(String path) { try {/*from w w w. ja v a 2 s . co m*/ String decoded = URLDecoder.decode(path, "UTF-8"); return (new URI(decoded)).getPath(); } catch (UnsupportedEncodingException e) { } catch (URISyntaxException e) { } return path; }