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.indusborn.ui.settings.SettingsController.java

@RequestMapping(value = "/sett/upd/passwd/{userId}", method = RequestMethod.GET)
public ModelAndView settUpdPasswd(@PathVariable Long userId, HttpServletRequest request, Model model) {
    ModelAndView resultView = new ModelAndView("sett.upd.passwd");
    UserVO userVO = (UserVO) request.getAttribute("userVO");
    UpdPasswdForm updPasswdForm = new UpdPasswdForm();
    Message message;//www.  j a v  a2s . c o  m

    if (userId != userVO.getId()) {
        message = new Message(MessageType.ERROR, MessageValues.UPD_PASSWD_NOT_PERMITTED);
        model.addAttribute("message", message);
        return resultView;
    }

    model.addAttribute("updPasswdForm", updPasswdForm);
    return resultView;
}

From source file:istata.web.HtmlController.java

@RequestMapping(value = { "/edit \"**", "/edit \"**/**" })
@ResponseBody/*from w w  w.j  a  v  a2s .  co  m*/
public String edit(HttpServletRequest request, HttpServletResponse response, Map<String, Object> model)
        throws IOException {

    String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
    stataService.saveCmd(path);

    path = path.substring(7, path.length() - 1);

    Path dofile = Paths.get(path).toAbsolutePath();

    if (dofile.toString().equals(path) && dofile.toFile().exists()) {
        model.put("content", stataService.loadDoFile(path).getContent());
        model.put("title", path);

        return VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "edit.vm", "UTF-8", model);
    } else {
        path = stataService.expandPath(path);

        dofile = Paths.get(path).toAbsolutePath();

        if (dofile.toFile().exists()) {
            response.sendRedirect("/edit \"" + dofile.toAbsolutePath().toString() + "\"");
            return null;
        } else {
            // TODO maybe this can be done more graceful
            throw new NoSuchFileException(path);
        }
    }

}

From source file:org.moserp.infrastructure.gateway.config.OAuthConfiguration.java

/**
 * Spring security offers in-built protection for cross site request forgery
 * (CSRF) by needing a custom token in the header for any requests that are
 * NOT safe i.e. modify the resources from the server e.g. POST, PUT & PATCH
 * etc.<br>/*from ww  w  . j  a va 2  s  .  c o  m*/
 * <br>
 *
 * This protection is achieved using cookies that send a custom value (would
 * remain same for the session) in the first request and then the front-end
 * would send back the value as a custom header.<br>
 * <br>
 *
 * In this method we create a filter that is applied to the web security as
 * follows:
 * <ol>
 * <li>Spring security provides the CSRF token value as a request attribute;
 * so we extract it from there.</li>
 * <li>If we have the token, Angular wants the cookie name to be
 * "XSRF-TOKEN". So we add the cookie if it's not there and set the path for
 * the cookie to be "/" which is root. In more complicated cases, this might
 * have to be the context root of the api gateway.</li>
 * <li>We forward the request to the next filter in the chain</li>
 * </ol>
 *
 * The request-to-cookie filter that we add needs to be after the
 * <code>csrf()</code> filter so that the request attribute for CsrfToken
 * has been already added before we start to process it.
 *
 * @return
 */
private Filter createCSRFHeaderFilter() {
    return new OncePerRequestFilter() {
        @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, CSRF_COOKIE_NAME);
                String token = csrf.getToken();
                if (cookie == null || token != null && !token.equals(cookie.getValue())) {
                    cookie = new Cookie(CSRF_COOKIE_NAME, token);
                    cookie.setPath("/");
                    response.addCookie(cookie);
                }
            }
            filterChain.doFilter(request, response);
        }
    };
}

From source file:com.haulmont.cuba.web.controllers.StaticContentController.java

protected LookupResult lookup(HttpServletRequest req) {
    LookupResult r = (LookupResult) req.getAttribute("lookupResult");
    if (r == null) {
        r = lookupNoCache(req);/*w ww . ja v a  2  s  .c o  m*/
        req.setAttribute("lookupResult", r);
    }
    return r;
}

From source file:com.osafe.events.CheckOutEvents.java

public static String processCartRecurrence(HttpServletRequest request, HttpServletResponse response) {
    Delegator delegator = (Delegator) request.getAttribute("delegator");
    LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
    GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin");
    ShoppingCart sc = org.ofbiz.order.shoppingcart.ShoppingCartEvents.getCartObject(request);
    try {//from  ww w.  j a va2 s  .c  o  m
        if (UtilValidate.isEmpty(userLogin)) {
            userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "admin"));

        }
        for (Iterator<?> item = sc.iterator(); item.hasNext();) {
            ShoppingCartItem sci = (ShoppingCartItem) item.next();
            if ("SLT_AUTO_REODR".equals(sci.getShoppingListId())) {
                Map serviceCtx = UtilMisc.toMap("userLogin", userLogin);
                serviceCtx.put("partyId", sc.getOrderPartyId());
                serviceCtx.put("productStoreId", sc.getProductStoreId());
                serviceCtx.put("listName",
                        "Shopping List Created From Shopping Cart for Product Id:" + sci.getProductId());
                serviceCtx.put("shoppingListTypeId", "SLT_AUTO_REODR");
                Map newListResult = null;
                try {
                    newListResult = dispatcher.runSync("createShoppingList", serviceCtx);
                } catch (GenericServiceException e) {
                    Debug.logError(e, "Problems creating new ShoppingList", module);
                }

                // check for errors
                if (ServiceUtil.isError(newListResult)) {
                    Debug.logError("Problems creating new ShoppingList", module);
                }

                // get the new list id
                if (UtilValidate.isNotEmpty(newListResult)) {
                    sci.setShoppingList((String) newListResult.get("shoppingListId"),
                            sci.getShoppingListItemSeqId());
                }
            }
        }

    } catch (Exception e) {
        Debug.logError(e, "Problems creating new ShoppingList From Shopping Cart", module);

    }

    String result = "success";

    return result;

}

From source file:com.stimulus.struts.ActionExceptionHandler.java

/**
        //from   w ww . ja  va 2  s .  com
 * This method overrides the the ExceptionHandler's storeException
 * method in order to create more than one error message.
 *
 * @param request - The request we are handling
 * @param property  - The property name to use for this error
 * @param error - The error generated from the exception mapping
 * @param forward - The forward generated from the input path
 *                  (from the form or exception mapping)
 */

protected void storeException(HttpServletRequest request, String property,

        ActionMessage error, ActionForward forward) {

    ActionMessages errors = (ActionMessages) request.getAttribute(Globals.ERROR_KEY);
    if (errors == null) {
        errors = new ActionMessages();
    }
    errors.add(property, error);
    request.setAttribute(Globals.ERROR_KEY, errors);

}

From source file:info.magnolia.module.admininterface.PageMVCServlet.java

/**
 *
 *///from  w  ww  .j a va 2  s  .c  o m
protected MVCServletHandler getHandler(HttpServletRequest request, HttpServletResponse response) {

    String pageName = RequestFormUtil.getParameter(request, "mgnlPage"); //$NON-NLS-1$
    if (StringUtils.isEmpty(pageName)) {
        pageName = (String) request.getAttribute("javax.servlet.include.request_uri"); //$NON-NLS-1$
        if (StringUtils.isEmpty(pageName)) {
            pageName = (String) request.getAttribute("javax.servlet.forward.servlet_path"); //$NON-NLS-1$
        }
        if (StringUtils.isEmpty(pageName)) {
            pageName = request.getRequestURI();
        }
        pageName = StringUtils.replaceOnce(StringUtils.substringAfterLast(pageName, "/pages/"), ".html", //$NON-NLS-1$ //$NON-NLS-2$
                StringUtils.EMPTY);
    }

    PageMVCHandler handler = null;

    if (pageName != null) {
        // try to get a registered handler
        try {
            handler = PageHandlerManager.getInstance().getPageHandler(pageName, request, response);
        } catch (InvalidDialogPageHandlerException e) {
            log.error("no page found: [" + pageName + "]"); //$NON-NLS-1$
        }
    } else {
        log.error("no dialogpage name passed"); //$NON-NLS-1$
    }

    return handler;
}

From source file:org.okj.commons.web.json.interceptor.JSONOutputterInterceptor.java

/**
 * request/*  ww  w .  j  a v a 2  s  .  co m*/
 * @param annotation
 * @param request
 * @return
 */
private Pagination getPagination(JsonResponse annotation, HttpServletRequest request) {
    try {
        return (Pagination) request.getAttribute(annotation.page());
    } catch (ClassCastException ex) {
        LogUtils.warn(LOGGER, ", pager={0}",
                request.getAttribute(annotation.page()));
    }
    return null;
}

From source file:org.openmrs.web.controller.FieldGenController.java

@SuppressWarnings("unchecked")
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    // find the field that was identified in the openmrs:fieldGen taglib
    Object uri = request.getAttribute("javax.servlet.include.servlet_path.fieldGen");
    if (uri == null) {
        uri = request.getAttribute("javax.servlet.include.servlet_path");
    }/*from w w w. ja  v a2s  .  c om*/
    String fieldGenPath = "";
    Map<String, Object> model = new HashMap<String, Object>();

    if (uri != null) {
        fieldGenPath = uri.toString();

        // Allowable extensions are '' (no extension) and '.field'
        if (fieldGenPath.endsWith("field")) {
            fieldGenPath = fieldGenPath.replace(".field", "");
        } else if (fieldGenPath.endsWith("jsp")) {
            throw new ServletException(
                    "Illegal extension used for fieldGen: '.jsp'. Allowable extensions are '' (no extension) and '.field'");
        }

        String type = (String) request.getAttribute("org.openmrs.fieldGen.type");
        String formFieldName = (String) request.getAttribute("org.openmrs.fieldGen.formFieldName");
        //String startVal = (String)request.getAttribute("org.openmrs.fieldGen.startVal");
        Map<String, Object> params = (Map<String, Object>) request
                .getAttribute("org.openmrs.fieldGen.parameters");
        Map<String, Object> moreParams = (Map<String, Object>) request
                .getAttribute("org.openmrs.fieldGen.parameterMap");

        model.put("type", type);
        model.put("formFieldName", formFieldName);
        model.put("obj", request.getAttribute("org.openmrs.fieldGen.object"));
        model.put("request", request.getAttribute("org.openmrs.fieldGen.request"));
        model.putAll(params);
        if (moreParams != null) {
            model.putAll(moreParams);
        }

        request.removeAttribute("org.openmrs.fieldGen.type");
        request.removeAttribute("org.openmrs.fieldGen.formFieldName");
        request.removeAttribute("org.openmrs.fieldGen.object");
        request.removeAttribute("org.openmrs.fieldGen.parameters");
        request.removeAttribute("org.openmrs.fieldGen.parameterMap");
    }

    return new ModelAndView(fieldGenPath, "model", model);

}

From source file:com.adobe.acs.commons.wcm.impl.AemEnvironmentIndicatorFilter.java

private WCMMode extractFromRequest(HttpServletRequest request) {

    return (WCMMode) request.getAttribute(WCMMode.REQUEST_ATTRIBUTE_NAME);
}