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.epam.cme.storefront.interceptors.beforecontroller.BeforeControllerInterceptor.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);

        // Call the pre handler once for the request
        for (final BeforeControllerHandler beforeControllerHandler : getBeforeControllerHandlers()) {
            if (!beforeControllerHandler.beforeController(request, response)) {
                // Return false immediately if a handler returns false
                return false;
            }/*from  w w w .  j av  a2s . c  o  m*/
        }
    }

    return true;
}

From source file:net.thewaffleshop.nimbus.web.WebJarsController.java

@ResponseBody
@RequestMapping("/webjarslocator/{webjar}/**")
public ResponseEntity locateWebjarAsset(@PathVariable String webjar, HttpServletRequest request) {
    try {/*from w ww.  j av  a 2  s .  co  m*/
        String mvcPrefix = "/webjarslocator/" + webjar + "/";
        String mvcPath = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
        String fullPath = assetLocator.getFullPath(webjar, mvcPath.substring(mvcPrefix.length()));
        return new ResponseEntity(new ClassPathResource(fullPath), HttpStatus.OK);
    } catch (Exception e) {
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }
}

From source file:org.chtijbug.drools.platform.web.annotation.JsonPathArgumentResolver.java

private String getRequestBody(NativeWebRequest webRequest) {
    HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class);
    String jsonBody = (String) servletRequest.getAttribute(JSONBODYATTRIBUTE);
    if (jsonBody == null) {
        try {/*from ww  w  .  java  2s. c o  m*/
            String body = IOUtils.toString(servletRequest.getInputStream());
            servletRequest.setAttribute(JSONBODYATTRIBUTE, body);
            return body;
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    return jsonBody;

}

From source file:org.lightadmin.core.view.preparer.ConfigurationAwareViewPreparer.java

protected Object attributeFromRequest(Request tilesContext, String attributeName) {
    ServletRequest servletTilesRequestContext = ServletUtil.getServletRequest(tilesContext);
    final HttpServletRequest httpServletRequest = servletTilesRequestContext.getRequest();

    return httpServletRequest.getAttribute(attributeName);
}

From source file:edu.duke.cabig.c3pr.utils.web.filter.GzipFilter.java

/**
 * Checks if the request uri is an include.
 * These cannot be gzipped./*from w  w  w  .  ja va2 s.  c  o m*/
 */
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 overall response. Not gzipping.");
    }
    return includeRequest;
}

From source file:com.github.lynxdb.server.api.http.handlers.EpError.java

@RequestMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity error(HttpServletRequest request, HttpServletResponse response) {

    HttpStatus status = HttpStatus.valueOf((int) request.getAttribute("javax.servlet.error.status_code"));

    ObjectMapper mapper = new ObjectMapper();
    ObjectNode error = mapper.createObjectNode();
    error.put("code", status.value());
    error.put("message", status.getReasonPhrase());
    error.put("details", getErrorAttributes(request, true).get("message").toString());
    if (getErrorAttributes(request, true).get("exception") != null) {
        error.put("trace", getErrorAttributes(request, true).get("exception").toString() + "\n"
                + getErrorAttributes(request, true).get("trace").toString());
    }/*from w w  w. j  a v a  2 s  .c o  m*/

    return ResponseEntity.status(status).body(error.toString());
}

From source file:cz.muni.fi.myweb1.reviewServlet.java

/**
 * Handles the HTTP <code>GET</code> method.
 *
 * @param request servlet request//from w w w . jav  a2s .co m
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String name = (String) request.getAttribute("name");
    String score = (String) request.getAttribute("score");

    List<Review> listReview = myFacade.getReviews(name);
    request.getSession().setAttribute("reviewList", listReview);

}

From source file:com.wms.multitenant.tenant.interceptor.TenantIdentifierInterceptorAdapter.java

@Override
public boolean preHandle(HttpServletRequest req, HttpServletResponse res, Object handler) throws Exception {

    Map<String, Object> pathVars = (Map<String, Object>) req
            .getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
    if (pathVars.containsKey("tenantId")) {
        String tenantId = pathVars.get("tenantId").toString();
        Optional<Tenant> thisTenant = tenantRepo.findByTenantKey(tenantId);
        if (thisTenant.isPresent()) {
            req.setAttribute("Current_Tenant", thisTenant.get().getTenantKey());
            return true;
        } else {//from ww w. ja  v  a2  s .c om
            res.sendRedirect(req.getContextPath() + "/signUp");
            return false;
        }
    } else {
        return true;
    }

}

From source file:io.github.benas.todolist.web.servlet.user.account.ChangePasswordServlet.java

private boolean isInvalid(HttpServletRequest request) {
    return request.getAttribute("error") != null;
}

From source file:net.groupbuy.interceptor.ExecuteTimeInterceptor.java

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {
    Long startTime = (Long) request.getAttribute(START_TIME_ATTRIBUTE_NAME);
    if (startTime == null) {
        startTime = System.currentTimeMillis();
        request.setAttribute(START_TIME_ATTRIBUTE_NAME, startTime);
    }/*w  w w .  java 2 s  . c o  m*/
    return true;
}