Package javax.servlet.http

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


                        "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

 
  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

                }
                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

    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

    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

    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

   * @param cookieName
   * @return
   */
  public static String getCookieValue(HttpServletRequest request, String cookieName) {
    try {
      Cookie cookie = getCookie(request, cookieName);
      if (null == cookie) {
        return null;
      } else {
        return URLDecoder.decode(cookie.getValue(), "utf-8");
      }
    } catch (Exception e) {
      return null;
    }
  }
View Full Code Here

   *            the name of the cookie to find
   * @return the cookie (if found), null if not found
   */
  public static Cookie getCookie(HttpServletRequest request, String name) {
    Cookie[] cookies = request.getCookies();
    Cookie returnCookie = null;

    if (cookies == null) { return returnCookie; }
    for (int i = 0; i < cookies.length; i++) {
      Cookie thisCookie = cookies[i];
      if (thisCookie.getName().equals(name) && !thisCookie.getValue().equals("")) {
        returnCookie = thisCookie;
        break;
      }
    }
    return returnCookie;
View Full Code Here

   * @param path
   */
  public static void addCookie(HttpServletRequest request, HttpServletResponse response, String name,
      String value, String path, int age) {
    LOG.debug("add cookie[name:{},value={},path={}]", new String[] { name, value, path });
    Cookie cookie = null;
    try {
      cookie = new Cookie(name, URLEncoder.encode(value, "utf-8"));
    } catch (UnsupportedEncodingException e) {
      throw new RuntimeException(e);
    }
    cookie.setSecure(false);
    cookie.setPath(path);
    cookie.setMaxAge(age);
    response.addCookie(cookie);
  }
View Full Code Here

TOP

Related Classes of javax.servlet.http.Cookie

Copyright © 2018 www.massapicom. 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.