List of usage examples for javax.servlet.http HttpServletRequest getServletPath
public String getServletPath();
From source file:com.iterzp.momo.filter.SiteStatusFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { Setting setting = SettingUtils.get(); if (setting.getIsSiteEnabled()) { filterChain.doFilter(request, response); } else {// ww w. ja v a 2s .co m String path = request.getServletPath(); if (path.equals(redirectUrl)) { filterChain.doFilter(request, response); return; } if (ignoreUrlPatterns != null) { for (String ignoreUrlPattern : ignoreUrlPatterns) { if (antPathMatcher.match(ignoreUrlPattern, path)) { filterChain.doFilter(request, response); return; } } } response.sendRedirect(request.getContextPath() + redirectUrl); } }
From source file:com.ibm.xsp.webdav.WebDavServlet.java
private void writeDefaultHeaderInfo(HttpServletRequest req, HttpServletResponse resp) { this.servletPath = req.getServletPath(); // LOGGER.info("req.getPathInfo():" + req.getPathInfo()); // LOGGER.info("req.getRequestURI():" + req.getRequestURI()); // LOGGER.info("req.getRequestURL():" + req.getRequestURL()); // LOGGER.info("req.getServletPath():" + this.servletPath); }
From source file:org.codemucker.testserver.capturing.CapturedRequest.java
public CapturedRequest(final HttpServletRequest req) { scheme = req.getScheme();//ww w .j av a 2 s. c o m host = req.getServerName(); port = req.getServerPort(); contextPath = req.getContextPath(); servletPath = req.getServletPath(); pathInfo = req.getPathInfo(); characterEncoding = req.getCharacterEncoding(); method = req.getMethod(); final Cookie[] cookies = req.getCookies(); // cookies if (cookies != null) { for (final Cookie cookie : cookies) { this.cookies.add(new CapturedCookie(cookie)); } } // headers for (@SuppressWarnings("unchecked") final Enumeration<String> names = req.getHeaderNames(); names.hasMoreElements();) { final String name = names.nextElement(); @SuppressWarnings("unchecked") final Enumeration<String> values = req.getHeaders(name); if (values != null) { for (; values.hasMoreElements();) { this.addHeader(new CapturedHeader(name, values.nextElement())); } } } // if we use the normal 'toString' on maps, and arrays, we get pretty // poor results // Use ArrayLists instead to get a nice output @SuppressWarnings("unchecked") final Map<String, String[]> paramMap = req.getParameterMap(); if (paramMap != null) { for (final String key : paramMap.keySet()) { final String[] vals = paramMap.get(key); this.parameters.put(key, new ArrayList<String>(Arrays.asList(vals))); } } // handle multipart posts if (ServletFileUpload.isMultipartContent(req)) { // Create a factory for disk-based file items final FileItemFactory factory = new DiskFileItemFactory(); // Create a new file upload handler final ServletFileUpload upload = new ServletFileUpload(factory); try { @SuppressWarnings("unchecked") final List<FileItem> items = upload.parseRequest(req); for (final FileItem item : items) { fileItems.add(new CapturedFileItem(item)); } } catch (final FileUploadException e) { throw new RuntimeException("Error handling multipart content", e); } } }
From source file:org.springsource.sinspctr.rest.SInspctrController.java
@ResponseBody @RequestMapping(value = "/**/*.xml", method = RequestMethod.POST) public ResponseEntity<String> saveConfig(HttpServletRequest request, @RequestParam("xml") String xml) { ResponseEntity<String> response; HttpHeaders headers = new HttpHeaders(); headers.add("content-type", "application/json"); try {//from w ww. ja v a 2s .c o m //"META-INF/spring/integration/spring-integration-context.xml" String servletPath = request.getServletPath(); if (servletPath.startsWith("/sinspctr/configs")) { servletPath = servletPath.substring("/sinspctr/configs".length(), servletPath.length()); } File siConfigFile = ResourceLocator.getClasspathRelativeFile(servletPath); FileCopyUtils.copy(siConfigFile, createBackupFile(siConfigFile)); siConfigFile.delete(); FileCopyUtils.copy(xml.getBytes(), siConfigFile); response = new ResponseEntity<String>("{\"status\":\"success\"}", HttpStatus.OK); return response; } catch (Exception e) { return new ResponseEntity<String>("{\"error\":\"" + e.getMessage() + "\"}", headers, HttpStatus.INTERNAL_SERVER_ERROR); } }
From source file:org.bedework.notifier.web.MethodBase.java
/** Get the decoded and fixed resource URI. This calls getServletPath() to * obtain the path information. The description of that method is a little * obscure in it's meaning. In a request of this form:<br><br> * "GET /ucaldav/user/douglm/calendar/1302064354993-g.ics HTTP/1.1[\r][\n]"<br><br> * getServletPath() will return <br><br> * /user/douglm/calendar/1302064354993-g.ics<br><br> * that is the context has been removed. In addition this method will URL * decode the path. getRequestUrl() does neither. * * @param req Servlet request object * @return List Path elements of fixed up uri * @throws NoteException on error//w w w . ja v a2 s. c om */ public List<String> getResourceUri(final HttpServletRequest req) throws NoteException { String uri = req.getServletPath(); if ((uri == null) || (uri.length() == 0)) { /* No path specified - set it to root. */ uri = "/"; } return fixPath(uri); }
From source file:com.sfwl.framework.web.casclient.SingleSignOutFilter.java
public void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse, final FilterChain filterChain) throws IOException, ServletException { final HttpServletRequest request = (HttpServletRequest) servletRequest; final HttpServletResponse response = (HttpServletResponse) servletResponse; // URL(js+css+img) if (excepUrlPattern != null && excepUrlPattern.matcher(request.getServletPath()).matches()) { filterChain.doFilter(servletRequest, servletResponse); return;//from w w w . j a va 2 s . c o m } /** * <p>Workaround for now for the fact that Spring Security will fail since it doesn't call {@link #init(javax.servlet.FilterConfig)}.</p> * <p>Ultimately we need to allow deployers to actually inject their fully-initialized {@link org.jasig.cas.client.session.SingleSignOutHandler}.</p> */ if (!this.handlerInitialized.getAndSet(true)) { HANDLER.init(); } if (HANDLER.process(request, response)) { filterChain.doFilter(servletRequest, servletResponse); } }
From source file:controllers.ControllerServlet.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//from w ww .j a va 2 s .c om * @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(); if (userPath.equals("/addWorker")) { String name = (String) request.getParameter("nameField"); try { UFNS.getInstance().addWorkerWithName(name); this.save(); String url = "workers"; response.sendRedirect(url); } catch (WrongNumberValueException ex) { Logger.getLogger(ControllerServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (Exception ex) { ex.printStackTrace(); } } else if (userPath.equals("/deleteWorker")) { String id = (String) request.getParameter("id"); try { UFNS.getInstance().removeWorkerWithId(Long.parseLong(id)); this.save(); } catch (WrongNumberValueException ex) { Logger.getLogger(ControllerServlet.class.getName()).log(Level.SEVERE, null, ex); } String url = "workers"; response.sendRedirect(url); } else if (userPath.equals("/deleteContract")) { String id = (String) request.getParameter("id"); String contractid = (String) request.getParameter("contractId"); try { Worker w = UFNS.getInstance().getWorkerWithId(Long.parseLong(id)); w.removeContractWithId(Long.parseLong(contractid)); this.save(); } catch (WrongNumberValueException ex) { Logger.getLogger(ControllerServlet.class.getName()).log(Level.SEVERE, null, ex); } String url = "contracts?id=" + id; response.sendRedirect(url); } else if (userPath.equals("/editWorker")) { String id = (String) request.getParameter("id"); String name = (String) request.getParameter("name"); String surname = (String) request.getParameter("surname"); String lastname = (String) request.getParameter("lastname"); try { Worker w = UFNS.getInstance().getWorkerWithId(Long.parseLong(id)); w.setWorkerName(name); w.setWorkerSurName(surname); w.setWorkerLastName(lastname); this.save(); ArrayList<AbstractContract> contracts; contracts = new ArrayList(UFNS.getInstance().getAllContractsForWorkerWithId(Long.parseLong(id))); ServletContext sc = getServletContext(); RequestDispatcher rd = sc.getRequestDispatcher(userPath); } catch (WrongNumberValueException ex) { Logger.getLogger(ControllerServlet.class.getName()).log(Level.SEVERE, null, ex); } finally { String url = "contracts?id=" + id; response.sendRedirect(url); } } else if (userPath.equals("/addContract")) { String id = (String) request.getParameter("id"); String post = (String) request.getParameter("post"); String workplace = (String) request.getParameter("workplace"); boolean budget = Boolean.parseBoolean(request.getParameter("budget").toString()); try { Worker w = UFNS.getInstance().getWorkerWithId(Long.parseLong(id)); if (budget) { w.addContract(new BudgetContract(workplace, post)); } else { w.addContract(new FinanceContract(workplace, post)); } } catch (WrongNumberValueException ex) { } finally { String url = "contracts?id=" + id; response.sendRedirect(url); } } }
From source file:mitm.djigzo.web.services.SecurityModule.java
public void contributeHttpServletRequestHandler(OrderedConfiguration<HttpServletRequestFilter> configuration, @Inject @Value("${access-denied-page}") final String accessDeniedPage) { /*/*from ww w .j av a2 s.c om*/ * Create a filter that will block access to some assets. The asset service allows access to some assets we do * not want to expose. The asset service will show all files in /assets/ directory and allows you (by default) * to download some files which you do not want to expose. */ HttpServletRequestFilter filter = new HttpServletRequestFilter() { @Override public boolean service(HttpServletRequest request, HttpServletResponse response, HttpServletRequestHandler handler) throws IOException { String path = request.getServletPath(); if (path.startsWith("/assets") && (!assetsWhitelist.contains(StringUtils.lowerCase(FilenameUtils.getExtension(path))))) { logger.warn("access to asset " + path + " denied"); response.sendRedirect(request.getContextPath() + "/" + accessDeniedPage); return true; } return handler.service(request, response); } }; configuration.add("AssetProtectionFilter", filter, "before:*"); }
From source file:de.berlios.jedi.presentation.editor.NewJispPackageFilter.java
/** * Sets a new Jisp Package, the list of existent Jisp Packages and a * JispIdManager in request session.<br> * Jisp Packages from list are registered in JispIdManager.<br> * If there is already a Jisp Package being created, nothing is done. * /*from www . j a va 2s . co m*/ * @throws ServletException * If a ServletException occurs when doing the filter. * @throws IOException * If a IOException occurs when doing the filter. * * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, * javax.servlet.ServletResponse, javax.servlet.FilterChain) */ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (!(request instanceof HttpServletRequest)) { LogFactory.getLog(LoginFilter.class) .error("Unexpected error: request in NewJispPackageFilter" + "isn't a HttpServletRequest"); throw new ServletException( "Unexpected error: request in NewJispPackageFilter" + "isn't a HttpServletRequest"); } HttpServletRequest httpRequest = (HttpServletRequest) request; JispPackage jispPackage = (JispPackage) ((HttpServletRequest) request).getSession() .getAttribute(EditorKeys.JISP_PACKAGE); try { if (jispPackage == null) { httpRequest.setAttribute(Keys.NEXT_FORWARD_NAME, httpRequest.getServletPath()); httpRequest.getSession().getServletContext().getRequestDispatcher("/NewJispPackage.do") .forward(request, response); return; } chain.doFilter(request, response); } catch (IOException e) { LogFactory.getLog(LoginFilter.class).error("IOException in NewJispPackageFilter", e); throw e; } catch (ServletException e) { LogFactory.getLog(LoginFilter.class).error("ServletException in NewJispPackageFilter", e); throw e; } }
From source file:info.joseluismartin.gtc.mvc.CacheController.java
/** * @param req/*w w w .j a v a 2 s . c om*/ * @return */ private String getContextUrl(HttpServletRequest req) { StringBuffer url = new StringBuffer(); String scheme = req.getScheme(); int port = req.getServerPort(); String servletPath = req.getServletPath(); String contextPaht = req.getContextPath(); url.append(scheme); url.append("://"); url.append(req.getServerName()); if ((scheme.equals("http") && port != 80) || (scheme.equals("https") && port != 443)) { url.append(':'); url.append(req.getServerPort()); } if (contextPaht != null) url.append(contextPaht); if (servletPath != null) url.append(servletPath); return url.toString(); }