List of usage examples for javax.servlet ServletRequest getParameterMap
public Map<String, String[]> getParameterMap();
From source file:org.jruby.rack.mock.WebUtils.java
/** * Obtain a named parameter from the given request parameters. * <p>See {@link #findParameterValue(java.util.Map, String)} * for a description of the lookup algorithm. * @param request current HTTP request/*from ww w . j a va 2 s . com*/ * @param name the <i>logical</i> name of the request parameter * @return the value of the parameter, or {@code null} * if the parameter does not exist in given request */ public static String findParameterValue(ServletRequest request, String name) { return findParameterValue(request.getParameterMap(), name); }
From source file:com.eu.evaluation.web.controller.EvaluateItemController.java
/** * // w ww .ja va 2 s . co m * @param evaluateType * @param objectDictionaryID ID * @param fieldDictionaryID ID * @param request * @return */ @ResponseBody @RequestMapping(value = "/evaluateItem", method = RequestMethod.POST, consumes = { "application/json" }) public EvaluateItem saveEvaluateItem(@RequestParam("evaluateType") EvaluateTypeEnum evaluateType, @RequestParam("objectDictionaryID") String objectDictionaryID, @RequestParam("fieldDictionaryID") String fieldDictionaryID, ServletRequest request) { Map<String, Object> otherMap = new HashMap<String, Object>(); for (Object key : request.getParameterMap().keySet()) { otherMap.put((String) key, request.getParameter((String) key)); } return evaluateTemplateService.createOrReplaceEvaluateItem(EvaluateTypeEnum.NOT_NULL, objectDictionaryID, fieldDictionaryID, otherMap); }
From source file:ParamSnoop.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws java.io.IOException, ServletException { /*from w w w . j av a 2s. c o m*/ Map paramMap = request.getParameterMap(); ServletContext context = config.getServletContext(); /* use the ServletContext.log method to log param names/values */ context.log("doFilter called in: " + config.getFilterName() + " on " + (new java.util.Date())); context.log("Snooping the parameters in request: " + ((HttpServletRequest) request).getRequestURI()); Iterator iter = paramMap.entrySet().iterator(); while (iter.hasNext()){ Map.Entry me = (Map.Entry) iter.next(); context.log((String)me.getKey() + ": " + ((String[]) me.getValue())[0]); } chain.doFilter(request,response); }
From source file:ParamSnoop.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws java.io.IOException, ServletException { Map paramMap = request.getParameterMap(); ServletContext context = config.getServletContext(); /* use the ServletContext.log method to log param names/values */// w ww .java2 s. c o m context.log("doFilter called in: " + config.getFilterName() + " on " + (new java.util.Date())); context.log("Snooping the parameters in request: " + ((HttpServletRequest) request).getRequestURI()); Iterator iter = paramMap.entrySet().iterator(); while (iter.hasNext()) { Map.Entry me = (Map.Entry) iter.next(); context.log((String) me.getKey() + ": " + ((String[]) me.getValue())[0]); } chain.doFilter(request, response); }
From source file:net.navasoft.madcoin.backend.services.rest.impl.TokenVerifierFilter.java
/** * Do filter./* w w w. j a v a 2s . c o m*/ * * @param request * the request * @param response * the response * @param chain * the chain * @throws IOException * Signals that an I/O exception has occurred. * @throws ServletException * the servlet exception * @since 8/09/2014, 10:28:12 AM */ @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { Map<String, String[]> parms = request.getParameterMap(); if (parms.containsKey("allowanceToken")) { String token = parms.get("allowanceToken")[0]; try { if (tokenUtils.validate(token)) { UserDetails userDetails = tokenUtils.getUserFromToken(token); UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken( userDetails.getUsername(), userDetails.getPassword()); authentication.setDetails( new WebAuthenticationDetailsSource().buildDetails((HttpServletRequest) request)); SecurityContextHolder.getContext().setAuthentication(userManager.authenticate(authentication)); } } catch (BadPaddingException e) { } catch (AuthenticationException e) { } } else if (parms.containsKey("workerToken")) { String token = parms.get("workerToken")[0]; try { if (providerTokenUtils.validate(token)) { UserDetails userDetails = providerTokenUtils.getUserFromToken(token); UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken( userDetails.getUsername(), userDetails.getPassword()); authentication.setDetails( new WebAuthenticationDetailsSource().buildDetails((HttpServletRequest) request)); SecurityContextHolder.getContext() .setAuthentication(providerManager.authenticate(authentication)); } } catch (BadPaddingException e) { e.printStackTrace(); } catch (AuthenticationException e) { e.printStackTrace(); } } chain.doFilter(request, response); }
From source file:filter.MultipartRequestFilter.java
/** * Check the type request and if it is a HttpServletRequest, then parse the request. * @throws ServletException If parsing of the given HttpServletRequest fails. * @see javax.servlet.Filter#doFilter(//from www . j ava2 s . c o m * javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain) */ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException { System.out.println("filter: request map = " + request.getParameterMap()); // Check type request. if (request instanceof HttpServletRequest) { // Cast back to HttpServletRequest. HttpServletRequest httpRequest = (HttpServletRequest) request; // Parse HttpServletRequest. HttpServletRequest parsedRequest = parseRequest(httpRequest); // Continue with filter chain. chain.doFilter(parsedRequest, response); } else { // Not a HttpServletRequest. chain.doFilter(request, response); } }
From source file:eu.rethink.lhcb.broker.servlet.WellKnownServlet.java
private void handleRequest(HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { // add header for cross domain stuff resp.addHeader("Access-Control-Allow-Origin", "*"); String host = req.getHeader("X-Forwarded-Host"); if (host == null) host = req.getHeader("Host"); // setting external host here helps BrokerWebSocketListener to return info about HTTP interface // Broker might not know how it is accessible. This is a workaround for it LHCBBroker.externalHost = host;//from www . j a v a 2 s.c o m final AsyncContext asyncContext = req.startAsync(); asyncContext.start(() -> { ServletRequest aReq = asyncContext.getRequest(); String payload = null; try { payload = IOUtils.toString(aReq.getReader()); } catch (IOException e) { e.printStackTrace(); } String finalPayload = payload; Map<String, String[]> params = aReq.getParameterMap(); LOG.debug("payload: {}\r\nparams: {}", payload, params); RequestCallback cb = new RequestCallback() { @Override public void response(Message msg) { resp.setStatus(HttpServletResponse.SC_OK); try { asyncContext.getResponse().getWriter().write(msg.toString()); asyncContext.getResponse().getWriter().flush(); asyncContext.complete(); } catch (IOException e) { e.printStackTrace(); } } @Override public void error(Exception e) { String error = "Request failed.\r\npayload: " + finalPayload + "\r\nparams: " + params; LOG.error(error + "\r\nreason: " + e.getLocalizedMessage(), e instanceof InvalidMessageException ? null : e); if (e instanceof InvalidMessageException) { resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); } else { resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } completeAsyncContext(asyncContext, error + "\r\nreason: " + e.getLocalizedMessage()); } }; try { Message msg = null; if (payload.length() > 0) { msg = Message.fromString(payload); } else { msg = Message.fromParams(params); } requestHandler.handleRequest(msg, cb); } catch (InvalidMessageException e) { cb.error(e); } }); }
From source file:com.school.exam.web.student.StudentController.java
@RequestMapping(value = "submitpaper", method = RequestMethod.POST) @Token(remove = true)//from ww w . j av a2 s.c om public String submitPaper(Model model, ServletRequest request) { ShiroDbRealm.ShiroUser user = getCurrentUser(); Map<String, String[]> param = request.getParameterMap(); Long examId = Long.valueOf(param.get("id")[0]); //????? Integer isNothas = resultService.hasExamPaperByPersonId(user.id, examId); if (isNothas > 0) { //model.addAttribute("message", "??,?????!"); return "redirect:examlist"; } else { TeMakeExamVO examvo = questionService.findExamQuestions(examId); examvo = addRemark(examvo, examId); List<TeExamResultVO> resultList = Lists.newArrayList(); Double sumScore = 0.0; List<TeExamQuestionVO> eqlist = examvo.getQuestionList(); for (TeExamQuestionVO vo : eqlist) { String[] selectval = param.get(vo.getId().toString()); // TeExamResultVO rvo = new TeExamResultVO(); rvo.setPersonId(user.id); rvo.setPersonName(user.getName()); rvo.setDepdId(examvo.getId()); rvo.setExamQuestionId(vo.getId()); rvo.setQuestionAnswer(vo.getQuestionAnswerId()); rvo.setState(1); if (null != selectval) { if (vo.getType().equals(1)) { if (vo.getQuestionAnswerId().equals(selectval[0])) { rvo.setQuestionScore(vo.getQuestionScore()); } else { rvo.setQuestionScore(0.0); } rvo.setChooseQuestionId(selectval[0]); } if (vo.getType().equals(2)) { if (vo.getQuestionAnswerId().contentEquals(StringUtils.toDelimitedString(selectval, ","))) { rvo.setQuestionScore(vo.getQuestionScore()); } else { rvo.setQuestionScore(0.0); } rvo.setChooseQuestionId(StringUtils.toDelimitedString(selectval, ",")); } } if (null != rvo.getQuestionScore()) { BigDecimal bd = BigDecimal.valueOf(rvo.getQuestionScore()); BigDecimal sum = BigDecimal.valueOf(sumScore).add(bd); sumScore = sum.doubleValue(); } resultList.add(rvo); } //? questionService.saveExamResult(resultList); TeExamPaperResultVO resultvo = new TeExamPaperResultVO(); resultvo.setExamId(examId); resultvo.setExamName(examvo.getExamName()); resultvo.setExamRemark(examvo.getExamRemark()); resultvo.setSumScore(sumScore); resultvo.setState(1); resultvo.setPersonId(user.id); resultvo.setPersonName(user.getName()); //? resultService.saveExamPaperResult(resultvo); model.addAttribute("sumScore", sumScore); model.addAttribute("examvo", examvo); model.addAttribute("resultlist", resultList); model.addAttribute("nav", NAV_MAP); model.addAttribute("project", examvo.getProject().getProjectName()); return "student/resultlist"; } }
From source file:com.swdouglass.joid.consumer.OpenIdFilter.java
@Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { // basically just check for openId parameters HttpServletRequest request = (HttpServletRequest) servletRequest; if (servletRequest.getParameter(OPENID_ATTRIBUTE) != null && !ignored(request)) { try {/*w w w. j a v a 2s . c o m*/ @SuppressWarnings("unchecked") AuthenticationResult result = joid .authenticate(convertToStringValueMap(servletRequest.getParameterMap())); String identity = result.getIdentity(); if (identity != null) { HttpServletRequest req = (HttpServletRequest) servletRequest; req.getSession(true).setAttribute(OpenIdFilter.OPENID_ATTRIBUTE, identity); HttpServletResponse resp = (HttpServletResponse) servletResponse; // could check this before setting Cookie cookie = new Cookie(OPENID_ATTRIBUTE, identity); if (cookieDomain != null) { cookie.setDomain(cookieDomain); } if (cookieMaxAge != null) { cookie.setMaxAge(cookieMaxAge); } resp.addCookie(cookie); // redirect to get rid of the long url resp.sendRedirect(result.getResponse().getReturnTo()); return; } } catch (AuthenticationException e) { e.printStackTrace(); log.info("auth failed: " + e.getMessage()); // should this be handled differently? } catch (Exception e) { e.printStackTrace(); } } filterChain.doFilter(servletRequest, servletResponse); }
From source file:gov.nih.nci.cabig.caaers.web.filters.BadInputFilter.java
/** * Stops requests that contain forbidden string patterns in parameter * names and parameter values./*from w ww . j a v a2 s . co m*/ * * @param request The servlet request to be processed * @param response The servlet response to be created * @return false if the request is forbidden, true otherwise. * @throws IOException if an input/output error occurs * @throws ServletException if a servlet error occurs */ public boolean processAllowsAndDenies(ServletRequest request, ServletResponse response) throws IOException, ServletException { @SuppressWarnings("unchecked") Map<String, String[]> paramMap = request.getParameterMap(); // Loop through the list of parameters. Iterator<String> y = paramMap.keySet().iterator(); while (y.hasNext()) { String name = y.next(); String[] values = request.getParameterValues(name); // See if the name contains a forbidden pattern. if (!checkAllowsAndDenies(name, response)) { return false; } // Check the parameter's values for the pattern. if (values != null) { for (int i = 0; i < values.length; i++) { String value = values[i]; if (!checkAllowsAndDenies(value, response)) { return false; } } } } // No parameter caused a deny. The request should continue. return true; }