Example usage for javax.servlet.http Cookie getName

List of usage examples for javax.servlet.http Cookie getName

Introduction

In this page you can find the example usage for javax.servlet.http Cookie getName.

Prototype

public String getName() 

Source Link

Document

Returns the name of the cookie.

Usage

From source file:org.akaza.openclinica.control.MainMenuServlet.java

public String getQueryStrCookie(HttpServletRequest request, HttpServletResponse response) {
    String queryStr = "";
    Cookie[] cookies = request.getCookies();
    for (Cookie cookie : cookies) {
        if (cookie.getName().equalsIgnoreCase("queryStr")) {
            try {
                queryStr = URLDecoder.decode(cookie.getValue(), "UTF-8");
            } catch (UnsupportedEncodingException e) {
                logger.error("Error decoding redirect URL from queryStr cookie:" + e.getMessage());
            }//from  ww  w.  ja  v a 2 s  .c  om
            cookie.setValue(null);
            cookie.setMaxAge(0);
            cookie.setPath("/");
            if (response != null)
                response.addCookie(cookie);
            break;
        }
    }
    return queryStr;
}

From source file:org.akaza.openclinica.control.MainMenuServlet.java

public String getTimeoutReturnToCookie(HttpServletRequest request, HttpServletResponse response) {
    String queryStr = "";
    if (ub == null || StringUtils.isEmpty(ub.getName()))
        return queryStr;

    Cookie[] cookies = request.getCookies();
    for (Cookie cookie : cookies) {
        if (cookie.getName().equalsIgnoreCase("bridgeTimeoutReturn-" + ub.getName())) {
            try {
                queryStr = URLDecoder.decode(cookie.getValue(), "UTF-8");
            } catch (UnsupportedEncodingException e) {
                logger.error("Error decoding redirect URL from queryStr cookie:" + e.getMessage());
            }//from w  ww.j av  a2s  . c  o m
            cookie.setValue(null);
            cookie.setMaxAge(0);
            cookie.setPath("/");
            if (response != null)
                response.addCookie(cookie);
            break;
        }
    }
    return queryStr;
}

From source file:com.icesoft.faces.context.BridgeExternalContext.java

public void addCookie(Cookie cookie) {
    responseCookieMap.put(cookie.getName(), cookie);
    cookieTransporter.send(cookie);
}

From source file:com.zimbra.cs.service.ExternalUserProvServlet.java

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String displayName = req.getParameter("displayname");
    String password = req.getParameter("password");

    String prelimToken = null;//from   w w  w  . ja v  a  2 s.  c o  m
    javax.servlet.http.Cookie cookies[] = req.getCookies();
    if (cookies != null) {
        for (Cookie cookie : cookies) {
            if (cookie.getName().equals("ZM_PRELIM_AUTH_TOKEN")) {
                prelimToken = cookie.getValue();
                break;
            }
        }
    }
    if (prelimToken == null) {
        throw new ServletException("unauthorized request");
    }
    Map<Object, Object> tokenMap = validatePrelimToken(prelimToken);
    String ownerId = (String) tokenMap.get("aid");
    //        String folderId = (String) tokenMap.get("fid");
    String extUserEmail = (String) tokenMap.get("email");

    provisionVirtualAccountAndRedirect(req, resp, displayName, password, ownerId, extUserEmail);
}

From source file:com.appeligo.search.actions.BaseAction.java

public TimeZone getTimeZone() {
    User user = getUser();/*  ww  w  . ja v a 2 s  .  c  o  m*/
    if (user != null) {
        getServletRequest().getSession().setAttribute(TIMEZONE_ID, user.getTimeZone());
        return user.getTimeZone();
    } else {
        TimeZone zone = (TimeZone) getServletRequest().getSession().getAttribute(TIMEZONE_ID);
        if (zone == null) {
            String timeZoneId = null;
            Cookie[] cookies = getServletRequest().getCookies();
            if (cookies != null) {
                for (Cookie cookie : cookies) {
                    if (cookie.getName().equals(TIMEZONE_ID)) {
                        cookie.setMaxAge(Integer.MAX_VALUE);
                        timeZoneId = cookie.getValue();
                        break;
                    }
                }
            }
            if (timeZoneId == null) {
                timeZoneId = DEFAULT_TIMEZONE_ID;
                Cookie cookie = new Cookie(TIMEZONE_ID, timeZoneId);
                cookie.setMaxAge(Integer.MAX_VALUE);
                response.addCookie(cookie);
            }
            zone = TimeZone.getTimeZone(timeZoneId);
            getServletRequest().getSession().setAttribute(TIMEZONE_ID, zone);
            return zone;
        } else {
            return zone;
        }
    }
}

From source file:com.appeligo.search.actions.BaseAction.java

public String getLineup() {
    String lineup = null;/*from  w ww  . j  a va  2 s .co  m*/
    //Get if from the user if there is one
    User user = getUser();
    if (user != null) {
        lineup = user.getLineupId();
        getServletRequest().getSession().setAttribute(LINEUP_ID, lineup);
    } else {
        lineup = (String) getServletRequest().getSession().getAttribute(LINEUP_ID);
        if (lineup == null) {
            // No user, and its not stored in the session, so check for a cookie. If there is no cookie, default them to pacific
            //Right now the lineup is not getting stored in the session when it is loaded by the cookie.
            //The reason is that the cookie gets set before they login and it would not get set with
            //The lineup from the user.
            Cookie[] cookies = getServletRequest().getCookies();
            if (cookies != null) {
                for (Cookie cookie : cookies) {
                    if (cookie.getName().equals(LINEUP_ID)) {
                        cookie.setMaxAge(Integer.MAX_VALUE);
                        lineup = cookie.getValue();
                        break;
                    }
                }
            }
            if (lineup == null) {
                lineup = DEFAULT_LINEUP;
                Cookie cookie = new Cookie(LINEUP_ID, lineup);
                cookie.setMaxAge(Integer.MAX_VALUE);
                response.addCookie(cookie);
                getServletRequest().getSession().setAttribute(LINEUP_ID, lineup);
            }
        }
    }
    return lineup;
}

From source file:io.stallion.requests.StRequest.java

@Override
public Cookie getCookie(String cookieName) {
    if (request.getCookies() != null) {
        for (Cookie cookie : request.getCookies()) {
            if (cookieName.equals(cookie.getName())) {
                return cookie;
            }//from w  ww . j a  va  2 s .co  m
        }
    }
    return null;
}

From source file:net.fenyo.mail4hotspot.web.BrowserServlet.java

@Override
protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException {
    // debug informations
    log.debug("doGet");
    log.debug("context path: " + request.getContextPath());
    log.debug("character encoding: " + request.getCharacterEncoding());
    log.debug("content length: " + request.getContentLength());
    log.debug("content type: " + request.getContentType());
    log.debug("local addr: " + request.getLocalAddr());
    log.debug("local name: " + request.getLocalName());
    log.debug("local port: " + request.getLocalPort());
    log.debug("method: " + request.getMethod());
    log.debug("path info: " + request.getPathInfo());
    log.debug("path translated: " + request.getPathTranslated());
    log.debug("protocol: " + request.getProtocol());
    log.debug("query string: " + request.getQueryString());
    log.debug("requested session id: " + request.getRequestedSessionId());
    log.debug("Host header: " + request.getServerName());
    log.debug("servlet path: " + request.getServletPath());
    log.debug("request URI: " + request.getRequestURI());
    @SuppressWarnings("unchecked")
    final Enumeration<String> header_names = request.getHeaderNames();
    while (header_names.hasMoreElements()) {
        final String header_name = header_names.nextElement();
        log.debug("header name: " + header_name);
        @SuppressWarnings("unchecked")
        final Enumeration<String> header_values = request.getHeaders(header_name);
        while (header_values.hasMoreElements())
            log.debug("  " + header_name + " => " + header_values.nextElement());
    }//from www  .ja v a2 s . co  m
    if (request.getCookies() != null)
        for (Cookie cookie : request.getCookies()) {
            log.debug("cookie:");
            log.debug("cookie comment: " + cookie.getComment());
            log.debug("cookie domain: " + cookie.getDomain());
            log.debug("cookie max age: " + cookie.getMaxAge());
            log.debug("cookie name: " + cookie.getName());
            log.debug("cookie path: " + cookie.getPath());
            log.debug("cookie value: " + cookie.getValue());
            log.debug("cookie version: " + cookie.getVersion());
            log.debug("cookie secure: " + cookie.getSecure());
        }
    @SuppressWarnings("unchecked")
    final Enumeration<String> parameter_names = request.getParameterNames();
    while (parameter_names.hasMoreElements()) {
        final String parameter_name = parameter_names.nextElement();
        log.debug("parameter name: " + parameter_name);
        final String[] parameter_values = request.getParameterValues(parameter_name);
        for (final String parameter_value : parameter_values)
            log.debug("  " + parameter_name + " => " + parameter_value);
    }

    // parse request

    String target_scheme = null;
    String target_host;
    int target_port;

    // request.getPathInfo() is url decoded
    final String[] path_info_parts = request.getPathInfo().split("/");
    if (path_info_parts.length >= 2)
        target_scheme = path_info_parts[1];
    if (path_info_parts.length >= 3) {
        target_host = path_info_parts[2];
        try {
            if (path_info_parts.length >= 4)
                target_port = new Integer(path_info_parts[3]);
            else
                target_port = 80;
        } catch (final NumberFormatException ex) {
            log.warn(ex);
            target_port = 80;
        }
    } else {
        target_scheme = "http";
        target_host = "www.google.com";
        target_port = 80;
    }

    log.debug("remote URL: " + target_scheme + "://" + target_host + ":" + target_port);

    // create forwarding request

    final URL target_url = new URL(target_scheme + "://" + target_host + ":" + target_port);
    final HttpURLConnection target_connection = (HttpURLConnection) target_url.openConnection();

    // be transparent for accept-language headers
    @SuppressWarnings("unchecked")
    final Enumeration<String> accepted_languages = request.getHeaders("accept-language");
    while (accepted_languages.hasMoreElements())
        target_connection.setRequestProperty("Accept-Language", accepted_languages.nextElement());

    // be transparent for accepted headers
    @SuppressWarnings("unchecked")
    final Enumeration<String> accepted_content = request.getHeaders("accept");
    while (accepted_content.hasMoreElements())
        target_connection.setRequestProperty("Accept", accepted_content.nextElement());

}

From source file:com.ssbusy.controller.catalog.CategoryController.java

@Override
@SuppressWarnings("unchecked")
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    ModelAndView model = new ModelAndView();
    MyCustomer customer = (MyCustomer) CustomerState.getCustomer();

    HttpSession session = request.getSession();
    MyOfferCode myOfferCode = (MyOfferCode) session.getAttribute("bonusOfferCode");
    Boolean w_flag = Boolean.FALSE;
    // cookies/*from w  w w  . ja  v a  2 s.c  om*/
    String dateTime = new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime());
    int count = 0;// ??
    Cookie cookies[] = request.getCookies();
    Boolean uiv2 = null;
    if (cookies != null) {
        for (Cookie c : cookies) {
            if (dateTime.equals(c.getName())) {
                count = Integer.valueOf(c.getValue());
                break;
                // } else if ("uiv2".equals(c.getName())) {
                // uiv2 = Boolean.valueOf(c.getValue()); // 2 cookie
            }
        }
    }
    if (cookies != null) {
        for (Cookie c : cookies) {
            if ("SPRING_SECURITY_REMEMBER_ME_COOKIE".equals(c.getName())) {
                model.addObject("rember", c.getValue());
                break;
            }
        }
    }
    // String uiParam = request.getParameter("uiv2");
    // if (StringUtils.isNotEmpty(uiParam)) { // 1 param
    // uiv2 = Boolean.valueOf(uiParam);
    // Cookie c = new Cookie("uiv2", uiv2.toString());
    // c.setPath("/");
    // c.setMaxAge(60 * 60 * 24 * 360);
    // response.addCookie(c);
    // } else if (uiv2 == null) {
    uiv2 = Boolean.TRUE; // 3 default. 
    // }
    session.setAttribute("uiv2", uiv2);
    // LOG.warn("uiv2=" + uiv2);

    if (myOfferCode != null) {
        if (customer.isRegistered())
            giftService.updateOwnerCustomer(customer, myOfferCode);
        else
            myOfferCode = null;
    } else if (count < maxoffercodeCount) {
        myOfferCode = giftService.getgift(customer);
        if (myOfferCode != null) {
            if (customer.isAnonymous()) {
                session.setAttribute("bonusOfferCode", myOfferCode);
                model.addObject("bonusOfferCode", myOfferCode);
                myOfferCode = null;
            }
        }
    }
    if (myOfferCode != null) {
        session.removeAttribute("bonusOfferCode");
        model.addObject("bonusOfferCode", myOfferCode);
        Cookie c = new Cookie(dateTime, String.valueOf(count + 1));
        c.setPath("/");
        c.setMaxAge(60 * 60 * 24);
        response.addCookie(c);
        LOG.info("offerCode sent, id=" + myOfferCode.getId() + ", ip=" + request.getRemoteAddr());
    }

    if (request.getParameterMap().containsKey("facetField")) {
        // If we receive a facetField parameter, we need to convert the
        // field to the
        // product search criteria expected format. This is used in
        // multi-facet selection. We
        // will send a redirect to the appropriate URL to maintain canonical
        // URLs

        String fieldName = request.getParameter("facetField");
        List<String> activeFieldFilters = new ArrayList<String>();
        Map<String, String[]> parameters = new HashMap<String, String[]>(request.getParameterMap());
        for (Iterator<Entry<String, String[]>> iter = parameters.entrySet().iterator(); iter.hasNext();) {
            Map.Entry<String, String[]> entry = iter.next();
            String key = entry.getKey();
            if (key.startsWith(fieldName + "-")) {
                activeFieldFilters.add(key.substring(key.indexOf('-') + 1));
                iter.remove();
            }
        }

        parameters.remove(ProductSearchCriteria.PAGE_NUMBER);
        parameters.put(fieldName, activeFieldFilters.toArray(new String[activeFieldFilters.size()]));
        parameters.remove("facetField");

        String newUrl = ProcessorUtils.getUrl(request.getRequestURL().toString(), parameters);
        model.setViewName("redirect:" + newUrl);
    } else {
        // Else, if we received a GET to the category URL (either the user
        // clicked this link or we redirected
        // from the POST method, we can actually process the results

        Category category = (Category) request
                .getAttribute(CategoryHandlerMapping.CURRENT_CATEGORY_ATTRIBUTE_NAME);
        assert (category != null);

        List<SearchFacetDTO> availableFacets = searchService.getCategoryFacets(category);
        ProductSearchCriteria searchCriteria = facetService.buildSearchCriteria(request, availableFacets);

        String searchTerm = request.getParameter(ProductSearchCriteria.QUERY_STRING);
        ProductSearchResult result;

        List<FulfillmentLocation> locations = null;
        try {
            // 
            if (customer != null && customer.getRegion() != null) {
                InventorySolrSearchServiceExtensionHandler.customerLocation
                        .set(locations = customer.getRegion().getFulfillmentLocations());
            }
            if (StringUtils.isNotBlank(searchTerm)) {
                result = searchService.findProductsByCategoryAndQuery(category, searchTerm, searchCriteria);
            } else {
                result = searchService.findProductsByCategory(category, searchCriteria);
            }
        } finally {
            InventorySolrSearchServiceExtensionHandler.customerLocation.remove();
        }

        facetService.setActiveFacetResults(result.getFacets(), request);
        List<Product> products = result.getProducts();

        if (products != null && products.size() > 0) {
            List<String> prodIds = new ArrayList<String>(products.size());
            for (Product product : products) {
                prodIds.add(String.valueOf(product.getId()));
            }
            model.addObject("ratingSums", ratingService.readRatingSummaries(prodIds, RatingType.PRODUCT));

            // ?productinventories
            if (locations != null) {
                Map<Product, List<Inventory>> invs = inventoryService.listAllInventories(products, locations);
                model.addObject("inventories", invs);
            }
        }

        model.addObject(PRODUCTS_ATTRIBUTE_NAME, products);
        model.addObject(CATEGORY_ATTRIBUTE_NAME, category);
        // facets
        List<SearchFacetDTO> facets = result.getFacets();
        if (facets != null) {
            _nextFact: for (Iterator<SearchFacetDTO> itr = facets.iterator(); itr.hasNext();) {
                SearchFacetDTO dto = itr.next();
                if (dto != null && dto.getFacetValues() != null) {
                    for (SearchFacetResultDTO searchFacetDTO : dto.getFacetValues()) {
                        if (searchFacetDTO != null)
                            if (searchFacetDTO.getQuantity() != null && searchFacetDTO.getQuantity() > 0)
                                continue _nextFact;
                    }
                }
                itr.remove();
            }
            model.addObject(FACETS_ATTRIBUTE_NAME, result.getFacets());
        }
        model.addObject(PRODUCT_SEARCH_RESULT_ATTRIBUTE_NAME, result);

        // TODO temp
        String view = category.getDisplayTemplate();
        if (StringUtils.isEmpty(view))
            view = getDefaultCategoryView();
        if (request.getRequestURI().startsWith("/weixin/")) {
            view = "weixin/catalog/w_category_item";
            w_flag = Boolean.TRUE;
        }
        if (uiv2) {
            if ("layout/home".equals(view))
                view = "v2/home";
            else {
                if (!view.startsWith("activity") && !view.startsWith("weixin/")) {
                    view = "v2/" + view;
                }

            }
        }
        session.setAttribute("w_flag", w_flag);
        model.setViewName(view);
    }
    // if (isAjaxRequest(request)) {
    // model.setViewName(RETURN_PRODUCT_WATERFALL_ITEM);
    // model.addObject("ajax", Boolean.TRUE);
    // }
    return model;
}

From source file:m.c.m.proxyma.resource.ProxymaResponseDataBean.java

/**
 * Adds a Cookie to the response./*  w w  w .j ava  2  s.c  om*/
 * If the Cookie has been already set, the new value overwrites the previous one.
 * The containsCookie method can be used to test for the presence of a
 * Cookie before setting its value.
 * @throws NullArgumentException if the passed argument is null
 */
public void addCookie(Cookie aCookie) throws NullArgumentException {
    if (aCookie == null)
        throw new NullArgumentException("You can't set a null Cookie");

    this.cookies.put(aCookie.getName(), aCookie);

}