List of usage examples for javax.servlet.http HttpServletRequest getRequestURI
public String getRequestURI();
From source file:org.bedework.util.http.HttpUtil.java
/** Returns the String url from the request. * * @param request incoming request * @return String url from the request */// w ww . j a va 2s . c o m public static String getUrl(final HttpServletRequest request) { try { final StringBuffer sb = request.getRequestURL(); if (sb != null) { return sb.toString(); } // Presumably portlet - see what happens with uri return request.getRequestURI(); } catch (Throwable t) { return "BogusURL.this.is.probably.a.portal"; } }
From source file:com.erudika.para.rest.RestUtils.java
/** * Extracts the resource name, for example '/v1/_some_resource_name' * returns '_some_resource_name'./*from w w w .ja va 2 s. c o m*/ * @param request a request * @return the resource name */ public static String extractResourceName(HttpServletRequest request) { if (request == null || request.getRequestURI().length() <= 3) { return ""; } String uri = request.getRequestURI().substring(1); int start = uri.indexOf("/"); if (start >= 0 && start + 1 < uri.length()) { int end = uri.substring(start + 1).indexOf("/") + start + 1; if (end > start) { return uri.substring(start + 1, end); } else { return uri.substring(start + 1); } } else { return ""; } }
From source file:fr.paris.lutece.portal.web.PortalJspBean.java
/** * Set the upload filter site next url/* w w w.j av a 2 s .c om*/ * @param request the HTTP request */ public static void setUploadFilterSiteNextUrl(HttpServletRequest request) { String strNextUrl = request.getRequestURI(); UrlItem url = new UrlItem(strNextUrl); Enumeration enumParams = request.getParameterNames(); while (enumParams.hasMoreElements()) { String strParamName = (String) enumParams.nextElement(); url.addParameter(strParamName, request.getParameter(strParamName)); } HttpSession session = request.getSession(true); session.setAttribute(ATTRIBUTE_UPLOAD_FILTER_SITE_NEXT_URL, url.getUrl()); }
From source file:fr.paris.lutece.portal.web.PortalJspBean.java
/** * This method is called by Portal.jsp when it caught an * UserNotSignedException.// w w w . j a va 2 s. c om * It gives the login url and stores in the session the url asked * @param request The HTTP request * @return The login page URL * @since v1.1 */ public static String redirectLogin(HttpServletRequest request) { String strNextUrl = request.getRequestURI(); UrlItem url = new UrlItem(strNextUrl); Enumeration enumParams = request.getParameterNames(); while (enumParams.hasMoreElements()) { String strParamName = (String) enumParams.nextElement(); url.addParameter(strParamName, request.getParameter(strParamName)); } HttpSession session = request.getSession(true); session.setAttribute(ATTRIBUTE_LOGIN_NEXT_URL, url.getUrl()); String strRedirect = SecurityService.getInstance().getLoginPageUrl(); return AppPathService.getAbsoluteUrl(request, strRedirect); }
From source file:org.apache.hadoop.yarn.webapp.util.WebAppUtils.java
/** * Get a HTML escaped uri with the query parameters of the request. * @param request HttpServletRequest with the request details * @return HTML escaped uri with the query paramters *//*w ww .j av a 2s .com*/ public static String getHtmlEscapedURIWithQueryString(HttpServletRequest request) { String urlEncodedQueryString = getURLEncodedQueryString(request); if (urlEncodedQueryString != null) { return HtmlQuoting.quoteHtmlChars(request.getRequestURI() + "?" + urlEncodedQueryString); } return HtmlQuoting.quoteHtmlChars(request.getRequestURI()); }
From source file:io.apiman.test.common.mock.EchoServlet.java
/** * Create an echo response from the inbound information in the http server * request.//from w ww . ja v a 2 s . co m * @param request the request * @param withBody if request is with body * @return a new echo response */ public static EchoResponse response(HttpServletRequest request, boolean withBody) { EchoResponse response = new EchoResponse(); response.setMethod(request.getMethod()); if (request.getQueryString() != null) { String[] normalisedQueryString = request.getQueryString().split("&"); Arrays.sort(normalisedQueryString); response.setResource( request.getRequestURI() + "?" + SimpleStringUtils.join("&", normalisedQueryString)); } else { response.setResource(request.getRequestURI()); } response.setUri(request.getRequestURI()); Enumeration<String> headerNames = request.getHeaderNames(); while (headerNames.hasMoreElements()) { String name = headerNames.nextElement(); String value = request.getHeader(name); response.getHeaders().put(name, value); } if (withBody) { long totalBytes = 0; InputStream is = null; try { is = request.getInputStream(); MessageDigest sha1 = MessageDigest.getInstance("SHA1"); byte[] data = new byte[1024]; int read; while ((read = is.read(data)) != -1) { sha1.update(data, 0, read); totalBytes += read; } ; byte[] hashBytes = sha1.digest(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < hashBytes.length; i++) { sb.append(Integer.toString((hashBytes[i] & 0xff) + 0x100, 16).substring(1)); } String fileHash = sb.toString(); response.setBodyLength(totalBytes); response.setBodySha1(fileHash); } catch (Exception e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(is); } } return response; }
From source file:com.lm.lic.manager.util.GenUtil.java
/** * Extract the requestded uri/ resource in raw form befor the context path was appended to it. * //from w ww.ja va2 s . c om * @param req * @return */ public static String extractRawUri(HttpServletRequest req) { String uri = req.getRequestURI(); String contextPath = req.getContextPath(); if (contextPath == null || contextPath.length() <= 0) return uri; int length = contextPath.length(); uri = uri.substring(length); return uri; }
From source file:com.runwaysdk.controller.ServletDispatcher.java
/** * This method strips the context path from the request URI and returns it. Use this method to handle URI's in a context path agnostic manner. * // w ww . ja v a 2s .c om * @param request * @return */ private static final String getServletPath(HttpServletRequest request) { String servletPath = request.getServletPath(); if (!"".equals(servletPath)) { return servletPath; } String requestUri = request.getRequestURI(); int startIndex = request.getContextPath().equals("") ? 0 : request.getContextPath().length(); int endIndex = request.getPathInfo() == null ? requestUri.length() : requestUri.indexOf(request.getPathInfo()); return requestUri.substring(startIndex, endIndex); }
From source file:fr.paris.lutece.plugins.mylutece.web.MyLuteceApp.java
/** * Set the current url//from w w w.j ava2s . co m * @param request The Http request * */ public static void setCurrentUrl(HttpServletRequest request) { String strCurrentUrl = request.getRequestURI(); UrlItem url = new UrlItem(strCurrentUrl); Enumeration enumParams = request.getParameterNames(); while (enumParams.hasMoreElements()) { String strParamName = (String) enumParams.nextElement(); url.addParameter(strParamName, request.getParameter(strParamName)); } HttpSession session = request.getSession(true); session.setAttribute(ATTRIBUTE_CURRENT_URL, url.getUrl()); }
From source file:com.zimbra.cs.servlet.ZimbraServlet.java
public static void proxyServletRequest(HttpServletRequest req, HttpServletResponse resp, Server server, AuthToken authToken) throws IOException, ServiceException { String uri = req.getRequestURI(); String qs = req.getQueryString(); if (qs != null) { uri += '?' + qs; }/*from www . ja v a 2s. c o m*/ proxyServletRequest(req, resp, server, uri, authToken); }