List of usage examples for javax.servlet.http HttpServletRequest getMethod
public String getMethod();
From source file:com.ikon.servlet.admin.CronTabServlet.java
@Override public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String method = request.getMethod(); if (isAdmin(request)) { if (method.equals(METHOD_GET)) { doGet(request, response);/*from w ww.jav a 2s . c om*/ } else if (method.equals(METHOD_POST)) { doPost(request, response); } } }
From source file:com.erudika.scoold.utils.CsrfFilter.java
@Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { final HttpServletRequest request = (HttpServletRequest) req; final HttpServletResponse response = (HttpServletResponse) res; boolean isCSPReportRequest = request.getRequestURI().startsWith("/reports/cspv"); if ("POST".equals(request.getMethod()) && !isCSPReportRequest) { String csrfToken = request.getParameter("_csrf"); String csrfInCookie = HttpUtils.getStateParam(CSRF_COOKIE, request); Long time = NumberUtils.toLong(request.getParameter("_time"), 0); String timekey = request.getParameter("_timekey"); if (timekey != null) { Long timeInSession = (Long) request.getSession().getAttribute(timekey); request.getSession().setAttribute(timekey, System.currentTimeMillis()); if (!time.equals(timeInSession)) { logger.warn("Time token mismatch. {}, {}", request.getRemoteAddr(), request.getRequestURL()); // response.sendError(403, "Time token mismatch."); response.sendRedirect(request.getRequestURI()); return; }//from w w w. ja v a 2s . c om } if (csrfToken == null) { csrfToken = request.getHeader("X-CSRF-TOKEN"); if (csrfToken == null) { csrfToken = request.getHeader("X-XSRF-TOKEN"); } } if (csrfToken == null || StringUtils.isBlank(csrfInCookie) || !csrfToken.equals(csrfInCookie)) { logger.warn("CSRF token mismatch. {}, {}", request.getRemoteAddr(), request.getRequestURL()); response.sendError(403, "CSRF token mismatch."); return; } } chain.doFilter(request, response); }
From source file:com.ebay.pulsar.collector.servlet.IngestServlet.java
private String readRequestHead(HttpServletRequest request) { try {/*w w w .j ava 2s .co m*/ StringBuffer sb = new StringBuffer(); sb.append(request.getMethod()).append(" "); sb.append(request.getProtocol()).append(" "); sb.append(request.getPathInfo()).append("\n"); // Jetstream getHeaderNames has issues. Enumeration<String> headerNames = request.getHeaderNames(); while (headerNames.hasMoreElements()) { String name = headerNames.nextElement(); sb.append(name).append(": "); sb.append(request.getHeader(name)).append("\n"); } return sb.toString(); } catch (Throwable ex) { return null; } }
From source file:jp.co.opentone.bsol.linkbinder.view.exception.LinkBinderExceptionHandler.java
private void logRequest(HttpServletRequest req) { log.error("Requested: {} {}", req.getMethod(), req.getRequestURI()); Enumeration<?> enm = req.getHeaderNames(); log.error("Header:"); while (enm.hasMoreElements()) { String name = (String) enm.nextElement(); log.error(" {} = {}", name, req.getHeader(name)); }/* w ww.ja va 2s. c om*/ log.error(" Parameters:"); @SuppressWarnings("unchecked") Map<String, String[]> parameterMap = req.getParameterMap(); for (Map.Entry<String, String[]> e : parameterMap.entrySet()) { log.error(" {} = {}", e.getKey(), StringUtils.join(e.getValue())); } }
From source file:com.googlecode.psiprobe.controllers.jsp.RecompileJspController.java
protected ModelAndView handleContext(String contextName, Context context, HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); Summary summary = session != null ? (Summary) session.getAttribute(DisplayJspController.SUMMARY_ATTRIBUTE) : null;/* w w w. j a v a 2s . co m*/ if (request.getMethod().equalsIgnoreCase("post") && summary != null) { List names = new ArrayList(); for (Enumeration e = request.getParameterNames(); e.hasMoreElements();) { String name = (String) e.nextElement(); if ("on".equals(request.getParameter(name))) { names.add(name); } } getContainerWrapper().getTomcatContainer().recompileJsps(context, summary, names); session.setAttribute(DisplayJspController.SUMMARY_ATTRIBUTE, summary); } else if (summary != null && contextName.equals(summary.getName())) { String name = ServletRequestUtils.getStringParameter(request, "source", null); if (name != null) { List names = new ArrayList(); names.add(name); getContainerWrapper().getTomcatContainer().recompileJsps(context, summary, names); session.setAttribute(DisplayJspController.SUMMARY_ATTRIBUTE, summary); } else { logger.error("source is not passed, nothing to do"); } } return new ModelAndView(new RedirectView( request.getContextPath() + ServletRequestUtils.getStringParameter(request, "view", getViewName()) + "?" + request.getQueryString())); }
From source file:com.streamsets.lib.security.http.SSOUserAuthenticator.java
private boolean isCORSOptionsRequest(HttpServletRequest httpReq) { return "OPTIONS".equals(httpReq.getMethod()); }
From source file:business.security.CustomLoggingInterceptor.java
@Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView model) throws Exception { log.trace(String.format("%s\t%s\t%s\t%s\t%s\t%d", new Date(), request.getRemoteAddr(), request.getUserPrincipal() == null ? " - " : request.getUserPrincipal().getName(), request.getMethod(), request.getRequestURI(), response.getStatus())); super.postHandle(request, response, handler, model); }
From source file:com.brienwheeler.web.spring.security.ParamVerifyingUsernamePasswordAuthenticationFilter.java
@Override protected boolean requiresAuthentication(HttpServletRequest request, HttpServletResponse response) { // we change the notion of how to handle a GET request to the login URL and // let it flow through to the DispatcherServlet so that we can host the form // and the filter on the same URL if desired. if (postOnly && !request.getMethod().equals("POST")) return false; // call super class to determine if request URL matches target // if not, we definitely don't require authentication. if (!super.requiresAuthentication(request, response)) return false; // when the URL matches, we still only require authentication if our parameterName // is null (meaning we don't care what submit button was used, or if the non-null // parameterName is present as a parameter (meaning that the submit button we care // about was used) return (parameterName == null) || (parameterName.isEmpty()) || (request.getParameter(parameterName) != null); }
From source file:edu.umd.cs.submitServer.filters.RegisterStudentsFilter.java
@Override public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) resp; if (!request.getMethod().equals("POST")) { throw new ServletException("Only POST accepted"); }/*from w w w .j a va2 s. co m*/ Connection conn = null; BufferedReader reader = null; FileItem fileItem = null; TreeSet<StudentRegistration> registeredStudents = new TreeSet<StudentRegistration>(); List<String> errors = new ArrayList<String>(); try { conn = getConnection(); // MultipartRequestFilter is required MultipartRequest multipartRequest = (MultipartRequest) request.getAttribute(MULTIPART_REQUEST); Course course = (Course) request.getAttribute("course"); // open the uploaded file fileItem = multipartRequest.getFileItem(); reader = new BufferedReader(new InputStreamReader(fileItem.getInputStream())); int lineNumber = 1; while (true) { String line = reader.readLine(); if (line == null) break; lineNumber++; // hard-coded skip of first two lines for Maryland-specific // format if (line.startsWith("Last,First,UID,section,ClassAcct,DirectoryID")) continue; if (line.startsWith(",,,,,")) { if (line.equals(",,,,,")) continue; String ldap = line.substring(5); Student student = Student.lookupByLoginName(ldap, conn); if (student != null) { StudentRegistration sr = StudentForUpload.registerStudent(course, student, "", ldap, null, conn); registeredStudents.add(sr); } else errors.add("Did not find " + ldap); continue; } if (line.startsWith("#")) continue; // skip blank lines if (line.trim().equals("")) continue; try { StudentForUpload s = new StudentForUpload(line, delimiter); Student student = s.lookupOrInsert(conn); StudentRegistration sr = StudentForUpload.registerStudent(course, student, s.section, s.classAccount, null, conn); registeredStudents.add(sr); } catch (IllegalStateException e) { errors.add(e.getMessage()); ServletExceptionFilter.logError(conn, ServerError.Kind.EXCEPTION, request, "error while registering " + line, null, e); } catch (Exception e1) { errors.add("Problem processing line: '" + line + "' at line number: " + lineNumber); ServletExceptionFilter.logError(conn, ServerError.Kind.EXCEPTION, request, "error while registering " + line, null, e1); } } } catch (SQLException e) { throw new ServletException(e); } finally { releaseConnection(conn); if (reader != null) reader.close(); if (fileItem != null) fileItem.delete(); } request.setAttribute("registeredStudents", registeredStudents); request.setAttribute("errors", errors); chain.doFilter(request, response); }