Example usage for javax.servlet.http HttpServletRequest getAttribute

List of usage examples for javax.servlet.http HttpServletRequest getAttribute

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getAttribute.

Prototype

public Object getAttribute(String name);

Source Link

Document

Returns the value of the named attribute as an Object, or null if no attribute of the given name exists.

Usage

From source file:com.acc.storefront.interceptors.BeforeControllerHandlerInterceptor.java

@Override
public boolean preHandle(final HttpServletRequest request, final HttpServletResponse response,
        final Object handler) throws Exception {
    if (request.getAttribute(INTERCEPTOR_ONCE_KEY) == null) {
        // Set the flag so that we are not executed multiple times
        request.setAttribute(INTERCEPTOR_ONCE_KEY, Boolean.TRUE);

        final HandlerMethod handlerMethod = (HandlerMethod) handler;

        // Call the pre handler once for the request
        for (final BeforeControllerHandler beforeControllerHandler : getBeforeControllerHandlers()) {
            if (!beforeControllerHandler.beforeController(request, response, handlerMethod)) {
                // Return false immediately if a handler returns false
                return false;
            }/*w ww  . j  a  v  a  2 s  .  co  m*/
        }
    }

    return true;
}

From source file:de.knightsoftnet.validators.server.security.CsrfCookieHandler.java

/**
 * set csrf/xsrf cookie.//from ww w.ja  v a  2 s.c  o m
 */
public void setCookie(final HttpServletRequest prequest, final HttpServletResponse presponse)
        throws IOException {
    final CsrfToken csrf = (CsrfToken) prequest.getAttribute(CsrfToken.class.getName());
    if (csrf != null) {
        Cookie cookie = WebUtils.getCookie(prequest, ResourcePaths.XSRF_COOKIE);
        final String token = csrf.getToken();
        if (cookie == null || token != null && !token.equals(cookie.getValue())) {
            cookie = new Cookie(ResourcePaths.XSRF_COOKIE, token);
            cookie.setPath(StringUtils.defaultString(StringUtils.trimToNull(prequest.getContextPath()), "/"));
            presponse.addCookie(cookie);
        }
    }
}

From source file:com.redhat.rhn.frontend.action.audit.scap.XccdfSearchAction.java

private Boolean getOptionScanDateSearch(HttpServletRequest request) {
    Object dateSrch = request.getAttribute(SCAN_DATE_SEARCH);
    if (dateSrch instanceof Boolean) {
        return ((Boolean) dateSrch).booleanValue();
    }/*from w w w. j a  va  2s.c  om*/
    String strDateSearch = (String) request.getAttribute(SCAN_DATE_SEARCH);
    return "on".equals(strDateSearch);
}

From source file:gov.nih.nci.cabig.caaers.web.filters.GzipFilter.java

/**
 * Checks if the request uri is an include.
 * These cannot be gzipped.//from   w  w w.j a v a 2  s.  com
 */
private boolean isIncluded(final HttpServletRequest request) {
    final String uri = (String) request.getAttribute("javax.servlet.include.request_uri");
    final boolean includeRequest = !(uri == null);

    if (includeRequest && LOG.isDebugEnabled()) {
        LOG.debug(request.getRequestURL() + " resulted in an include request. This is unusable, because"
                + "the response will be assembled into the overrall response. Not gzipping.");
    }
    return includeRequest;
}

From source file:org.juiser.spring.web.RequestContextUser.java

protected User findUser() {
    try {//from  w  w  w  .j a va 2s  . co m
        RequestAttributes reqAttr = RequestContextHolder.currentRequestAttributes();

        if (reqAttr instanceof ServletRequestAttributes) {

            ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) reqAttr;

            HttpServletRequest request = servletRequestAttributes.getRequest();

            if (request != null) {
                Object obj = request.getAttribute(User.class.getName());
                if (obj instanceof User) {
                    return (User) obj;
                }
            }
        }
    } catch (IllegalStateException e) {
        log.debug("Unable to obtain request context user via RequestContextHolder.", e);
    }

    return null;
}

From source file:com.lc.storefront.interceptors.BeforeControllerHandlerInterceptor.java

 @Override
public boolean preHandle(final HttpServletRequest request, final HttpServletResponse response, final Object handler) throws Exception
{
   if (request.getAttribute(INTERCEPTOR_ONCE_KEY) == null)
   {//from   w ww .j  a v a2 s .  co m
      // Set the flag so that we are not executed multiple times
      request.setAttribute(INTERCEPTOR_ONCE_KEY, Boolean.TRUE);

      final HandlerMethod handlerMethod = (HandlerMethod) handler;

      // Call the pre handler once for the request
      for (final BeforeControllerHandler beforeControllerHandler : getBeforeControllerHandlers())
      {
         if (!beforeControllerHandler.beforeController(request, response, handlerMethod))
         {
            // Return false immediately if a handler returns false
            return false;
         }
      }
   }

   return true;
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.gesdis.TeachingReportAction.java

private boolean hasErrors(HttpServletRequest request) {

    return request.getAttribute(Globals.ERROR_KEY) != null;
}

From source file:pl.edu.icm.comac.vis.server.TimingInterceptor.java

@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler,
        Exception ex) throws Exception {

    Long start = (Long) request.getAttribute(HANDLING_START_ATT);
    Long end = (Long) request.getAttribute(HANDLING_END_ATTR);
    long t = System.currentTimeMillis();
    if (start != null && end != null && request != null) {
        log.debug("Request: {} handling: {}ms full processing: {}ms; url: {} query: {}",
                request.getContextPath(), end - start, t - start, request.getRequestURL(),
                request.getQueryString());

    } else {//from   www. j  a  v  a  2s. c  o  m
        log.debug("One of timer elements is null");
    }
}

From source file:com.goldengekko.meetr.web.AccountController.java

@ModelAttribute(value = "token")
public DConnection populateToken(HttpServletRequest request) {

    final DConnection conn = (DConnection) request.getAttribute(SecurityInterceptor.AUTH_PARAM_OAUTH);

    // if present on the request, set the ThreadLocal in the service:
    if (null != conn) {
        salesforceService.setToken(conn.getAccessToken());
        salesforceService.setAppArg0(conn.getAppArg0());
    }//  ww  w  . j  ava2s . c  o m
    return conn;
}

From source file:com.wury.app.controller.ErrorController.java

@RequestMapping
public ModelAndView errorPage(HttpServletRequest request) {
    ModelAndView mav = new ModelAndView("all_user/error_page");
    Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");

    switch (statusCode) {
    case 400:/*from   w  ww . j  a  v  a  2s .  c o  m*/
        mav.addObject("messageProperty", "Bad Request");
        break;
    case 403:
        mav.addObject("messageProperty", "Access Denied");
        break;
    case 404:
        mav.addObject("messageProperty", "Resources Not Found");
        break;
    case 500:
        mav.addObject("messageProperty", "Internal Server Error");
        break;
    default:
        mav.addObject("messageProperty", "Unknown Error");
    }

    String requestUrl = (String) request.getAttribute("javax.servlet.error.request_uri");
    if (requestUrl == null) {
        requestUrl = "Unknown";
    }

    mav.addObject("statusCode", statusCode);
    mav.addObject("requestUrl", requestUrl);
    return mav;
}