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:io.hops.hopsworks.api.admin.llap.LlapMonitorProxyServlet.java

@Override
protected String rewriteQueryStringFromRequest(HttpServletRequest servletRequest, String queryString) {
    return (String) servletRequest.getAttribute(ATTR_QUERY_STRING);
}

From source file:com.acc.storefront.web.theme.UiExperienceSiteThemeResolver.java

@Override
public String resolveThemeName(final HttpServletRequest request) {
    // Lookup the cached theme name in the request
    String themeName = (String) request.getAttribute(THEME_REQUEST_ATTRIBUTE_NAME);

    if (themeName == null) {
        // Resolve Theme from CMSSiteService
        themeName = determineDefaultThemeName();

        // Cache the theme in the request attributes
        if (themeName != null) {
            request.setAttribute(THEME_REQUEST_ATTRIBUTE_NAME, themeName);
        }//ww w . ja  v a  2  s .c om
    }

    return themeName;
}

From source file:com.atlassian.jira.security.xsrf.SimpleXsrfTokenGenerator.java

private String getPendingToken(HttpServletRequest httpServletRequest) {
    return (String) httpServletRequest.getAttribute(SET_COOKIE_PENDING);
}

From source file:net.lightbody.bmp.proxy.jetty.servlet.Forward.java

public void doGet(HttpServletRequest sreq, HttpServletResponse sres) throws ServletException, IOException {
    String path = (String) sreq.getAttribute("javax.servlet.include.servlet_path");
    if (path == null)
        path = sreq.getServletPath();//from  w  w w  .ja  v a2  s. c om
    if (path.length() == 0) {
        path = (String) sreq.getAttribute("javax.servlet.include.path_info");
        if (path == null)
            path = sreq.getPathInfo();
    }

    String forward = (String) _forwardMap.get(path);
    if (log.isDebugEnabled())
        log.debug("Forward " + path + " to " + forward);
    if (forward != null) {
        ServletContext context = getServletContext().getContext(forward);
        String contextPath = sreq.getContextPath();
        if (contextPath.length() > 1)
            forward = forward.substring(contextPath.length());

        RequestDispatcher dispatch = context.getRequestDispatcher(forward);
        if (dispatch != null) {
            dispatch.forward(sreq, sres);
            return;
        }
    }

    sres.sendError(404);
}

From source file:com.netflix.genie.web.resources.handlers.GenieResourceHttpRequestHandler.java

/**
 * {@inheritDoc}//w ww . j  ava2 s .c  o m
 * <p>
 * Default to using the {@link JobFileService} implementation.
 */
@Override
protected Resource getResource(final HttpServletRequest request) throws IOException {
    final String jobId = (String) request.getAttribute(GENIE_JOB_ID_ATTRIBUTE);
    if (StringUtils.isBlank(jobId)) {
        throw new IllegalStateException(
                "Required request attribute '" + GENIE_JOB_ID_ATTRIBUTE + "' is not set");
    }
    final String relativePath = (String) request
            .getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);

    return this.jobFileService.getJobFileAsResource(jobId, relativePath);
}

From source file:com.iflytek.edu.cloud.frame.support.ServiceRequestLogging.java

/**
 * @param request/*from  w  ww  .j  a va2  s  .  co  m*/
 * @param response
 */
public void recoredLog(HttpServletRequest request, HttpServletResponse response) {
    String clientIp = ServiceUtil.getRemoteAddr(request);
    String locale = ((Locale) request.getAttribute(Constants.SYS_PARAM_KEY_LOCALE)).getDisplayName();
    String format = (String) request.getAttribute(Constants.SYS_PARAM_KEY_FORMAT);
    String appkey = (String) request.getParameter(Constants.SYS_PARAM_KEY_APPKEY);
    String httpMethod = request.getMethod();
    String serviceMethod = request.getParameter(Constants.SYS_PARAM_KEY_METHOD);
    String serviceVersion = request.getParameter(Constants.SYS_PARAM_KEY_VERSION);
    int responseStatus = response.getStatus();
    Long requestTimeMillis = (Long) request.getAttribute(ServiceMetricsFilter.SERVICE_EXEC_TIME);

    String mainErrorCode = (String) request.getAttribute(Constants.MAIN_ERROR_CODE);

    RestContext context = RestContextHolder.getContext();
    if (StringUtils.hasText(mainErrorCode)) {
        LOGGER.warn("service request information : mainErrorCode={}, clientIp={}, httpMethod={}, locale={},"
                + " appkey={}, serviceMethod={}, serviceVersion={}, format={}, responseStatus={}, requestTimeMillis={},"
                + " callCycoreCount={}, callCycoreTime={}", mainErrorCode, clientIp, httpMethod, locale, appkey,
                serviceMethod, serviceVersion, format, responseStatus, requestTimeMillis,
                context.getCallCycoreCount(), context.getCallCycoreTime());
    } else {
        LOGGER.info("service request information : clientIp={}, httpMethod={}, locale={},"
                + " appkey={}, serviceMethod={}, serviceVersion={}, format={}, responseStatus={}, requestTimeMillis={}"
                + " callCycoreCount={}, callCycoreTime={}", clientIp, httpMethod, locale, appkey, serviceMethod,
                serviceVersion, format, responseStatus, requestTimeMillis, context.getCallCycoreCount(),
                context.getCallCycoreTime());
    }
}

From source file:com.erudika.scoold.controllers.ErrorController.java

@GetMapping("/error/{code}")
public String get(@PathVariable String code, HttpServletRequest req, Model model) {
    model.addAttribute("path", "error.vm");
    model.addAttribute("title", utils.getLang(req).get("error.title"));
    model.addAttribute("status", req.getAttribute("javax.servlet.error.status_code"));
    model.addAttribute("reason", req.getAttribute("javax.servlet.error.message"));
    model.addAttribute("code", code);
    return "base";
}

From source file:de.uni_koeln.spinfo.maalr.webapp.util.DebugInterceptor.java

public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) throws Exception {
    if (enabled) {
        long startTime = (Long) request.getAttribute("startTime");
        long endTime = System.currentTimeMillis();
        long executeTime = endTime - startTime;
        if (modelAndView != null) {
            logger.debug(//from ww  w.  j  ava2 s  .c o m
                    "Execution Time for view '" + modelAndView.getViewName() + "': " + executeTime + " ms.");
        } else {
            //logger.debug("Execution Time for request: " + executeTime + " ms.");
        }

    }
}

From source file:org.emr.intercepter.RequestInterceptor.java

public boolean authorizeRequest(HttpServletRequest request) {
    if (request.getAttribute("aid") != null)
        return true;
    else// w ww.  j ava  2s  .c om
        return false;
}

From source file:org.frat.common.controller.ErrorController.java

@RequestMapping("error/404")
public String generalError(HttpServletRequest request, HttpServletResponse response, Model model) {
    // retrieve some useful information from the request
    Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
    Throwable throwable = (Throwable) request.getAttribute("javax.servlet.error.exception");
    String exceptionMessage = getExceptionMessage(throwable, statusCode);

    String requestUri = (String) request.getAttribute("javax.servlet.error.request_uri");
    if (requestUri == null) {
        requestUri = "Unknown";
    }// w ww. j a v  a  2s . c  o  m

    String message = MessageFormat.format("{0} returned for {1} with message {2}", statusCode, requestUri,
            exceptionMessage);

    model.addAttribute("errorMessage", message);
    response.setContentType("text/html;charset=UTF-8");
    return "error/404";
}