List of usage examples for javax.servlet.http HttpServletRequest getMethod
public String getMethod();
From source file:edu.usu.sdl.openstorefront.service.transfermodel.ErrorInfo.java
public ErrorInfo(Throwable error, HttpServletRequest request) { this.error = error; if (request != null) { requestUrl = request.getRequestURI(); requestMethod = request.getMethod(); clientIp = SecurityUtil.getClientIp(request); StringBuilder input = new StringBuilder(); if (StringUtils.isNotBlank(request.getQueryString())) { input.append("Query: ").append(request.getQueryString()).append("\n"); }//from w w w . jav a 2 s. c om inputData = input.toString(); } }
From source file:gov.nih.nci.cabig.caaers.web.OpenSessionInViewInterceptorFilter.java
/** * @see OpenSessionInViewInterceptor//from w w w . j a v a 2s . c om * @see org.springframework.web.servlet.HandlerInterceptor#afterCompletion */ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpReq = ((HttpServletRequest) request); if (log.isDebugEnabled()) { log.debug("Opening session for request " + httpReq.getMethod() + ' ' + httpReq.getRequestURI()); } OpenSessionInViewInterceptor interceptor = (OpenSessionInViewInterceptor) getApplicationContext() .getBean(getInterceptorBeanName()); WebRequest webRequest = new ServletWebRequest(httpReq); interceptor.preHandle(webRequest); try { chain.doFilter(request, response); interceptor.postHandle(webRequest, null); } catch (IOException e) { serailizeContext(request, interceptor.getSessionFactory().getCurrentSession(), e); throw e; } catch (ServletException e) { serailizeContext(request, interceptor.getSessionFactory().getCurrentSession(), e); throw e; } catch (RuntimeException e) { serailizeContext(request, interceptor.getSessionFactory().getCurrentSession(), e); throw e; } finally { interceptor.afterCompletion(webRequest, null); log.debug("Session closed"); } }
From source file:css.controller.AdmissionGradesController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { EntityManager em = new EntityManager(); if (httpServletRequest.getMethod().equals("POST")) { String stringid[] = httpServletRequest.getParameterValues("id[]"); int id[] = new int[stringid.length]; for (int i = 0; i < stringid.length; i++) { id[i] = Integer.parseInt(stringid[i]); }// w ww . ja v a 2s.c o m String names[] = httpServletRequest.getParameterValues("name[]"); String cnps[] = httpServletRequest.getParameterValues("cnp[]"); String sgradesh[] = httpServletRequest.getParameterValues("gradeh[]"); double gradesh[] = new double[sgradesh.length]; for (int i = 0; i < sgradesh.length; i++) { gradesh[i] = Double.parseDouble(sgradesh[i]); } String sgradesb[] = httpServletRequest.getParameterValues("gradeb[]"); double gradesb[] = new double[sgradesb.length]; for (int i = 0; i < sgradesb.length; i++) { gradesb[i] = Double.parseDouble(sgradesb[i]); } String sgradesa[] = httpServletRequest.getParameterValues("gradea[]"); double gradesa[] = new double[sgradesa.length]; for (int i = 0; i < sgradesa.length; i++) { gradesa[i] = Double.parseDouble(sgradesa[i]); } for (int i = 0; i < id.length; i++) { List<Student> by = em.getBy(Student.class, new StudentFilterById(id[i])); if (!by.isEmpty()) { Student student = by.get(0); student.setNume(names[i]); student.setCNP(cnps[i]); student.setBacGrade(gradesb[i]); student.setHighSchoolGrade(gradesh[i]); student.setExamGrade(gradesa[i]); em.update(student); } } } ModelAndView model = new ModelAndView("admissiongrades"); List<Student> students = em.getAll(Student.class); model.addObject("liststud", students); return model; }
From source file:ee.ria.xroad.proxy.clientproxy.ClientMessageHandler.java
private void verifyCanProcess(HttpServletRequest request) { if (!isPostRequest(request)) { throw new ClientException(X_INVALID_HTTP_METHOD, "Must use POST request method instead of %s", request.getMethod()); }/*w w w .j a v a2 s. co m*/ GlobalConf.verifyValidity(); if (!SystemProperties.isSslEnabled()) { return; } AuthKey authKey = KeyConf.getAuthKey(); if (authKey.getCertChain() == null) { throw new CodedException(X_SSL_AUTH_FAILED, "Security server has no valid authentication certificate"); } }
From source file:org.tsugi.jpa.controllers.BaseController.java
/** * Just populate some common model stuff for less repeating * * @param req the request// w w w .j ava2 s .co m * @param principal the current security principal (if there is one) * @param model the model */ void commonModelPopulate(HttpServletRequest req, Principal principal, Model model) { model.addAttribute("today", new Date()); // a little extra request handling stuff model.addAttribute("req", req); model.addAttribute("reqURI", req.getMethod() + " " + req.getRequestURI()); }
From source file:com.github.wnameless.spring.papertrail.PaperTrailService.java
@Transactional @SuppressWarnings({ "unchecked", "deprecation" }) public void audit(HttpServletRequest request, HttpServletResponse response) { if (!targetMethods.contains(HttpMethod.valueOf(request.getMethod()))) return;/*from w w w.j a v a 2s . c om*/ final PaperTrail paperTrail = newPaperTrail(); paperTrail.setUserId(userIdStrategy == null ? getUserTypedId(request) : userIdStrategy.getUserId(request)); paperTrail.setRemoteAddr(request.getRemoteAddr()); paperTrail.setHttpMethod(HttpMethod.valueOf(request.getMethod())); paperTrail.setRequestUri(request.getRequestURI()); paperTrail.setHttpStatus(response.getStatus()); // Before callbacks if (beforeCallback != null) { beforeCallback.beforePaperTrail(paperTrail, request, response); } // Around callback if (aroundCallback != null) { aroundCallback.aroundPaperTrail(paperTrailRepo, paperTrail, request, response); } else { paperTrailRepo.save(paperTrail); } // After callbacks if (afterCallback != null) { afterCallback.afterPaperTrail(paperTrail, request, response); } // Legacy after callbacks if (!callbacks.isEmpty()) { for (@SuppressWarnings("rawtypes") PaperTrailCallback callback : callbacks.values()) { callback.doWithPaperTrail(paperTrail, request, response); } } }
From source file:org.olat.modules.tu.TunnelMapper.java
@Override public MediaResource handle(String relPath, HttpServletRequest hreq) { String method = hreq.getMethod(); String uri = relPath;/*from www . j av a 2s.c o m*/ HttpUriRequest meth = null; try { URIBuilder builder = new URIBuilder(); builder.setScheme(proto).setHost(host).setPort(port.intValue()); if (uri == null) { uri = (startUri == null) ? "" : startUri; } if (uri.length() > 0 && uri.charAt(0) != '/') { uri = "/" + uri; } if (StringHelper.containsNonWhitespace(uri)) { builder.setPath(uri); } if (method.equals("GET")) { String queryString = hreq.getQueryString(); if (StringHelper.containsNonWhitespace(queryString)) { builder.setCustomQuery(queryString); } meth = new HttpGet(builder.build()); } else if (method.equals("POST")) { Map<String, String[]> params = hreq.getParameterMap(); HttpPost pmeth = new HttpPost(builder.build()); List<BasicNameValuePair> pairs = new ArrayList<BasicNameValuePair>(); for (String key : params.keySet()) { String vals[] = params.get(key); for (String val : vals) { pairs.add(new BasicNameValuePair(key, val)); } } HttpEntity entity = new UrlEncodedFormEntity(pairs, "UTF-8"); pmeth.setEntity(entity); meth = pmeth; } // Add olat specific headers to the request, can be used by external // applications to identify user and to get other params // test page e.g. http://cgi.algonet.se/htbin/cgiwrap/ug/test.py if ("enabled".equals( CoreSpringFactory.getImpl(BaseSecurityModule.class).getUserInfosTunnelCourseBuildingBlock())) { User u = ident.getUser(); meth.addHeader("X-OLAT-USERNAME", ident.getName()); meth.addHeader("X-OLAT-LASTNAME", u.getProperty(UserConstants.LASTNAME, null)); meth.addHeader("X-OLAT-FIRSTNAME", u.getProperty(UserConstants.FIRSTNAME, null)); meth.addHeader("X-OLAT-EMAIL", u.getProperty(UserConstants.EMAIL, null)); meth.addHeader("X-OLAT-USERIP", ipAddress); } HttpResponse response = httpClient.execute(meth); if (response == null) { // error return new NotFoundMediaResource(relPath); } // get or post successfully Header responseHeader = response.getFirstHeader("Content-Type"); if (responseHeader == null) { // error EntityUtils.consumeQuietly(response.getEntity()); return new NotFoundMediaResource(relPath); } return new HttpRequestMediaResource(response); } catch (ClientProtocolException e) { log.error("", e); return null; } catch (URISyntaxException e) { log.error("", e); return null; } catch (IOException e) { log.error("Error loading URI: " + (meth == null ? "???" : meth.getURI()), e); return null; } }
From source file:org.osiam.resources.helper.JsonInputValidator.java
public Group validateJsonGroup(HttpServletRequest request) throws IOException { String jsonInput = getRequestBody(request); Validator validator = validators.get(RequestMethod.valueOf(request.getMethod())); Group group;/*from w w w . j av a 2 s. c o m*/ try { group = validator.validateGroup(jsonInput); } catch (JsonParseException ex) { throw new IllegalArgumentException("The JSON structure is invalid", ex); } if (group.getSchemas() == null || group.getSchemas().isEmpty() || !group.getSchemas().contains(Group.SCHEMA)) { throw new SchemaUnknownException(); } return group; }
From source file:org.osiam.resources.helper.JsonInputValidator.java
public User validateJsonUser(HttpServletRequest request) throws IOException { String jsonInput = getRequestBody(request); Validator validator = validators.get(RequestMethod.valueOf(request.getMethod())); User user;/*w ww . j av a 2 s. com*/ try { user = validator.validateJsonUser(jsonInput); } catch (JsonParseException ex) { throw new IllegalArgumentException("The JSON structure is invalid", ex); } if (user.getSchemas() == null || user.getSchemas().isEmpty() || !user.getSchemas().contains(User.SCHEMA)) { throw new SchemaUnknownException(); } if (user.getId() != null && !user.getId().isEmpty()) { user = new User.Builder(user).setId(null).build(); } return user; }
From source file:com.amazon.dtasdk.v2.signature.Request.java
/** * Creates a Request from an HttpServletRequest. Useful for verifying the signature of a request. * // w w w . j a v a 2 s . com * NOTE: This consumes the body of the request which can cause issues when you try and read it again. * * @param httpServletRequest * the HttpServletRequest to copy * @throws IOException * on invalid url or body copying */ public Request(HttpServletRequest httpServletRequest) throws IOException { url = getFullURL(httpServletRequest); method = Method.valueOf(httpServletRequest.getMethod()); Enumeration<String> headerNames = httpServletRequest.getHeaderNames(); while (headerNames.hasMoreElements()) { String name = headerNames.nextElement(); headers.put(name, httpServletRequest.getHeader(name)); } headers.put(CONTENT_TYPE_HEADER, httpServletRequest.getContentType()); body = IOUtils.toString(httpServletRequest.getInputStream()); }