List of usage examples for org.apache.commons.httpclient.util URIUtil decode
public static String decode(String escaped, String charset) throws URIException
From source file:com.esri.gpt.control.webharvest.client.waf.WafFile.java
private String encode(String url) { url = Val.chkStr(url);/*ww w . ja va 2s . c o m*/ try { return URIUtil.encodePathQuery(URIUtil.decode(url, "UTF-8"), "UTF-8"); } catch (URIException ex) { return url; } }
From source file:de.hybris.platform.addonsupport.controllers.page.AbstractAddOnPageController.java
/** * Checks request URL against properly resolved URL and returns null if url is proper or redirection string if not. * //from w ww .java 2 s . co m * @param request * - request that contains current URL * @param response * response to write "301 Moved Permanently" status to if redirected * @param resolvedUrlPath * - properly resolved URL * @param responseStatusAttributeName * - response attribute name to which write the "301 Moved Permanently" status * @return null if url is properly resolved or redirection string if not * @throws UnsupportedEncodingException */ protected String checkRequestUrl(final HttpServletRequest request, final HttpServletResponse response, final String resolvedUrlPath, final String responseStatusAttributeName) throws UnsupportedEncodingException { try { final String resolvedUrl = response.encodeURL(request.getContextPath() + resolvedUrlPath); final String requestURI = URIUtil.decode(request.getRequestURI(), "utf-8"); final String decoded = URIUtil.decode(resolvedUrl, "utf-8"); if (StringUtils.isNotEmpty(requestURI) && requestURI.endsWith(decoded)) { return null; } else { request.setAttribute(responseStatusAttributeName, HttpStatus.MOVED_PERMANENTLY); final String queryString = request.getQueryString(); if (queryString != null && !queryString.isEmpty()) { return "redirect:" + resolvedUrlPath + "?" + queryString; } return "redirect:" + resolvedUrlPath; } } catch (final URIException e) { throw new UnsupportedEncodingException(); } }
From source file:com.store.rau.storefront.controllers.pages.AbstractPageController.java
/** * Checks request URL against properly resolved URL and returns null if url is proper or redirection string if not. * * @param request/*from ww w.j av a2s . c o m*/ * - request that contains current URL * @param response * - response to write "301 Moved Permanently" status to if redirected * @param resolvedUrlPath * - properly resolved URL * @return null if url is properly resolved or redirection string if not * @throws UnsupportedEncodingException */ protected String checkRequestUrl(final HttpServletRequest request, final HttpServletResponse response, final String resolvedUrlPath) throws UnsupportedEncodingException { try { final String resolvedUrl = response.encodeURL(request.getContextPath() + resolvedUrlPath); final String requestURI = URIUtil.decode(request.getRequestURI(), "utf-8"); final String decoded = URIUtil.decode(resolvedUrl, "utf-8"); if (StringUtils.isNotEmpty(requestURI) && requestURI.endsWith(decoded)) { return null; } else { // org.springframework.web.servlet.View.RESPONSE_STATUS_ATTRIBUTE = "org.springframework.web.servlet.View.responseStatus" request.setAttribute("org.springframework.web.servlet.View.responseStatus", HttpStatus.MOVED_PERMANENTLY); final String queryString = request.getQueryString(); if (queryString != null && !queryString.isEmpty()) { return "redirect:" + resolvedUrlPath + "?" + queryString; } return "redirect:" + resolvedUrlPath; } } catch (final URIException e) { LOGGER.error("URIException:" + e.getMessage(), e); throw new UnsupportedEncodingException(e.getMessage()); } }
From source file:com.epam.cme.storefront.controllers.pages.AbstractPageController.java
/** * Checks request URL against properly resolved URL and returns null if url is proper or * redirection string if not.//w ww . j ava 2s . c o m * * @param request * - request that contains current URL * @param response * - response to write "301 Moved Permanently" status to if redirected * @param resolvedUrl * - properly resolved URL * @return null if url is properly resolved or redirection string if not * @throws UnsupportedEncodingException */ protected String checkRequestUrl(final HttpServletRequest request, final HttpServletResponse response, final String resolvedUrl) throws UnsupportedEncodingException { try { final String requestURI = URIUtil.decode(request.getRequestURI(), "utf-8"); final String decoded = URIUtil.decode(resolvedUrl, "utf-8"); if (StringUtils.isNotEmpty(requestURI) && requestURI.endsWith(decoded)) { return null; } else { request.setAttribute(View.RESPONSE_STATUS_ATTRIBUTE, HttpStatus.MOVED_PERMANENTLY); final String queryString = request.getQueryString(); if (queryString != null && !queryString.isEmpty()) { return "redirect:" + resolvedUrl + "?" + queryString; } return "redirect:" + resolvedUrl; } } catch (final URIException e) { throw new UnsupportedEncodingException(); } }
From source file:com.exxonmobile.ace.hybris.storefront.controllers.pages.AbstractPageController.java
/** * Checks request URL against properly resolved URL and returns null if url is proper or redirection string if not. * // w w w . j ava 2 s .c o m * @param request * - request that contains current URL * @param response * - response to write "301 Moved Permanently" status to if redirected * @param resolvedUrlPath * - properly resolved URL * @return null if url is properly resolved or redirection string if not * @throws UnsupportedEncodingException */ protected String checkRequestUrl(final HttpServletRequest request, final HttpServletResponse response, final String resolvedUrlPath) throws UnsupportedEncodingException { try { final String resolvedUrl = response.encodeURL(request.getContextPath() + resolvedUrlPath); final String requestURI = URIUtil.decode(request.getRequestURI(), "utf-8"); final String decoded = URIUtil.decode(resolvedUrl, "utf-8"); if (StringUtils.isNotEmpty(requestURI) && requestURI.endsWith(decoded)) { return null; } else { request.setAttribute(View.RESPONSE_STATUS_ATTRIBUTE, HttpStatus.MOVED_PERMANENTLY); final String queryString = request.getQueryString(); if (queryString != null && !queryString.isEmpty()) { return "redirect:" + resolvedUrlPath + "?" + queryString; } return "redirect:" + resolvedUrlPath; } } catch (final URIException e) { throw new UnsupportedEncodingException(); } }
From source file:com.hcc.cms.util.PageUtils.java
public static String getCardNumber(String userInfo) { String cardNumber = null;//w ww . j a v a2s . com try { String userInfoCookie = URIUtil.decode(userInfo, "UTF-8"); log.debug("Cookie : >>> " + userInfoCookie); if (userInfoCookie.contains("cardNumber")) { cardNumber = userInfoCookie.split("cardNumber=")[1].split(",")[0]; } else { log.debug("Cookie doesnot contain cardNumber: >>> "); } } catch (Exception e) { log.debug("Error while Decoding URI:>>> " + e); } return cardNumber; }
From source file:de.innovationgate.wgpublisher.webtml.form.TMLForm.java
private String extractFileFromDataURL(String dataURL) throws NoSuchAlgorithmException, IOException { int commaPos = dataURL.indexOf(","); if (commaPos == -1) { return null; }//from ww w .j a va 2s . c o m List<String> metadata = WGUtils.deserializeCollection(dataURL.substring(0, commaPos), ";"); // Parse the metadata String mimeType = "text/plain"; String charSet = "US-ASCII"; boolean isBase64 = false; int idx = 0; for (String mdField : metadata) { if (mdField.startsWith("charset=")) { charSet = mdField.substring(8); } else if (mdField.equals("base64")) { isBase64 = true; } else if (idx == 0) { mimeType = mdField; } idx++; } // Parse the data String data = dataURL.substring(commaPos + 1); byte[] dataBytes; if (isBase64) { dataBytes = Base64.decode(data); } else { dataBytes = URIUtil.decode(data, charSet) .getBytes(getFormContext().getwgacore().getCharacterEncoding()); } String suffix = WGFactory.getMimetypeDeterminationService().determineSuffixByMimeType(mimeType); if (suffix != null) { suffix = "." + suffix; } else { suffix = ""; } String fileName = "dataurl_" + WGUtils.toHexString(MD5HashingInputStream.getStreamHashBytes(new ByteArrayInputStream(dataBytes))) + suffix; ByteArrayInputStream stream = new ByteArrayInputStream(dataBytes); addfile(stream, fileName); return fileName; }
From source file:org.apache.hadoop.util.ServletUtil.java
/** * Parse and decode the path component from the given request. * @param request Http request to parse//from w w w .ja va 2 s .c om * @param servletName the name of servlet that precedes the path * @return decoded path component, null if UTF-8 is not supported */ public static String getDecodedPath(final HttpServletRequest request, String servletName) { try { return URIUtil.decode(getRawPath(request, servletName), "UTF-8"); } catch (URIException e) { throw new AssertionError("JVM does not support UTF-8"); // should never happen! } }
From source file:org.apache.webdav.lib.methods.XMLResponseMethodBase.java
private String getHref(Response response) { String href = response.getHref(); if (this.decodeResponseHrefs != null) { try {//w ww. j a v a 2s . c o m href = URIUtil.decode(href, this.decodeResponseHrefs); } catch (URIException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (this.assertHrefsArePathes) { int pos = href.indexOf("://"); if (pos != -1) { pos = href.indexOf('/', pos + 3); if (pos != -1) { href = href.substring(pos); } else { href = "/"; } } } return href; }
From source file:org.cloudfoundry.identity.uaa.util.UaaUrlUtilsTest.java
@Test public void testDecodeScopes() throws Exception { String xWWWFormEncodedscopes = "scim.userids+password.write+openid+cloud_controller.write+cloud_controller.read"; System.out.println(URLDecoder.decode(xWWWFormEncodedscopes)); System.out.println(URIUtil.decode(xWWWFormEncodedscopes, "UTF-8")); System.out.println(UriUtils.decode(xWWWFormEncodedscopes, "UTF-8")); //Assert.assertEquals(URLDecoder.decode(xWWWFormEncodedscopes), UriUtils.decode(xWWWFormEncodedscopes, "UTF-8")); }