List of usage examples for javax.servlet.http HttpServletRequest getRequestURI
public String getRequestURI();
From source file:fr.paris.lutece.util.http.SecurityUtil.java
/** * Write request variables into the dump stringbuffer * @param sb The dump stringbuffer/* w w w . j ava 2 s. co m*/ * @param request The HTTP request */ private static void dumpVariables(StringBuffer sb, HttpServletRequest request) { dumpVariable(sb, "AUTH_TYPE", request.getAuthType()); dumpVariable(sb, "REQUEST_METHOD", request.getMethod()); dumpVariable(sb, "PATH_INFO", request.getPathInfo()); dumpVariable(sb, "PATH_TRANSLATED", request.getPathTranslated()); dumpVariable(sb, "QUERY_STRING", request.getQueryString()); dumpVariable(sb, "REQUEST_URI", request.getRequestURI()); dumpVariable(sb, "SCRIPT_NAME", request.getServletPath()); dumpVariable(sb, "LOCAL_ADDR", request.getLocalAddr()); dumpVariable(sb, "SERVER_PROTOCOL", request.getProtocol()); dumpVariable(sb, "REMOTE_ADDR", request.getRemoteAddr()); dumpVariable(sb, "REMOTE_HOST", request.getRemoteHost()); dumpVariable(sb, "HTTPS", request.getScheme()); dumpVariable(sb, "SERVER_NAME", request.getServerName()); dumpVariable(sb, "SERVER_PORT", String.valueOf(request.getServerPort())); }
From source file:org.frontcache.core.FCUtils.java
public static String buildRequestURI(HttpServletRequest request) { String uri = request.getRequestURI(); return uri; }
From source file:com.arm.connector.bridge.core.Utils.java
public static String getBaseURL(String endpoint, HttpServletRequest request) { String url = ""; try {/*from w ww . j av a 2s. c om*/ url = request.getRequestURL().toString().replace(request.getRequestURI().substring(1), request.getContextPath()); url += "//" + endpoint; url = url.replace("://", "_TEMP_"); url = url.replace("//", "/"); url = url.replace("_TEMP_", "://"); } catch (Exception ex) { url = request.getRequestURL().toString(); } return url; }
From source file:com.zimbra.common.util.HttpUtil.java
/** Returns the full URL (including query string) associated with the * given <code>HttpServletRequest</code>. */ public static String getFullRequestURL(HttpServletRequest req) { if (req == null) return null; String uri = encodePath(req.getRequestURI()), qs = req.getQueryString(); if (qs != null) uri += '?' + qs; return uri;// ww w. ja v a 2 s.c o m }
From source file:com.att.ajsc.csilogging.util.UtilLib.java
public static String getServiceName(HttpServletRequest request) { String serviceName = "N/A"; if (request.getAttribute(CommonNames.REST_NAME_HEADER) != null) { serviceName = request.getAttribute(CommonNames.REST_NAME_HEADER).toString(); } else {//from ww w . j a v a2 s . c o m String service = null; String pathinfo[] = request.getRequestURI().split("\\/"); for (int i = 1; i < pathinfo.length; i++) { if (service == null) { service = pathinfo[i]; } else { service = service + "." + pathinfo[i]; } } serviceName = service; } return serviceName; }
From source file:com.twinsoft.convertigo.engine.servlets.GenericServlet.java
protected static String getServletBaseUrl(HttpServletRequest request) { String base = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort(); String requestURI = request.getRequestURI(); int i = requestURI.lastIndexOf('/'); return base + requestURI.substring(0, i); }
From source file:ch.entwine.weblounge.common.url.UrlUtils.java
/** * Returns the request url as a string./* w w w . j a v a 2 s.c om*/ * * @param request * the request * @param includePath * <code>true</code> to also include the request uri * @param includeQuery * <code>true</code> to include the query string * @return the url as a string */ public static URL toURL(HttpServletRequest request, boolean includePath, boolean includeQuery) { try { StringBuffer buf = new StringBuffer(request.getScheme()); buf.append("://"); buf.append(request.getServerName()); if (request.getServerPort() != 80) buf.append(":").append(request.getServerPort()); if (includePath && request.getRequestURI() != null) buf.append(request.getRequestURI()); if (includeQuery && StringUtils.isNotBlank(request.getQueryString())) buf.append(request.getQueryString()); return new URL(buf.toString()); } catch (MalformedURLException e) { throw new IllegalStateException(e); } }
From source file:com.ms.commons.summer.web.handler.DataBinderUtil.java
/** * ?/* ww w . ja v a 2 s .c om*/ * * @param method * @param model * @param request * @param response * @param c * @return */ @SuppressWarnings("unchecked") public static Object[] getArgs(Method method, Map<String, Object> model, HttpServletRequest request, HttpServletResponse response, Class<?> c) { Class<?>[] paramTypes = method.getParameterTypes(); Object[] args = new Object[paramTypes.length]; Map<String, Object> argMap = new HashMap<String, Object>(args.length); Map<String, String> pathValues = null; PathPattern pathPattern = method.getAnnotation(PathPattern.class); if (pathPattern != null) { String path = request.getRequestURI(); int index = path.lastIndexOf('.'); if (index != -1) { path = path.substring(0, index); String[] patterns = pathPattern.patterns(); pathValues = getPathValues(patterns, path); } } MapBindingResult errors = new MapBindingResult(argMap, ""); ParameterNameDiscoverer parameterNameDiscoverer = new LocalVariableTableParameterNameDiscoverer(); for (int i = 0; i < paramTypes.length; i++) { Class<?> paramType = paramTypes[i]; MethodParameter methodParam = new MethodParameter(method, i); methodParam.initParameterNameDiscovery(parameterNameDiscoverer); GenericTypeResolver.resolveParameterType(methodParam, c.getClass()); String paramName = methodParam.getParameterName(); // map if (Map.class.isAssignableFrom(paramType)) { args[i] = model; } // HttpServletRequest else if (HttpServletRequest.class.isAssignableFrom(paramType)) { args[i] = request; } // HttpServletResponse else if (HttpServletResponse.class.isAssignableFrom(paramType)) { args[i] = response; } // HttpSession else if (HttpSession.class.isAssignableFrom(paramType)) { args[i] = request.getSession(); } // Errors else if (Errors.class.isAssignableFrom(paramType)) { args[i] = errors; } // MultipartFile else if (MultipartFile.class.isAssignableFrom(paramType)) { MultipartFile[] files = resolveMultipartFiles(request, errors, paramName); if (files != null && files.length > 0) { args[i] = files[0]; } } // MultipartFile[] else if (MultipartFile[].class.isAssignableFrom(paramType)) { args[i] = resolveMultipartFiles(request, errors, paramName); } else { // ?? if (BeanUtils.isSimpleProperty(paramType)) { SimpleTypeConverter converter = new SimpleTypeConverter(); Object value; // ? if (paramType.isArray()) { value = request.getParameterValues(paramName); } else { Object[] parameterAnnotations = methodParam.getParameterAnnotations(); value = null; if (parameterAnnotations != null && parameterAnnotations.length > 0) { if (pathValues != null && pathValues.size() > 0) { for (Object object : parameterAnnotations) { if (PathVariable.class.isInstance(object)) { PathVariable pv = (PathVariable) object; if (StringUtils.isEmpty(pv.value())) { value = pathValues.get(paramName); } else { value = pathValues.get(pv.value()); } break; } } } } else { value = request.getParameter(paramName); } } try { args[i] = converter.convertIfNecessary(value, paramType, methodParam); model.put(paramName, args[i]); } catch (TypeMismatchException e) { errors.addError(new FieldError(paramName, paramName, e.getMessage())); } } else { // ???POJO if (paramType.isArray()) { ObjectArrayDataBinder binder = new ObjectArrayDataBinder(paramType.getComponentType(), paramName); args[i] = binder.bind(request); model.put(paramName, args[i]); } else { Object bindObject = BeanUtils.instantiateClass(paramType); SummerServletRequestDataBinder binder = new SummerServletRequestDataBinder(bindObject, paramName); binder.bind(request); BindException be = new BindException(binder.getBindingResult()); List<FieldError> fieldErrors = be.getFieldErrors(); for (FieldError fieldError : fieldErrors) { errors.addError(fieldError); } args[i] = binder.getTarget(); model.put(paramName, args[i]); } } } } return args; }
From source file:ch.entwine.weblounge.common.impl.language.LanguageUtils.java
/** * Returns the preferred one out of of those languages that are requested by * the client through the <code>Accept-Language</code> header and are * supported by both the localizable and the site. * <p>//from w w w . j a v a2 s . c o m * The preferred one is defined by the following priorities: * <ul> * <li>Requested by the client</li> * <li>The localizable's original language</li> * <li>The site default language</li> * <li>The first language of what is supported by both the localizable and the * site</li> * </ul> * * @param localizable * the localizable * @param request * the http request * @param site * the site */ public static Language getPreferredLanguage(Localizable localizable, HttpServletRequest request, Site site) { // Path String[] pathElements = StringUtils.split(request.getRequestURI(), "/"); for (String element : pathElements) { for (Language l : localizable.languages()) { if (l.getIdentifier().equals(element)) { return l; } } } // Accept-Language header if (request.getHeader("Accept-Language") != null) { Enumeration<?> locales = request.getLocales(); while (locales.hasMoreElements()) { try { Language l = getLanguage((Locale) locales.nextElement()); if (localizable != null && !localizable.supportsLanguage(l)) continue; if (!site.supportsLanguage(l)) continue; return l; } catch (UnknownLanguageException e) { // never mind, some clients will send stuff like "*" as the locale } } } // The localizable's original language if (localizable != null && localizable instanceof Resource) { Resource<?> r = (Resource<?>) localizable; if (r.getOriginalContent() != null) { if (site.supportsLanguage(r.getOriginalContent().getLanguage())) return r.getOriginalContent().getLanguage(); } } // Site default language if (localizable != null && localizable.supportsLanguage(site.getDefaultLanguage())) { return site.getDefaultLanguage(); } // Any match if (localizable != null) { for (Language l : site.getLanguages()) { if (localizable.supportsLanguage(l)) { return l; } } } return null; }
From source file:com.log4ic.compressor.utils.HttpUtils.java
/** * ??//from ww w. j a v a2s .com * * @param request * @return */ public static String getRequestUri(HttpServletRequest request) { //?JSP?include?? Object queryUri = request.getAttribute("javax.servlet.include.request_uri"); if (queryUri == null) { //?JSP?forward?? queryUri = request.getAttribute("javax.servlet.forward.request_uri"); } if (queryUri != null) { return queryUri.toString(); } return request.getRequestURI(); }