List of usage examples for javax.servlet.http HttpServletRequest getAttribute
public Object getAttribute(String name);
Object
, or null
if no attribute of the given name exists. From source file:com.glaf.core.util.RequestUtils.java
/** * ??/*from w w w .ja va 2 s. co m*/ * * @param request * @param name * @return */ public static String getStringValue(HttpServletRequest request, String name) { if (request.getAttribute(name) != null) { return (String) request.getAttribute(name); } return request.getParameter(name); }
From source file:com.sun.socialsite.web.filters.CustomizedPageFragmentCachingFilter.java
@Override protected String calculateKey(final HttpServletRequest req) { String uri = null;/*from www . j ava2 s.com*/ String query = null; if (req.getAttribute("javax.servlet.include.request_uri") != null) { uri = (String) (req.getAttribute("javax.servlet.include.request_uri")); query = (String) (req.getAttribute("javax.servlet.include.query_string")); } else { uri = req.getRequestURI(); query = req.getQueryString(); } // TODO: something better than this anonymous/loggedin workaround StringBuilder sb = new StringBuilder(); sb.append((req.getRemoteUser() != null) ? "LOGGED_IN" : "ANONYMOUS"); sb.append("|"); sb.append(req.getMethod()); sb.append("|"); sb.append(uri); if (query != null) { sb.append("?").append(query); } String key = sb.toString(); log.trace("key=" + key); return key; }
From source file:net.sourceforge.fenixedu.presentationTier.Action.resourceAllocationManager.AddClassesDA.java
public ActionForward listClasses(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { InfoShift infoShift = (InfoShift) request.getAttribute(PresentationConstants.SHIFT); List classes = ReadAvailableClassesForShift.run(infoShift.getExternalId()); if (classes != null && !classes.isEmpty()) { Collections.sort(classes, new BeanComparator("nome")); request.setAttribute(PresentationConstants.CLASSES, classes); }//from www . j a va 2s . c o m return mapping.findForward("ListClasses"); }
From source file:at.ac.tuwien.dsg.cloud.utilities.test.kongtestservice.utilities.RequestLogInterceptor.java
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { logger.info("REQUEST: " + request.getRequestURI() + " FORWARD OF: " + request.getAttribute("javax.servlet.forward.request_uri")); return super.preHandle(request, response, handler); }
From source file:com.nec.harvest.servlet.interceptor.LoggerInterceptor.java
@Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { final long startEcecutionTime = (Long) request.getAttribute(STRAT_EXECUTION_TIME_KEY); final long endExecutionTime = System.currentTimeMillis(); final long timeUse = endExecutionTime - startEcecutionTime; logger.info("Start execution time :" + startEcecutionTime + " & End execution time :" + endExecutionTime + " & Time use: " + timeUse + "[milliseconds] on the request Url: " + request.getRequestURL().toString()); super.postHandle(request, response, handler, modelAndView); }
From source file:org.surfnet.oaaas.resource.resourceserver.AbstractResource.java
private AuthenticatedPrincipal getAuthenticatedPrincipal(HttpServletRequest request) { VerifyTokenResponse verifyTokenResponse = (VerifyTokenResponse) request .getAttribute(AuthorizationServerFilter.VERIFY_TOKEN_RESPONSE); return verifyTokenResponse.getPrincipal(); }
From source file:cn.designthougths.sample.axon.sfav.webui.UIApplication.java
private Filter csrfHeaderFilter() { return new OncePerRequestFilter() { @Override/*from w w w . j a v a2 s. c om*/ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class.getName()); if (csrf != null) { Cookie cookie = WebUtils.getCookie(request, "XSRF-TOKEN"); String token = csrf.getToken(); if (cookie == null || token != null && !token.equals(cookie.getValue())) { cookie = new Cookie("XSRF-TOKEN", token); cookie.setPath("/"); response.addCookie(cookie); } } filterChain.doFilter(request, response); } }; }
From source file:com.swcguild.addressbookwebapp.controller.ErrorController.java
@RequestMapping("error") // #2 - note the use of the Spring Model object rather than a Map public String customError(HttpServletRequest request, HttpServletResponse response, Model model) { // #3 - retrieve some useful information from the request Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code"); HttpStatus httpStatus = HttpStatus.valueOf(statusCode); Throwable throwable = (Throwable) request.getAttribute("javax.servlet.error.exception"); String exceptionMessage = null; exceptionMessage = httpStatus.getReasonPhrase(); String requestUri = (String) request.getAttribute("javax.servlet.error.request_uri"); if (requestUri == null) { requestUri = "Unknown"; }//from w w w .ja v a2 s . c o m // #4 - format the message for the View String message = MessageFormat.format("{0} returned for {1}: {2}", statusCode, requestUri, exceptionMessage); // #5 - put the message in the model object model.addAttribute("errorMessage", message); return "customError"; }
From source file:com.tamnd.app.filters.CsrfHeaderFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class.getName()); if (csrf != null) { Cookie cookie = WebUtils.getCookie(request, "XSRF-TOKEN"); String token = csrf.getToken(); if (cookie == null || token != null && !token.equals(cookie.getValue())) { cookie = new Cookie("XSRF-TOKEN", token); cookie.setPath("/"); response.addCookie(cookie);/*w ww .j ava2s . c o m*/ } } filterChain.doFilter(request, response); // CsrfToken token = (CsrfToken) request.getAttribute(REQUEST_ATTRIBUTE_NAME); // if (token != null) { // response.setHeader(RESPONSE_HEADER_NAME, token.getHeaderName()); // response.setHeader(RESPONSE_PARAM_NAME, token.getParameterName()); // response.setHeader(RESPONSE_TOKEN_NAME , token.getToken()); // } // filterChain.doFilter(request, response); }
From source file:io.fns.calculator.filter.CsrfTokenGeneratorFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { CsrfToken token = (CsrfToken) request.getAttribute("_csrf"); // Spring Security will allow the Token to be included in this header // name/*w ww.ja v a2 s. c om*/ response.setHeader("X-CSRF-HEADER", token.getHeaderName()); // Spring Security will allow the token to be included in this parameter // name response.setHeader("X-CSRF-PARAM", token.getParameterName()); // this is the value of the token to be included as either a header or // an HTTP parameter response.setHeader("X-CSRF-TOKEN", token.getToken()); filterChain.doFilter(request, response); }