Examples of Cookie


Examples of javax.servlet.http.Cookie

  public static Cookie getCookie(Cookie[] cookies, String cookieName) {
    if(cookies == null){
      return null;
    }
    for (int i = 0; i < cookies.length; i++) {
      Cookie cookie = cookies[i];
      if (cookieName.equals(cookie.getName()))
        return (cookie);
    }
    return (null);
  }
View Full Code Here

Examples of javax.servlet.http.Cookie

   * and path will be set to <code>/</code>.
   * @param res the source where the cookie will be deleted.
   * @param cookieName the name of the cookie to delete.
   */
  public static void deleteCookie(HttpServletResponse res, String cookieName){
    Cookie cookie = new Cookie(cookieName,null);
    cookie.setMaxAge(0);
    cookie.setPath("/");
    res.addCookie(cookie);
  }
View Full Code Here

Examples of javax.servlet.http.Cookie

                // next token
                cookieLine = nextToken(st);
            } else {
                String name = cookieLine.substring(0, equalPos);
                String value = extractFromQuotes(cookieLine.substring(equalPos + 1));
                Cookie thisCookie = new Cookie(name, value);
                thisCookie.setVersion(version);
                thisCookie.setSecure(isSecure());
                cookieList.add(thisCookie);

                // check for path / domain / port
                cookieLine = nextToken(st);
                while ((cookieLine != null) && cookieLine.trim().startsWith("$")) {
                    cookieLine = cookieLine.trim();
                    equalPos = cookieLine.indexOf('=');
                    String attrValue = equalPos == -1 ? "" : cookieLine
                            .substring(equalPos + 1).trim();
                    if (cookieLine.startsWith("$Path")) {
                        thisCookie.setPath(extractFromQuotes(attrValue));
                    } else if (cookieLine.startsWith("$Domain")) {
                        thisCookie.setDomain(extractFromQuotes(attrValue));
                    }
                    cookieLine = nextToken(st);
                }

                Logger.log(Logger.FULL_DEBUG, Launcher.RESOURCES,
                        "WinstoneRequest.CookieFound", thisCookie.toString());
                if (thisCookie.getName().equals(WinstoneSession.SESSION_COOKIE_NAME)) {
                    // Find a context that manages this key
                    HostConfiguration hostConfig = this.hostGroup.getHostByName(this.serverName);
                    WebAppConfiguration ownerContext = hostConfig.getWebAppBySessionKey(thisCookie.getValue());
                    if (ownerContext != null) {
                        this.requestedSessionIds.put(ownerContext.getContextPath(),
                                thisCookie.getValue());
                        this.currentSessionIds.put(ownerContext.getContextPath(),
                                thisCookie.getValue());
                    }
                    // If not found, it was probably dead
                    else {
                        this.deadRequestedSessionId = thisCookie.getValue();
                    }
//                    this.requestedSessionId = thisCookie.getValue();
//                    this.currentSessionId = thisCookie.getValue();
                    Logger.log(Logger.FULL_DEBUG, Launcher.RESOURCES,
                            "WinstoneRequest.SessionCookieFound",
                            new String[] {thisCookie.getValue(),
                            ownerContext == null ? "" : "prefix:" + ownerContext.getContextPath()});
                }
            }
        }
    }
View Full Code Here

Examples of javax.servlet.http.Cookie

            WebAppConfiguration ownerContext = hostConfig.getWebAppByURI(prefix);
            if (ownerContext != null) {
                WinstoneSession session = ownerContext.getSessionById(sessionId, true);
                if ((session != null) && session.isNew()) {
                    session.setIsNew(false);
                    Cookie cookie = new Cookie(WinstoneSession.SESSION_COOKIE_NAME, session.getId());
                    cookie.setMaxAge(-1);
                    cookie.setSecure(req.isSecure());
                    cookie.setVersion(0); //req.isSecure() ? 1 : 0);
                    cookie.setPath(req.getWebAppConfig().getContextPath().equals("") ? "/"
                                    : req.getWebAppConfig().getContextPath());
                    this.cookies.add(cookie); // don't call addCookie because we might be including
                }
            }
        }
       
        // Look for expired sessions: ie ones where the requested and current ids are different
        for (Iterator i = req.getRequestedSessionIds().keySet().iterator(); i.hasNext(); ) {
            String prefix = (String) i.next();
            String sessionId = (String) req.getRequestedSessionIds().get(prefix);
            if (!req.getCurrentSessionIds().containsKey(prefix)) {
                Cookie cookie = new Cookie(WinstoneSession.SESSION_COOKIE_NAME, sessionId);
                cookie.setMaxAge(0); // explicitly expire this cookie
                cookie.setSecure(req.isSecure());
                cookie.setVersion(0); //req.isSecure() ? 1 : 0);
                cookie.setPath(prefix.equals("") ? "/" : prefix);
                this.cookies.add(cookie); // don't call addCookie because we might be including
            }
        }
       
        Logger.log(Logger.FULL_DEBUG, Launcher.RESOURCES, "WinstoneResponse.HeadersPreCommit",
View Full Code Here

Examples of javax.servlet.http.Cookie

                        "WinstoneOutputStream.Header", header);
            }

            if (!this.owner.getHeaders().isEmpty()) {
                for (Iterator i = this.owner.getCookies().iterator(); i.hasNext();) {
                    Cookie cookie = (Cookie) i.next();
                    String cookieText = this.owner.writeCookie(cookie);
                    this.outStream.write(cookieText.getBytes("8859_1"));
                    this.outStream.write(CR_LF);
                    Logger.log(Logger.FULL_DEBUG, Launcher.RESOURCES,
                            "WinstoneOutputStream.Header", cookieText);
View Full Code Here

Examples of javax.servlet.http.Cookie

 
  private User getUserFromRememberMeCookie(){
    ActionContext ctx = ActionContext.getContext();
    HttpServletRequest req = (HttpServletRequest)ctx.get(ServletActionContext.HTTP_REQUEST);
    Cookie[] cookies = req.getCookies();
    Cookie passKey = ServletUtilities.getCookie(cookies,SessionConstants.REMEMBER_ME);
    if(passKey != null){
      String val = passKey.getValue();
      String[] s = val.split(":");
      if(s != null && s.length == 2){
        String username = s[0];
        String passwordMD5 = s[1];
        try {
View Full Code Here

Examples of javax.servlet.http.Cookie

                }
                headerArrayStream.write(getStringBlock(headerValue));
            }

            for (Iterator i = this.owner.getCookies().iterator(); i.hasNext();) {
                Cookie cookie = (Cookie) i.next();
                String cookieText = this.owner.writeCookie(cookie);
                int colonPos = cookieText.indexOf(':');
                if (colonPos == -1)
                    throw new WinstoneException(Ajp13Listener.AJP_RESOURCES.getString(
                            "Ajp13OutputStream.NoColonHeader", cookieText));
View Full Code Here

Examples of javax.servlet.http.Cookie

    if (contentType != null) res.setContentType(contentType);
    if (locale != null) res.setLocale(locale);
    // Write cookies
    Enumeration cookieenum = cookies.elements();
    while (cookieenum.hasMoreElements()) {
      Cookie c = (Cookie) cookieenum.nextElement();
      res.addCookie(c);
    }
    // Write standard headers
    Enumeration headerenum = headers.keys();
    while (headerenum.hasMoreElements()) {
View Full Code Here

Examples of javax.servlet.http.Cookie

    this.user = user;
  }
 
  private void doRememberMe(User userRecord){
    if(rememberMe == true){
      Cookie passCookie = createPassCookie(userRecord);
      HttpServletResponse res = getServletResponse();
      res.addCookie(passCookie);
    }else{
      ServletUtilities.deleteCookie(getServletResponse(),SessionConstants.REMEMBER_ME);
    }
View Full Code Here

Examples of javax.servlet.http.Cookie

    StringBuffer passKey = new StringBuffer();
    passKey.append(userRecord.getUsername());
    passKey.append(":");
    passKey.append(userRecord.getPassword());
   
    Cookie passCookie = new Cookie(SessionConstants.REMEMBER_ME,passKey.toString());
    passCookie.setPath("/");
    passCookie.setMaxAge(ServletUtilities.SECONDS_PER_YEAR);
    return passCookie;   
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.