List of usage examples for javax.servlet.http Cookie getValue
public String getValue()
From source file:net.longfalcon.web.BaseController.java
protected boolean isCookieSet(String cookieName, HttpServletRequest httpServletRequest) { try {/* w w w . j a va 2 s. c o m*/ Cookie[] cookies = httpServletRequest.getCookies(); for (Cookie cookie : cookies) { if (cookie.getName().equals(cookieName) && ValidatorUtil.isNotNull(cookie.getValue())) { return true; } } } catch (Exception e) { _log.error(e); } return false; }
From source file:com.mobilehelix.appserver.session.SessionManager.java
private String getSessIDFromRequest(HttpServletRequest req) throws AppserverSystemException { String sessIDB64 = req.getHeader(HTTPHeaderConstants.MH_SESSION_ID_HEADER); if ((sessIDB64 == null) && (req.getCookies() != null)) { for (Cookie c : req.getCookies()) { if (HTTPHeaderConstants.MH_SESSION_ID_HEADER.equalsIgnoreCase(c.getName())) { sessIDB64 = c.getValue(); break; }/*from w ww. j av a2s . c o m*/ } } // Decode the B64-encoded key. if (sessIDB64 != null) { byte[] sessID = Base64.decodeBase64(sessIDB64); return this.hashSessionID(sessID); } return null; }
From source file:cn.org.once.cstack.config.SecurityConfiguration.java
/** * Filter CRSF to add XSFR-TOKEN between exchange * * @return/* www . j a v a2s . c om*/ */ private Filter csrfHeaderFilter() { 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, "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:controllers.Parent_Controller.java
public String[] checkSetCookie2(HttpServletRequest request) { Cookie[] cookies2;/* w w w . j av a 2 s.c om*/ cookies2 = request.getCookies(); String creds[] = new String[2]; int countcookies = 0; try { for (Cookie cookie1 : cookies2) { switch (cookie1.getName()) { case "handle": System.out.println("Got Handle cookie"); creds[0] = cookie1.getValue(); countcookies++; break; case "uid": System.out.println("Got uid cookie"); creds[1] = cookie1.getValue(); countcookies++; break; } } if (countcookies == 0) { creds = null; return creds; } else { return creds; } } catch (Exception e) { System.out.println("Parent_Controller>checksetcookie2() error-->" + e); creds = null; return creds; } }
From source file:org.dspace.webmvc.theme.ThemeChangeInterceptor.java
@Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { ThemeResolver themeResolver = RequestContextUtils.getThemeResolver(request); if (themeResolver == null) { throw new IllegalStateException("No ThemeResolver found: not in a DispatcherServlet request?"); }// ww w . j a va 2s . co m String newTheme = request.getParameter(this.paramName); if (newTheme != null) { themeResolver.setThemeName(request, response, newTheme); response.addCookie(new Cookie("themeName", newTheme)); } else { ThemeMapEntry bestMatch = null; for (ThemeMapEntry entry : themeMappings) { if (entry.mapType == MapType.VIEW || entry.mapType == MapType.ANY) { if (modelAndView != null && pathMatcher.match(entry.path, modelAndView.getViewName())) { if (entry.isBestMatch(bestMatch)) { bestMatch = entry; } } } if (entry.mapType == MapType.URL || entry.mapType == MapType.ANY) { String path = urlPathHelper.getLookupPathForRequest(request); if (pathMatcher.match(entry.path, path)) { if (entry.isBestMatch(bestMatch)) { bestMatch = entry; } } } if (entry.mapType == MapType.CONTROLLER || entry.mapType == MapType.ANY) { } } if (bestMatch != null) { themeResolver.setThemeName(request, response, bestMatch.themeName); } else if (request.getCookies() != null) { for (Cookie cookie : request.getCookies()) { if ("themeName".equals(cookie.getName())) { themeResolver.setThemeName(request, response, cookie.getValue()); } } } } super.postHandle(request, response, handler, modelAndView); }
From source file:cec.easyshop.storefront.filters.CustomerLocationRestorationFilter.java
@Override public void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain filterChain) throws ServletException, IOException { if (getCustomerLocationFacade().getUserLocationData() == null) { final Cookie[] cookies = request.getCookies(); if (cookies != null) { for (final Cookie cookie : cookies) { if (getCustomerLocationCookieGenerator().getCookieName().equals(cookie.getName())) { final UserLocationData cookieUserLocationData = decipherUserLocationData( StringUtils.remove(cookie.getValue(), "\"")); getCustomerLocationFacade().setUserLocationData(cookieUserLocationData); break; }//from w ww . j av a 2 s . com } } } filterChain.doFilter(request, response); }
From source file:hudson.plugins.timestamper.format.TimestampFormatter.java
/** * Create a new {@link TimestampFormatter}. * //from w w w. ja v a 2 s .c o m * @param systemTimeFormat * the system clock time format * @param elapsedTimeFormat * the elapsed time format * @param request * the current HTTP request * @param timeZoneId * the currently configured time zone */ TimestampFormatter(String systemTimeFormat, String elapsedTimeFormat, Optional<? extends HttpServletRequest> request, Optional<String> timeZoneId) { String mode = null; Boolean local = null; String offset = null; if (request.isPresent()) { Cookie[] cookies = request.get().getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { if (mode == null && "jenkins-timestamper".equals(cookie.getName())) { mode = cookie.getValue(); } if (local == null && "jenkins-timestamper-local".equals(cookie.getName())) { local = Boolean.valueOf(cookie.getValue()); } if (offset == null && "jenkins-timestamper-offset".equals(cookie.getName())) { offset = cookie.getValue(); } } } } if ("elapsed".equalsIgnoreCase(mode)) { formatTimestamp = new ElapsedTimeFormatFunction(elapsedTimeFormat); } else if ("none".equalsIgnoreCase(mode)) { formatTimestamp = new EmptyFormatFunction(); } else { // "system", no mode cookie, or unrecognised mode cookie if (local != null && local.booleanValue()) { if (offset == null) { offset = "0"; } String localTimeZoneId = convertOffsetToTimeZoneId(offset); timeZoneId = Optional.of(localTimeZoneId); } formatTimestamp = new SystemTimeFormatFunction(systemTimeFormat, timeZoneId); } }
From source file:com.salesmanager.catalog.CatalogInterceptor.java
@Override protected String doIntercept(ActionInvocation invoke, HttpServletRequest req, HttpServletResponse resp) throws Exception { /** remove profile url **/ req.getSession().removeAttribute("profileUrl"); /** synchronize mini shopping cart**/ //get http session shopping cart ShoppingCart cart = SessionUtil.getMiniShoppingCart(req); MerchantStore mStore = SessionUtil.getMerchantStore(req); if (cart == null) {//synch only when the cart is null or empty Cookie[] cookies = req.getCookies(); if (cookies != null) { for (int i = 0; i < cookies.length; i++) { Cookie cookie = cookies[i]; if (cookie.getName().equals(CatalogConstants.SKU_COOKIE + mStore.getMerchantId())) { Locale locale = LocaleUtil.getLocale(req); String cookieValue = StringUtil.unescape(cookie.getValue()); ShoppingCart sc = MiniShoppingCartSerializationUtil.deserializeJSON(cookieValue, mStore, locale);/*from w ww .j a va 2 s .c o m*/ if (sc != null) { MiniShoppingCartUtil.calculateTotal(sc, mStore); SessionUtil.setMiniShoppingCart(sc, req); } else {//expire cookie cookie.setValue(null); cookie.setMaxAge(0); resp.addCookie(cookie); } } } } } return null; }
From source file:eu.europeana.core.util.web.ClickStreamLoggerImpl.java
private String printLogAffix(HttpServletRequest request) { String ip = request.getRemoteAddr(); String reqUrl = getRequestUrl(request); final User user = ControllerUtil.getUser(); String userId;/*from w w w .ja v a2 s. c o m*/ if (user != null) { userId = user.getEmail(); // todo: is this desirable? was id.toString() } else { userId = ""; } String language = ControllerUtil.getLocale(request).toString(); String userAgent = request.getHeader("User-Agent"); String referer = request.getHeader("referer"); Cookie[] cookies = request.getCookies(); String utma = ""; String utmb = ""; String utmc = ""; String utmz = ""; String languageCookie = ""; if (cookies != null) { for (Cookie cookie : cookies) { if (cookie.getName().equalsIgnoreCase("__utma")) { utma = cookie.getValue(); } else if (cookie.getName().equalsIgnoreCase("__utmb")) { utmb = cookie.getValue(); } else if (cookie.getName().equalsIgnoreCase("__utmc")) { utmc = cookie.getValue(); } else if (cookie.getName().equalsIgnoreCase("__utmz")) { utmz = cookie.getValue(); } else if (cookie.getName() .equalsIgnoreCase("org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE")) { languageCookie = cookie.getValue(); } } } PortalTheme theme = themeHandler.getByRequest(request); return MessageFormat.format( "userId={0}, lang={1}, req={4}, date={2}, ip={3}, user-agent={5}, referer={6}, utma={8}, " + "utmb={9}, utmc={10}, utmz={13}, v={7}, duration={11}, langCookie={12}, defaultLanguage={14}", userId, language, new DateTime(), ip, reqUrl, userAgent, referer, VERSION, utma, utmb, utmc, ClickStreamLoggerInterceptor.getTimeElapsed(), languageCookie, utmz, theme.getDefaultLanguage()); }
From source file:com.junly.service.helper.TicketHelper.java
/** <p class="detail"> * ???ticket/*from ww w .j a v a 2 s . c o m*/ * </p> * @author junly * @date 2017324 * @param request * @param httpChannelType * @return */ public String getTicket(HttpServletRequest request, HttpChannelType httpChannelType) { Cookie cookies[] = request.getCookies(); String ticket = null; if (null != cookies) { for (Cookie cookie : cookies) { if (StringUtils.equals(ViewContants.LOGIN_TICKET_KEY, cookie.getName())) { ticket = StringUtils.trim(cookie.getValue()); StringBuilder builder = new StringBuilder(httpChannelType.name()); builder.append("?cookieticket=").append(ticket); builder.append("?=").append(request.getServerName()).append("===="); builder.append(cookie.getDomain()); logger.info(builder.toString()); break; } } } // java??cookieheader???, // ???cookie? ?? if (StringUtils.isBlank(ticket)) { ticket = customHeadTicket(request, httpChannelType); } if (StringUtils.isBlank(ticket)) { ticket = StringUtils.trim(request.getParameter(ViewContants.LOGIN_TICKET_KEY)); } return ticket; }