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:fr.mby.portal.coreimpl.app.BasicAppSigner.java

@Override
public String retrieveSignature(final HttpServletRequest request) {
    String signature = null;/*from  w  w w.ja v  a  2  s  .  c  om*/

    final Object attrObject = request.getAttribute(IPortal.SIGNATURE_PARAM_NAME);
    if (attrObject != null && attrObject instanceof String) {
        signature = (String) attrObject;
    }

    if (!StringUtils.hasText(signature)) {
        signature = request.getParameter(IPortal.SIGNATURE_PARAM_NAME);
    }

    if (!StringUtils.hasText(signature)) {
        final Cookie[] cookies = request.getCookies();
        if (cookies != null) {
            for (final Cookie cookie : cookies) {
                if (cookie != null && IPortal.SIGNATURE_PARAM_NAME.equals(cookie.getName())) {
                    signature = cookie.getValue();
                }
            }
        }
    }

    if (!StringUtils.hasText(signature)) {
        request.setAttribute(IPortal.SIGNATURE_PARAM_NAME, signature);
    }

    return signature;
}

From source file:org.craftercms.engine.freemarker.CrafterTemplateExceptionHandler.java

protected String createErrorId() {
    HttpServletRequest request = RequestContext.getCurrent().getRequest();
    Integer currentErrorId = (Integer) request.getAttribute(FREEMARKER_CURRENT_ERROR_ID_ATTRIBUTE);

    if (currentErrorId == null) {
        currentErrorId = 1;/*from  ww w .j  av a 2 s  .  c  om*/
    } else {
        currentErrorId++;
    }

    request.setAttribute(FREEMARKER_CURRENT_ERROR_ID_ATTRIBUTE, currentErrorId);

    return currentErrorId.toString();
}

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

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request//  w  ww. j a  va  2 s .  c  o  m
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    String name = (String) request.getAttribute("username");
    String password = (String) request.getAttribute("password");
    Boolean employee = Boolean.parseBoolean(request.getAttribute("employee").toString());

    if (myFacade.register(name, password, employee)) {
        request.getSession().setAttribute("username", name);
        RequestDispatcher rd = request.getRequestDispatcher("/outline.jsp");
        rd.forward(request, response);
    }

    else {
        //TODO error
    }
}

From source file:org.impalaframework.extension.mvc.flash.FlashHelper.java

void mergeFlashState(HttpServletRequest request, ModelMap modelMap) {
    final Map<String, Object> flashState = (Map<String, Object>) request.getAttribute("flashState");
    if (flashState != null) {
        modelMap.mergeAttributes(flashState);
        request.removeAttribute("flashState");
    }//from   w ww  .  j av  a  2 s.  c  om
}

From source file:org.hdiv.web.multipart.HdivCommonsMultipartResolver.java

@Override
public MultipartHttpServletRequest resolveMultipart(HttpServletRequest request) throws MultipartException {

    HdivMultipartException multipartException = (HdivMultipartException) request
            .getAttribute(IMultipartConfig.FILEUPLOAD_EXCEPTION);
    if (multipartException != null) {
        Exception orig = multipartException.getOriginal();
        if (orig instanceof MultipartException) {
            throw (MultipartException) orig;
        } else {/*  ww  w .j  av a  2  s . c  o  m*/
            throw new MultipartException("Could not parse multipart servlet request", orig);
        }
    }

    // If MultipartHttpServletRequest instance is present in request wrappers path, don't call to MultipartResolver
    MultipartHttpServletRequest original = WebUtils.getNativeRequest(request,
            MultipartHttpServletRequest.class);
    if (original != null) {

        // Use MultipartHttpServletRequestWrapper to maintain MultipartHttpServletRequest in first place
        // and obtains parameter values from RequestWrapper, with real values with confidentiality activated
        RequestWrapper requestWrapper = WebUtils.getNativeRequest(request, RequestWrapper.class);
        return new MultipartHttpServletRequestWrapper(request, requestWrapper, original);
    }

    // If MultipartHttpServletRequest instance is not present, parse multipart request
    return super.resolveMultipart(request);
}

From source file:com.ar.dev.tierra.api.config.CsrfHeaderFilter.java

/**
 * Metodo para agregar cookie contra CRSF
 * @param request/*from  www.  ja v a  2s.  c  o m*/
 * @param response
 * @param filterChain
 * @throws ServletException
 * @throws IOException 
 */
@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);
        }
    }
    filterChain.doFilter(request, response);
}

From source file:pl.szcze.userserviceproject.CsrfHeaderFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {
    CsrfToken csrfToken = (CsrfToken) request.getAttribute(CsrfToken.class.getName());

    if (csrfToken != null) {
        Cookie cookie = WebUtils.getCookie(request, "XSRF-TOKEN");
        String token = csrfToken.getToken();

        if (cookie == null || token != null && !token.equals(cookie.getValue())) {
            cookie = new Cookie("XSRF-TOKEN", token);
            cookie.setPath("/");
            response.addCookie(cookie);//from  www.  j a v  a 2  s  .c  om
        }
    }

    filterChain.doFilter(request, response);
}

From source file:com.redhat.rhn.frontend.action.kickstart.ssm.SsmKSScheduleAction.java

private boolean isIP(HttpServletRequest request) {
    return Boolean.TRUE.equals(request.getAttribute(SCHEDULE_TYPE_IP));
}

From source file:com.swcguild.addressbookarch.controller.ErrorController.java

@RequestMapping(value = "/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";
    }/*ww w . ja v  a 2s.  co  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:psiprobe.controllers.ErrorHandlerController.java

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    String originalUri = (String) request.getAttribute("javax.servlet.error.request_uri");
    if (originalUri != null && originalUri.endsWith(ajaxExtension)) {
        return new ModelAndView(ajaxViewName);
    }/*from   ww  w  .j a v a2  s.  co m*/
    return new ModelAndView(viewName);
}