List of usage examples for javax.servlet.http HttpServletRequest getRequestURI
public String getRequestURI();
From source file:io.apiman.test.common.mock.EchoResponse.java
/** * Create an echo response from the inbound information in the http server * request.//from w w w . j a v a 2 s. co m * @param request * @param withBody * @return a new echo response */ public static EchoResponse from(HttpServletRequest request, boolean withBody) { EchoResponse response = new EchoResponse(); response.setMethod(request.getMethod()); 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"); //$NON-NLS-1$ byte[] data = new byte[1024]; int read = 0; 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:io.lavagna.web.security.PathConfiguration.java
private static String extractRequestedUrl(HttpServletRequest req) { String queryString = req.getQueryString(); return removeStart(req.getRequestURI(), req.getContextPath()) + (queryString != null ? ("?" + queryString) : ""); }
From source file:mojo.view.util.DebugUtils.java
public static void logRequestInfo(HttpServletRequest req) { logger.debug("session.id : " + req.getSession().getId()); logger.debug("request.method : " + req.getMethod()); logger.debug("request.pathInfo : " + req.getPathInfo()); logger.debug("request.requestURI : " + req.getRequestURI()); logger.debug("request.requestURL : " + req.getRequestURL()); logger.debug("request.queryString : " + req.getQueryString()); logger.debug(""); logRequestHeaders(req);//from ww w .j a va 2 s .c om logRequestParameters(req); logRequestAttributes(req); }
From source file:br.com.webbudget.infraestructure.configuration.ApplicationUtils.java
/** * Constroi a URL base da aplicacao/*from w w w . j a v a 2s . com*/ * * @return a URL base da aplicaco + contexto */ public static String buildBaseURL() { final FacesContext facesContext = FacesContext.getCurrentInstance(); final HttpServletRequest request = (HttpServletRequest) facesContext.getExternalContext().getRequest(); final StringBuilder builder = new StringBuilder(); String actualPath = request.getRequestURL().toString(); builder.append(actualPath.replace(request.getRequestURI(), "")); builder.append(request.getContextPath()); return builder.toString(); }
From source file:info.magnolia.module.servletsanity.support.ServletAssert.java
public static void assertRequestUri(HttpServletRequest request, String expected) throws IOException { expected = request.getContextPath() + expected; if (!request.getRequestURI().equals(expected)) { append("ERROR RequestURI is [" + request.getRequestURI() + "] expected it to be [" + expected + "]"); } else {// w w w.ja v a 2 s .com append("PASSED RequestURI is correct"); } }
From source file:info.magnolia.cms.util.ServletUtil.java
/** * Returns the request uri for the request. If the request is an include it will return the uri being included. The * returned uri is not decoded.//from www .j a va 2 s. co m */ public static String getRequestUri(HttpServletRequest request) { if (request.getAttribute(INCLUDE_REQUEST_URI_ATTRIBUTE) != null) return (String) request.getAttribute(INCLUDE_REQUEST_URI_ATTRIBUTE); return request.getRequestURI(); }
From source file:com.streak.logging.analysis.AnalysisUtility.java
public static String getRequestBaseName(HttpServletRequest req) { String path = req.getRequestURI(); return path.substring(0, path.lastIndexOf("/")); }
From source file:edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet.java
private static String assembleUrlToReturnHere(HttpServletRequest request) { String queryString = request.getQueryString(); if ((queryString == null) || queryString.isEmpty()) { return request.getRequestURI(); } else {// w w w . j a v a 2 s . co m return request.getRequestURI() + "?" + UrlBuilder.urlEncode(queryString); } }
From source file:info.magnolia.cms.util.ServletUtil.java
/** * Returns the original request uri. The If the request has been forwarded it finds the original request uri from * request attributes. The returned uri is not decoded. *///from w w w. j a v a2 s. c om public static String getOriginalRequestURI(HttpServletRequest request) { if (request.getAttribute(FORWARD_REQUEST_URI_ATTRIBUTE) != null) { return (String) request.getAttribute(FORWARD_REQUEST_URI_ATTRIBUTE); } return request.getRequestURI(); }
From source file:com.ibm.rpe.web.template.ui.utils.Utils.java
public static String getTemplateServiceUrl(HttpServletRequest request, String systemProperty, String contextRoot) {// w w w. ja va2 s. c o m String serviceURL = getSystemProperty(systemProperty, null); if (CommonUtils.isNullOrEmpty(serviceURL)) { serviceURL = request.getRequestURL().toString(); serviceURL = serviceURL.substring(0, serviceURL.indexOf(request.getRequestURI())); if (!CommonUtils.isNullOrEmpty(serviceURL)) { if (serviceURL.endsWith("/")) //$NON-NLS-1$ { serviceURL = serviceURL + contextRoot; } else { serviceURL = serviceURL + "/" + contextRoot; //$NON-NLS-1$ } System.out.println("Template Service URL not set. Using " + serviceURL); //$NON-NLS-1$ } else { System.out.println("Template Service URL is not set and it cannot be derived. Failure....."); //$NON-NLS-1$ } } else { System.out.println("Template Service URL is " + serviceURL); //$NON-NLS-1$ } return serviceURL; }