List of usage examples for javax.servlet.http HttpServletRequest getServletPath
public String getServletPath();
From source file:gov.nih.nci.ncicb.tcga.dcc.common.web.StaticContentServlet.java
private URL[] getRequestResourceURLs(HttpServletRequest request) throws MalformedURLException { final String rawResourcePath = request.getServletPath() + request.getPathInfo(); //The Spring ResourceServlet allowed for combined resource url delimited by ',' as you can see //below but we're not using it since we have one call to the server for each resource by default. //Still I left that code there in case in the future we want to use the feature. final String[] localResourcePaths = StringUtils.delimitedListToStringArray(rawResourcePath, ","); final URL[] resources = new URL[localResourcePaths.length]; for (int i = 0; i < localResourcePaths.length; i++) { final URL resource = getServletContext().getResource(localResourcePaths[i]); if (resource == null) { return null; } else {//from w ww . j av a2 s . com resources[i] = resource; } } return resources; }
From source file:org.reallysqs.server.views.CreateQueueResponseView.java
@Override protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { Queue queue = (Queue) model.get("queue"); String location = "http://" + request.getLocalName() + ":" + request.getLocalPort() + request.getContextPath() + request.getServletPath() + "/queues/" + queue.getName(); response.addHeader("Location", location); }
From source file:com.huateng.ebank.framework.web.TransFilter.java
private boolean expiredSystem(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String uriStr = StringUtils.substringAfterLast(req.getServletPath(), "/"); if (StringUtils.indexOf(loginRef, uriStr) == -1) { resp.setHeader("Pragma", "No-cache"); resp.setHeader("Cache-Control", "no-cache,no-store,max-age=0"); resp.setDateHeader("Expires", 1); RequestDispatcher rd = (req).getRequestDispatcher(expiredPageName); rd.forward(req, resp);// w ww. j a v a2s .c om return true; } return false; }
From source file:com.mythesis.userbehaviouranalysis.RequestServlet.java
/** * Handles the HTTP <code>POST</code> method. * @param request servlet request/*www . j ava 2 s . c o m*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String userPath = request.getServletPath(); File input = new File("D://UserBehaviourAnalysisInput.txt"); ProfileAnalysis analysis = new ProfileAnalysis(); switch (userPath) { // if history is sent case "/history": String id = request.getParameter("userID"); String[] urls = request.getParameter("urls").split(","); Mongo mongo = new Mongo("localhost", 27017); DB db = mongo.getDB("profileAnalysis"); DBCollection userinfo = db.getCollection("userinfo"); BasicDBObject searchQuery = new BasicDBObject(); searchQuery.put("userID", id); DBCursor cursor = userinfo.find(searchQuery); if (cursor.hasNext()) { DateTime current = new DateTime(); SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm"); DBObject entry = cursor.next(); String check = (String) entry.get("timestamp"); Date temp = null; try { temp = format.parse(check); } catch (ParseException ex) { Logger.getLogger(RequestServlet.class.getName()).log(Level.SEVERE, null, ex); } DateTime previous = new DateTime(temp); System.out.println("last history analysis on: " + previous); System.out.println("current date/time: " + current); Duration duration = new Duration(previous, current); if (duration.getStandardHours() < 24) break; } analysis.perform(id, urls, input); break; // if query is sent case "/query": try { JSONObject data = new JSONObject(request.getParameter("data")); Iterator it = data.keys(); ArrayList<String> profiles = new ArrayList<>(); ArrayList<String> queries = new ArrayList<>(); while (it.hasNext()) { String key = (String) it.next(); profiles.add(key); queries.add((String) data.get(key)); } analysis.storeQueries(profiles, queries, input); } catch (JSONException ex) { Logger.getLogger(RequestServlet.class.getName()).log(Level.SEVERE, null, ex); } break; } }
From source file:com.netflix.spinnaker.gate.controllers.EntityTagsController.java
@RequestMapping(value = "/**", method = RequestMethod.GET) public Map get(HttpServletRequest request) { String pattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE); String id = new AntPathMatcher().extractPathWithinPattern(pattern, request.getServletPath()); return entityTagsService.get(id); }
From source file:org.iwethey.forums.web.admin.AdminInterceptor.java
/** * <p>Check the session for an authenticated admin user. If none, redirect to * the login page.</p>// w w w . ja va2s . co m * * @param request The servlet request object. * @param response The servlet response object. * @param handler The request handler processing this request. */ @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { Integer id = (Integer) WebUtils.getSessionAttribute(request, USER_ID_ATTRIBUTE); if (id == null) { String uri = request.getServletPath(); String query = request.getQueryString(); ModelAndView mv = new ModelAndView(new RedirectView("../user/login.iwt")); throw new ModelAndViewDefiningException(mv); } else { User u = mUserManager.getUserById(id); return u.isAdmin(); } }
From source file:org.terasoluna.gfw.functionaltest.app.exceptionhandling.ExceptionLevelResolverFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { // Workaround for application servers that don't provide getServletPath(), eg. WebSphere Liberty Profile 8.5. String path = request.getServletPath(); if (path == null || path.length() == 0) { path = request.getPathInfo();//from w ww . j a va 2 s.com } if (path.equals("/exceptionhandling/5_1")) { throw new BusinessTestException("n.cc.0000", "Error"); } else if (path.equals("/exceptionhandling/5_2")) { throw new BusinessTestException("a.cc.0000", "Error"); } else if (path.equals("/exceptionhandling/5_3")) { throw new BusinessTestException("d.cc.0000", "Error"); } }
From source file:com.baidu.cc.web.filter.AuthCheckFilter.java
@Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; HttpServletResponse response = (HttpServletResponse) servletResponse; String path = request.getServletPath(); if (request.getParameter("method") != null) { path = path + "?method=" + request.getParameter("method"); }/*from w w w .j av a 2 s. c o m*/ // ?includePath ??? if (UrlUtils.urlMatch(includePathv, path)) { if (StringUtils.contains("/project/editProject.action;/project/saveProject.action;", path)) { // ?????projectId????? String tmpProjectId = request.getParameter("reqParam.project.id"); if (StringUtils.isEmpty(tmpProjectId)) { tmpProjectId = request.getParameter("reqParam.projectId"); } Long pid = NumberUtils.toLong(tmpProjectId, 0); if (pid < 1L) { filterChain.doFilter(request, response); return; } } String authCheck = request.getParameter("authCheck"); Long projectId = SysUtils.getProjectIdFromAuthcheck(authCheck); Long userId = SysUtils.getUserIdFromAuthcheck(authCheck); Long cookieUserId = SysUtils.getUserIdFromCookie(request); // authCheck?? if (projectId == 0L || userId == 0L || !cookieUserId.equals(userId) || !accessSettingService.checkAuth(userId, SysUtils.ACCESS_SETTING_TYPE_PROJECT, projectId)) { throw new AuthException("??"); } } filterChain.doFilter(request, response); }
From source file:org.shareok.data.webserv.filters.UserSessionFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { try {/*from w w w . j a v a 2 s. c o m*/ HttpServletRequest httpRequest = (HttpServletRequest) request; String contextPath = httpRequest.getServletPath(); if (contextPath.contains("/")) { contextPath = contextPath.split("/")[1]; } //.getContextPath(); if (null != contextPath && !"".equals(contextPath) && ShareokdataManager.requiredUserAuthentication(contextPath)) { SessionRepository<Session> repo = (SessionRepository<Session>) httpRequest .getAttribute(SessionRepository.class.getName()); if (contextPath.equals("register")) { String email = (String) httpRequest.getParameter("email"); String password = (String) httpRequest.getParameter("password"); String userName = (String) httpRequest.getParameter("nickname"); if (null == email || "".equals(email)) { throw new UserRegisterInfoNotFoundException( "Valid email register information is required!"); } if (null == password || "".equals(password)) { throw new UserRegisterInfoNotFoundException("Valid password is required for registration!"); } /***************** * Some password validation logic here: */ ExpiringSession session = (ExpiringSession) repo.createSession(); session.setMaxInactiveIntervalInSeconds(600); String sessionId = session.getId(); RedisUser user = redisUserService.findUserByUserEmail(email); if (null != user && password.equals(user.getPassword())) { session.setAttribute(ShareokdataManager.getSessionRedisUserAttributeName(), user); user.setSessionKey(sessionId); user.setUserName(userName); redisUserService.updateUser(user); } else if (null == user) { ApplicationContext context = new ClassPathXmlApplicationContext("redisContext.xml"); user = (RedisUser) context.getBean("redisUser"); user.setEmail(email); user.setPassword(password); user.setSessionKey(sessionId); redisUserService.addUser(user); } else if (null != user && !password.equals(user.getPassword())) { throw new UserRegisterInfoNotFoundException( "Your login information does not match our records!`"); } session.setAttribute(ShareokdataManager.getSessionRedisUserAttributeName(), user); repo.save(session); chain.doFilter(request, response); // HttpServletResponse httpReponse = (HttpServletResponse)response; // httpReponse.sendRedirect("/webserv/home"); } else { boolean sessionValidated = false; HttpSession session = (HttpSession) httpRequest.getSession(false); if (null != session) { ExpiringSession exSession = (ExpiringSession) repo.getSession(session.getId()); if (null != exSession) { RedisUser user = (RedisUser) session .getAttribute(ShareokdataManager.getSessionRedisUserAttributeName()); if (null != user) { RedisUser userPersisted = redisUserService.findAuthenticatedUser(user.getEmail(), session.getId()); if (null != userPersisted) { sessionValidated = true; } } } } if (!sessionValidated) { if (null != session) { repo.delete(session.getId()); session.setAttribute(ShareokdataManager.getSessionRedisUserAttributeName(), null); session.invalidate(); } httpRequest.logout(); //request.getRequestDispatcher("/WEB-INF/jsp/logout.jsp").forward(request, response); HttpServletResponse httpReponse = (HttpServletResponse) response; httpReponse.sendRedirect("/webserv/login"); } else { chain.doFilter(request, response); } } } else { chain.doFilter(request, response); } } catch (IOException ex) { request.setAttribute("errorMessage", ex); request.getRequestDispatcher("/WEB-INF/jsp/userError.jsp").forward(request, response); } catch (ServletException ex) { request.setAttribute("errorMessage", ex); request.getRequestDispatcher("/WEB-INF/jsp/userError.jsp").forward(request, response); } catch (UserRegisterInfoNotFoundException ex) { request.setAttribute("errorMessage", ex); request.getRequestDispatcher("/WEB-INF/jsp/userError.jsp").forward(request, response); } }
From source file:com.gs.config.CustomFilterLogin.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { Assert.isInstanceOf(HttpServletRequest.class, request, "Can only process HttpServletRequest"); Assert.isInstanceOf(HttpServletResponse.class, response, "Can only process HttpServletResponse"); HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; // System.out.println("ESTOY EN CUSTOMFILTERLOGIN: "+httpRequest.getServletPath()); String path = httpRequest.getServletPath(); HttpSession session = httpRequest.getSession(false); if (session == null && !httpRequest.isRequestedSessionIdValid()) { String targetUrl = httpRequest.getContextPath() + "/login"; httpResponse.sendRedirect(httpResponse.encodeRedirectURL(targetUrl)); return;//from w ww .j a v a 2s . co m } chain.doFilter(request, response); }