Example usage for javax.servlet.http HttpServletRequest getSession

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

Introduction

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

Prototype

public HttpSession getSession();

Source Link

Document

Returns the current session associated with this request, or if the request does not have a session, creates one.

Usage

From source file:com.surfs.storage.web.controller.storage.LogoutController.java

private ModelAndView logout(HttpServletRequest request) {
    request.getSession().invalidate();
    ModelAndView modelAndView = new ModelAndView();
    modelAndView.setViewName("redirect:/");
    return modelAndView;
}

From source file:com.salesmanager.core.util.CheckoutUtil.java

/**
 * OrderProductAttribute is configured from javascript This code needs to
 * invoke catalog objects because it requires getProductOptionValueId, will
 * not change any price Add attributes to product, add attribute offset
 * price to original product price/*from ww  w  .  j av  a 2s.  c om*/
 * 
 * @param attributes
 * @param lineId
 * @param currency
 * @param request
 * @return
 * @throws Exception
 */
public static OrderProduct addAttributesFromRawObjects(List<OrderProductAttribute> attributes, long productId,
        String lineId, String currency, HttpServletRequest request) throws Exception {

    Locale loc = request.getLocale();
    String lang = loc.getLanguage();

    HttpSession session = request.getSession();

    Map cartLines = SessionUtil.getOrderProducts(request);

    if (cartLines == null) {
        throw new Exception("No OrderProduct exixt yet, cannot assign attributes");
    }

    OrderProduct scp = (OrderProduct) cartLines.get(lineId);

    if (scp == null) {
        throw new Exception("No OrderProduct exixt for lineId " + lineId);
    }

    CatalogService cservice = (CatalogService) ServiceFactory.getService(ServiceFactory.CatalogService);

    BigDecimal sumPrice = null;

    // make sure OrderProduct and productId match
    if (scp.getProductId() == productId) {

        Locale locale = (Locale) request.getSession().getAttribute("WW_TRANS_I18N_LOCALE");
        if (locale == null)
            locale = request.getLocale();

        // get attributes for this product
        Collection productAttributes = cservice.getProductAttributes(productId, locale.getLanguage());
        Map mapAttributes = new HashMap();
        if (productAttributes != null) {

            Iterator i = productAttributes.iterator();
            while (i.hasNext()) {
                ProductAttribute p = (ProductAttribute) i.next();
                mapAttributes.put(p.getOptionValueId(), p);
            }

        }

        if (scp != null) {

            StringBuffer attributesLine = null;

            if (attributes != null) {
                attributesLine = new StringBuffer();
                int count = 0;
                Iterator i = attributes.iterator();
                while (i.hasNext()) {
                    OrderProductAttribute opa = (OrderProductAttribute) i.next();
                    String attrPriceText = opa.getPrice();
                    BigDecimal attrPrice = null;
                    if (attrPriceText != null) {
                        attrPrice = CurrencyUtil.validateCurrency(attrPriceText, currency);
                    } else {
                        attrPrice = opa.getOptionValuePrice();
                    }
                    // get all information from the attribute
                    ProductAttribute pa = (ProductAttribute) mapAttributes.get(opa.getProductOptionValueId());
                    if (pa != null) {
                        if (attrPrice == null) {
                            attrPrice = pa.getOptionValuePrice();
                        }
                    }
                    if (attrPrice != null) {
                        opa.setOptionValuePrice(attrPrice);
                        opa.setPrice(CurrencyUtil.displayFormatedAmountNoCurrency(attrPrice, currency));
                        if (sumPrice == null) {
                            sumPrice = new BigDecimal(attrPrice.doubleValue()).setScale(2);
                        } else {
                            // double pr = sumPrice.doubleValue() +
                            // attrPrice.doubleValue();
                            // sumPrice = new
                            // BigDecimal(sumPrice.doubleValue() +
                            // attrPrice.doubleValue());
                            BigDecimal currentPrice = sumPrice;
                            sumPrice = currentPrice.add(attrPrice);
                        }
                    }
                    // opa.setOrderId(Long.parseLong(orderId));
                    opa.setOrderProductId(productId);
                    opa.setProductAttributeIsFree(pa.isProductAttributeIsFree());

                    opa.setProductOption("");
                    if (StringUtils.isBlank(opa.getProductOptionValue())) {
                        opa.setProductOptionValue("");
                    }

                    ProductOption po = pa.getProductOption();
                    Set poDescriptions = po.getDescriptions();
                    if (poDescriptions != null) {
                        Iterator pi = poDescriptions.iterator();
                        while (pi.hasNext()) {
                            ProductOptionDescription pod = (ProductOptionDescription) pi.next();
                            if (pod.getId().getLanguageId() == LanguageUtil.getLanguageNumberCode(lang)) {
                                opa.setProductOption(pod.getProductOptionName());
                                break;
                            }
                        }
                    }

                    if (StringUtils.isBlank(opa.getProductOptionValue())) {
                        ProductOptionValue pov = pa.getProductOptionValue();
                        if (pov != null) {
                            Set povDescriptions = pov.getDescriptions();
                            if (povDescriptions != null) {
                                Iterator povi = povDescriptions.iterator();
                                while (povi.hasNext()) {
                                    ProductOptionValueDescription povd = (ProductOptionValueDescription) povi
                                            .next();
                                    if (povd.getId().getLanguageId() == LanguageUtil
                                            .getLanguageNumberCode(lang)) {
                                        opa.setProductOptionValue(povd.getProductOptionValueName());
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    opa.setProductAttributeWeight(pa.getProductAttributeWeight());
                    if (count == 0) {
                        attributesLine.append("[ ");
                    }
                    attributesLine.append(opa.getProductOption()).append(" -> ")
                            .append(opa.getProductOptionValue());
                    if (count + 1 == attributes.size()) {
                        attributesLine.append("]");
                    } else {
                        attributesLine.append(", ");
                    }
                    count++;
                }
            }

            // add attribute price to productprice
            if (sumPrice != null) {
                // sumPrice = sumPrice.multiply(new
                // BigDecimal(scp.getProductQuantity()));

                scp.setAttributeAdditionalCost(sumPrice);// add additional
                // attribute
                // price

                // get product price
                BigDecimal productPrice = scp.getProductPrice();
                productPrice = productPrice.add(sumPrice);

                // added
                scp.setProductPrice(productPrice);

                // BigDecimal finalPrice = scp.getFinalPrice();
                BigDecimal finalPrice = productPrice.multiply(new BigDecimal(scp.getProductQuantity()));
                // finalPrice = finalPrice.add(sumPrice);
                // BigDecimal cost = scp.get

                scp.setPriceText(CurrencyUtil.displayFormatedAmountNoCurrency(productPrice, currency));
                scp.setPriceFormated(CurrencyUtil.displayFormatedAmountWithCurrency(finalPrice, currency));
            }

            if (attributesLine != null) {
                scp.setAttributesLine(attributesLine.toString());
            }

            Set attributesSet = new HashSet(attributes);

            scp.setOrderattributes(attributesSet);

        }

    }

    return scp;
}

From source file:com.formkiq.core.webflow.FlowManager.java

/**
 * Start new WebFlow.//w ww  .  j  a v  a 2s  . co  m
 * @param <T> {@link FlowEventProcessor}
 * @param request {@link HttpServletRequest}
 * @param eventProcessor Class
 * @param states {@link List}
 * @return {@link WebFlow}
 */
public static <T extends FlowEventProcessor> WebFlow start(final HttpServletRequest request,
        final Class<T> eventProcessor, final List<FlowState> states) {

    if (states.isEmpty()) {
        throw new IllegalArgumentException("states is empty");
    }

    List<FlowState> newstates = new ArrayList<>(states);
    if (!FlowStateType.START.equals(newstates.get(0).getType())) {
        newstates.add(0, new FlowState(FlowStateType.START));
    }

    if (!FlowStateType.START.equals(newstates.get(0).getType())) {
        newstates.add(0, new FlowState(FlowStateType.START));
    }

    if (!last(newstates).isEnd()) {
        newstates.add(new FlowState(FlowStateType.END));
    }

    int webflowSessionID = getNextWebFlowSessionId(request);

    WebFlow flow = new WebFlow(webflowSessionID, eventProcessor, newstates);

    request.getSession().setAttribute(getExecutionSessionKey(flow.getSessionKey()).getLeft(), flow);

    return flow;
}

From source file:com.cloudbees.demo.beesshop.cart.ShoppingCartRepository.java

public void resetCurrentShoppingCart(@Nonnull HttpServletRequest request) {
    request.getSession().removeAttribute(ShoppingCart.class.getName());
}

From source file:edu.mum.waa.webstore.controller.UserController.java

@RequestMapping("/logout")
public String logout(HttpServletRequest request) {
    request.getSession().invalidate();
    return "login";
}

From source file:ui.controller.ControllerParent.java

public void signOut(HttpServletRequest request) {
    request.getSession().invalidate();
}

From source file:com.digitalizat.control.TAccountingController.java

@RequestMapping(value = "clients")
public String viewSignin(HttpServletRequest request) {
    HttpSession sesion = request.getSession();
    if (sesion.getAttribute("logged") != null && ((Boolean) sesion.getAttribute("logged"))) {
        return "/clients/list";
    } else {/*from  w  w w. j a  va 2  s .c  o  m*/
        return "/plataforma/signin";
    }
}

From source file:dijalmasilva.controllers.User.java

@RequestMapping("/logout")
public String logout(HttpServletRequest req) {
    req.getSession().invalidate();

    return "home";
}

From source file:org.itracker.web.util.LoginUtilities.java

/**
 * get current user from request-attribute currUser, if not set from request-session
 *
 * @return current user or null if unauthenticated
 * @throws NullPointerException if the request was null
 *///from ww w.  j av  a  2 s.  c o  m
@Deprecated
public static User getCurrentUser(HttpServletRequest request) {

    final String remoteUser = request.getRemoteUser();
    if (null == remoteUser) {
        return null;
    }
    User currUser = (User) request.getAttribute("currUser");
    if (null != currUser && currUser.getLogin().equals(remoteUser)) {
        if (logger.isDebugEnabled()) {
            logger.debug("found user in request: " + remoteUser);
        }
    }
    if (null == currUser) {
        currUser = (User) request.getSession().getAttribute("currUser");
        if (null != currUser && currUser.getLogin().equals(remoteUser)) {
            if (logger.isDebugEnabled()) {
                logger.debug("found user in session: " + remoteUser);
            }
        }
    }
    if (null == currUser) {
        currUser = ServletContextUtils.getItrackerServices().getUserService().getUserByLogin(remoteUser);
        if (null != currUser && currUser.getLogin().equals(remoteUser)) {
            if (logger.isDebugEnabled()) {
                logger.debug("found user by login: " + remoteUser);
            }
        }
    }

    return currUser;
}

From source file:net.eggcanfly.spring.example.web.IndexController.java

@ResponseBody
@RequestMapping("/")
public String index(HttpServletRequest req) {

    req.getSession().setAttribute("session", "session");

    return "session";
}