List of usage examples for java.net URLDecoder decode
public static String decode(String s, Charset charset)
From source file:org.geowebcache.proxy.ProxyDispatcher.java
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { String methStr = request.getMethod(); if (!methStr.equalsIgnoreCase("POST")) { throw new ServletException("Illegal method " + methStr + " for this proxy."); }/*from ww w.jav a 2s.co m*/ String urlStr = request.getParameter("url"); if (urlStr == null || urlStr.length() == 0 || !urlStr.startsWith("http://")) { throw new ServletException("Expected url parameter."); } synchronized (this) { long time = System.currentTimeMillis(); if (time - lastRequest < 1000) { throw new ServletException("Only one request per second please."); } else { lastRequest = time; } } log.info("Proxying request for " + request.getRemoteAddr() + " to " + " " + urlStr); String charEnc = request.getCharacterEncoding(); if (charEnc == null) { charEnc = "UTF-8"; } String decodedUrl = URLDecoder.decode(urlStr, charEnc); URL url = new URL(decodedUrl); HttpURLConnection wmsBackendCon = (HttpURLConnection) url.openConnection(); if (wmsBackendCon.getContentEncoding() != null) { response.setCharacterEncoding(wmsBackendCon.getContentEncoding()); } response.setContentType(wmsBackendCon.getContentType()); int read = 0; byte[] data = new byte[1024]; while (read > -1) { read = wmsBackendCon.getInputStream().read(data); if (read > -1) { response.getOutputStream().write(data, 0, read); } } return null; }
From source file:fr.aliasource.webmail.server.OBMSSOProvider.java
@Override public Credentials obtainCredentials(Map<String, String> settings, HttpServletRequest req) { String ticket = req.getParameter("ticket"); if (ticket == null) { logger.warn("no ticket in url"); return null; }/*from w w w . j av a 2 s .co m*/ try { String logoutUrl = req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort() + req.getContextPath() + "/session;jsessionid=" + req.getSession().getId(); URL url = new URL(settings.get(SSO_SERVER_URL) + "?action=validate&ticket=" + ticket + "&logout=" + URLEncoder.encode(logoutUrl, "UTF-8")); InputStream in = url.openStream(); String content = IOUtils.toString(in); in.close(); if (logger.isDebugEnabled()) { logger.debug("SSO server returned:\n" + content); } Credentials creds = null; if (!content.equals("invalidOBMTicket")) { String[] ssoServerReturn = content.split("&password="); String login = ssoServerReturn[0].substring("login=".length()); String pass = ssoServerReturn[1]; creds = new Credentials(URLDecoder.decode(login, "UTF-8"), URLDecoder.decode(pass, "UTF-8")); } return creds; } catch (Exception e) { logger.error("Ticket validation error: " + e.getMessage(), e); return null; } }
From source file:org.artifactory.repo.webdav.methods.MoveMethod.java
@Override public void handle(ArtifactoryRequest request, ArtifactoryResponse response) throws IOException { log.debug("Handling {}", getName()); RepoPath repoPath = request.getRepoPath(); if (StringUtils.isEmpty(repoPath.getPath())) { response.sendError(HttpStatus.SC_BAD_REQUEST, "Cannot perform MOVE action on a repository. " + "Please specify a valid path", log); return;/*w ww . ja va2 s.c o m*/ } String destination = URLDecoder.decode(request.getHeader("Destination"), "UTF-8"); if (StringUtils.isEmpty(destination)) { response.sendError(HttpStatus.SC_BAD_REQUEST, "Header 'Destination' is required.", log); return; } String targetPathWithoutContextUrl = StringUtils.remove(destination, request.getServletContextUrl()); String targetPathParent = PathUtils.getParent(targetPathWithoutContextUrl); RepoPath targetPath = InternalRepoPathFactory.create(targetPathParent); if (!authService.canDelete(repoPath) || !authService.canDeploy(targetPath)) { response.sendError(HttpStatus.SC_FORBIDDEN, "Insufficient permissions.", log); return; } MoveMultiStatusHolder status; status = getMoveMultiStatusHolder(repoPath, targetPath, request); if (!status.hasWarnings() && !status.hasErrors()) { response.sendSuccess(); } else { response.sendError(status); } }
From source file:com.jxt.web.filter.DefaultFilterBuilder.java
private String decode(String value) { if (value == null) { return null; }//from w w w . j a v a 2 s.com try { return URLDecoder.decode(value, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException("UTF8 decodeFail. value:" + value); } }
From source file:edu.gmu.csiss.automation.pacs.utils.BaseTool.java
/** * Get classpath/*from ww w . java 2s .co m*/ * @return * class path */ public static String getClassPath() { if (isNull(_classpath)) { String dir = new BaseTool().getClass().getClassLoader().getResource("").getPath(); // dir = dir.replaceAll("\\%20", " "); //commented by Ziheng on 8/29/2015 try { dir = URLDecoder.decode(dir, "utf-8"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } _classpath = dir; } return _classpath; }
From source file:com.connectsdk.etc.helper.HttpMessage.java
public static String decode(String str) { try {/* w w w .j a v a 2 s. co m*/ return URLDecoder.decode(str, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return null; }
From source file:com.hp.alm.ali.idea.entity.EntityQuery.java
public static String decode(String val) { try {/*from ww w .ja va 2 s. c o m*/ return URLDecoder.decode(val, "UTF-8"); } catch (UnsupportedEncodingException e) { return val; } }
From source file:org.apache.wink.test.mock.MockHttpServletRequestWrapper.java
public String decode(String s) { try {/*from w ww. ja va 2 s . c om*/ String encoding = getCharacterEncoding(); if (encoding == null) { encoding = "UTF-8"; } return URLDecoder.decode(s, encoding); // This implements http://oauth.pbwiki.com/FlexibleDecoding } catch (java.io.UnsupportedEncodingException e) { throw new IllegalArgumentException(e); } }
From source file:com.oakhole.utils.EncodeUtils.java
/** * URL ?, EncodeUTF-8.//from w ww . j a va 2 s .co m * * @param input * String * @return String */ public static String urlDecode(String input) throws UnsupportedEncodingException { return URLDecoder.decode(input, DEFAULT_URL_ENCODING); }
From source file:com.alecgorge.minecraft.jsonapi.NanoHTTPD.java
/** * Decodes the percent encoding scheme. <br/> * For example: "an+example%20string" -> "an example string" */// w w w. ja v a 2 s. c o m public static String decodePercent(String str) { try { return URLDecoder.decode(str, "UTF-8"); } catch (Exception e) { e.printStackTrace(); return null; } }