List of usage examples for javax.servlet.http HttpServletRequest getContextPath
public String getContextPath();
From source file:edu.cornell.mannlib.vitro.webapp.filters.PageRoutingFilter.java
@Override public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain chain) throws IOException, ServletException { ServletContext ctx = filterConfig.getServletContext(); PageDao pageDao = ModelAccess.on(ctx).getWebappDaoFactory().getPageDao(); Map<String, String> urlMappings = pageDao.getPageMappings(); // get URL without hostname or servlet context HttpServletResponse response = (HttpServletResponse) arg1; HttpServletRequest req = (HttpServletRequest) arg0; String path = req.getRequestURI().substring(req.getContextPath().length()); // check for first part of path // ex. /hats/superHat -> /hats Matcher m = urlPartPattern.matcher(path); if (m.matches() && m.groupCount() >= 1) { String path1stPart = m.group(1); String pageUri = urlMappings.get(path1stPart); //try it with a leading slash? if (pageUri == null) pageUri = urlMappings.get("/" + path1stPart); if (pageUri != null && !pageUri.isEmpty()) { log.debug(path + "is a request to a page defined in the display model as " + pageUri); //add the pageUri to the request scope for use by the PageController PageController.putPageUri(req, pageUri); //This will send requests to HomePageController or PageController String controllerName = getControllerToForwardTo(req, pageUri, pageDao); log.debug(path + " is being forwarded to controller " + controllerName); RequestDispatcher rd = ctx.getNamedDispatcher(controllerName); if (rd == null) { log.error(path + " should be forwarded to controller " + controllerName + " but there " + "is no servlet named that defined for the web application in web.xml"); //TODO: what should be done in this case? }// ww w. j av a 2 s . c om rd.forward(req, response); } else if ("/".equals(path) || path.isEmpty()) { log.debug("url '" + path + "' is being forward to home controller"); RequestDispatcher rd = ctx.getNamedDispatcher(HOME_CONTROLLER_NAME); rd.forward(req, response); } else { doNonDisplayPage(path, arg0, arg1, chain); } } else { doNonDisplayPage(path, arg0, arg1, chain); } }
From source file:com.yahoo.dba.perf.myperf.springmvc.SigninController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse resp) throws Exception { logger.info("receive url path: " + request.getContextPath() + "," + request.getRequestURI() + ", " + request.getServletPath() + ", parameters: " + request.getQueryString()); boolean failed = false; String username = request.getParameter("name"); if (username != null) { username = username.trim().toLowerCase(); //find the user from the system cache AppUser appUser = this.frameworkContext.getAuth().findUserByName(username); //sign in process boolean authed = this.frameworkContext.getAuth().login(appUser, request); if (authed)//display {//from w w w. j av a 2 s.c om String view = getLoginSuccessView(); //if admin user, and setup not done yet, send to setup. if (appUser.isAdminUser() && !frameworkContext.getMyperfConfig().isConfigured()) view = this.getSetupView(); logger.info(appUser.getName() + " login, redirect to " + view); return new ModelAndView(new RedirectView(view)); } //if(appUser!=null && appUser.match(request.getParameter("pd")) else { failed = true; } } //if(username!=null) //not authenticated? Try again //TODO add retry count long server_ts = System.currentTimeMillis(); int seed = (int) (Math.random() * Integer.MAX_VALUE); ModelAndView mv = new ModelAndView(getLoginFormView()); mv.addObject("name", username); if (failed) mv.addObject("message", DEFAULT_ERROR); mv.addObject("help_key", "start"); mv.addObject("server_ts", server_ts); mv.addObject("ars", seed);//ars: authentication random seed //add store them in session request.getSession(true).setAttribute(AppUser.SERVER_TS, new Long(server_ts)); request.getSession().setAttribute(AppUser.RANDOM_SEED, new Integer(seed)); return mv; }
From source file:com.pearson.pdn.demos.chainoflearning.CalendarServlet.java
@Override protected String getRedirectUri(HttpServletRequest req) throws ServletException, IOException { GenericUrl url = new GenericUrl(req.getRequestURL().toString()); url.setRawPath(req.getContextPath() + "/oauth2callback"); return url.build(); }
From source file:br.com.devopsnapratica.controller.account.LoginController.java
@Override public String getResetPasswordUrl(HttpServletRequest request) { String url = request.getScheme() + "://" + request.getServerName() + getResetPasswordPort(request, request.getScheme() + "/"); if (request.getContextPath() != null && !"".equals(request.getContextPath())) { url = url + request.getContextPath() + "/login/resetPassword"; } else {//from w w w . j a v a 2 s . co m url = url + "/login/resetPassword"; } return url; }
From source file:org.test.skeleton.controller.ExpliotDemoController.java
@RequestMapping(value = "/csrf/messages/", method = RequestMethod.POST) public void exploit(HttpServletRequest request, HttpServletResponse response) throws Exception { Message messageToSave = messageParser.parse(request.getInputStream()); messageDao.save(messageToSave);/*from w w w .ja va 2s . com*/ response.sendRedirect(request.getContextPath()); }
From source file:com.glaf.core.util.RequestUtils.java
/** * ?//from www . j a v a 2 s. c om * * @param request */ public static void setRequestParameterToAttribute(HttpServletRequest request) { request.setAttribute("contextPath", request.getContextPath()); Enumeration<?> enumeration = request.getParameterNames(); while (enumeration.hasMoreElements()) { String paramName = (String) enumeration.nextElement(); String paramValue = getParameter(request, paramName); if (StringUtils.isNotEmpty(paramName) && StringUtils.isNotEmpty(paramValue)) { if (request.getAttribute(paramName) != null) { continue; } else if (StringUtils.equalsIgnoreCase("method", paramName)) { continue; } else if (StringUtils.equalsIgnoreCase("action", paramName)) { continue; } else if (StringUtils.equalsIgnoreCase("actionType", paramName)) { continue; } else if (StringUtils.equalsIgnoreCase("reset", paramName)) { continue; } else if (StringUtils.equalsIgnoreCase("submit", paramName)) { continue; } else if (StringUtils.equalsIgnoreCase("button", paramName)) { continue; } else if (StringUtils.equalsIgnoreCase("cancel", paramName)) { continue; } else if (StringUtils.equalsIgnoreCase("parent", paramName)) { continue; } else if (StringUtils.equalsIgnoreCase("hasPermission", paramName)) { continue; } request.setAttribute(paramName, paramValue); } } }
From source file:org.apache.cxf.fediz.service.idp.FederationEntryPoint.java
protected String extractFullContextPath(HttpServletRequest request) throws MalformedURLException { String result = null;//from www . j a v a2 s. c o m String contextPath = request.getContextPath(); String requestUrl = request.getRequestURL().toString(); String requestPath = new URL(requestUrl).getPath(); // Cut request path of request url and add context path if not ROOT if (requestPath != null && requestPath.length() > 0) { int lastIndex = requestUrl.lastIndexOf(requestPath); result = requestUrl.substring(0, lastIndex); } else { result = requestUrl; } if (contextPath != null && contextPath.length() > 0) { // contextPath contains starting slash result = result + contextPath; } if (result.charAt(result.length() - 1) != '/') { result = result + "/"; } return result; }
From source file:com.thinkgem.jeesite.modules.sys.interceptor.GlobalInterceptor.java
@Override public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { String uri = request.getRequestURI(); String uriPrefix = request.getContextPath() + Global.ADMIN_PATH; // ??POST/*w w w . j a v a 2 s . com*/ if ("POST".equals(request.getMethod()) && uri.length() > uriPrefix.length()) { User user = UserUtils.getUser(); if (user != null) { StringBuilder sb = new StringBuilder(); sb.append("url: (" + request.getMethod() + ") " + uri); int index = 0; for (Object param : request.getParameterMap().keySet()) { sb.append((index++ == 0 ? "?" : "&") + param + "="); sb.append(StringUtils.abbreviate(request.getParameter((String) param), 100)); } sb.append("; userId: " + user.getId()); sb.append("; userName: " + user.getName()); sb.append("; loginName: " + user.getLoginName()); sb.append("; ipAddr: " + request.getLocalAddr()); sb.append("; datetime: " + DateUtils.getDateTime()); sb.append("; handler: " + handler.toString()); logger.info(sb.toString()); } } }
From source file:edu.cornell.mannlib.vitro.webapp.web.widgets.LoginWidget.java
/** What's the URL for this servlet? */ private String getAuthenticateUrl(HttpServletRequest request) { String contextPath = request.getContextPath(); return contextPath + "/authenticate"; }
From source file:edu.cornell.mannlib.vitro.webapp.web.widgets.LoginWidget.java
/** What's the URL for this servlet, with the cancel parameter added? */ private String getCancelUrl(HttpServletRequest request) { String contextPath = request.getContextPath(); String urlParams = "?cancel=true"; return contextPath + "/authenticate" + urlParams; }