Package javax.servlet.http

Examples of javax.servlet.http.Cookie


          offset = print(buffer, offset, response.getContentLength());
        break;

        // cookie
      case 'c':
        Cookie cookie = request.getCookie(segment._string);
        if (cookie == null)
          cookie = responseFacade.getCookie(segment._string);
        if (cookie == null)
          buffer[offset++] = (byte) '-';
        else
          offset = print(buffer, offset, cookie.getValue());
        break;

        // set cookie
      case Segment.SET_COOKIE:
        ArrayList<Cookie> cookies = responseFacade.getCookies();
View Full Code Here


  {
    Cookie[] cookies = request.getCookies();

    if (cookies != null) {
      for (int i = 0; i < cookies.length; i++) {
        Cookie cookie = cookies[i];

        if (cookie.getName().equals(_name)) {
          return _regexp == null || _regexp.matcher(cookie.getValue()).find();
        }
      }
    }

    return false;
View Full Code Here

    ArrayList<Cookie> cookiesOut = responseFacade.getCookies();

    if (cookiesOut != null) {
      size = cookiesOut.size();
      for (int i = 0; i < size; i++) {
        Cookie cookie = cookiesOut.get(i);
        int cookieVersion = cookie.getVersion();

        fillCookie(cb, cookie, now, 0, false);
        _req.writeHeader("Set-Cookie", cb);
        if (cookieVersion > 0) {
          fillCookie(cb, cookie, now, cookieVersion, true);
View Full Code Here

  {
    char []buf = rawCookie.getBuffer();
    int j = rawCookie.getOffset();
    int end = j + rawCookie.length();
    int version = 0;
    Cookie cookie = null;

    while (j < end) {
      char ch = 0;

      CharBuffer cbName = _cbName;
      CharBuffer cbValue = _cbValue;

      cbName.clear();
      cbValue.clear();

      for (;
           j < end && ((ch = buf[j]) == ' ' || ch == ';' || ch ==',');
           j++) {
      }

      if (end <= j)
        break;

      boolean isSpecial = false;
      if (buf[j] == '$') {
        isSpecial = true;
        j++;
      }

      for (; j < end; j++) {
        ch = buf[j];
        if (ch < 128 && TOKEN[ch])
          cbName.append(ch);
        else
          break;
      }

      for (; j < end && (ch = buf[j]) == ' '; j++) {
      }

      if (end <= j)
        break;
      else if (ch == ';' || ch == ',') {
        try {
          cookie = new Cookie(cbName.toString(), "");
          cookie.setVersion(version);
          _cookies.add(cookie);
          // some clients can send bogus cookies
        } catch (Exception e) {
          log.log(Level.FINE, e.toString(), e);
        }
        continue;
      }
      else if (ch != '=') {
        for (; j < end && (ch = buf[j]) != ';'; j++) {
        }
        continue;
      }

      j++;

      for (; j < end && (ch = buf[j]) == ' '; j++) {
      }

      if (ch == '"') {
        for (j++; j < end; j++) {
          ch = buf[j];
          if (ch == '"')
            break;
          cbValue.append(ch);
        }
        j++;
      }
      else {
        for (; j < end; j++) {
          ch = buf[j];
          if (ch < 128 && VALUE[ch])
            cbValue.append(ch);
          else
            break;
        }
      }

      if (! isSpecial) {
        if (cbName.length() == 0)
          log.warning("bad cookie: " + rawCookie);
        else {
          cookie = new Cookie(toName(cbName), cbValue.toString());
          cookie.setVersion(version);
          _cookies.add(cookie);
        }
      }
      else if (cookie == null) {
        if (cbName.matchesIgnoreCase("Version"))
          version = cbValue.charAt(0) - '0';
      }
      else if (cbName.matchesIgnoreCase("Version"))
        cookie.setVersion(cbValue.charAt(0) - '0');
      else if (cbName.matchesIgnoreCase("Domain"))
        cookie.setDomain(cbValue.toString());
      else if (cbName.matchesIgnoreCase("Path"))
        cookie.setPath(cbValue.toString());
    }
  }
View Full Code Here

    Authenticator auth = getAuthenticator();

    if (auth instanceof CookieAuthenticator) {
      CookieAuthenticator cookieAuth = (CookieAuthenticator) auth;

      Cookie resinAuth = ((CauchoRequest) request).getCookie("resinauthid");

      if (resinAuth != null) {
        user = cookieAuth.authenticateByCookie(resinAuth.getValue());

        if (user != null)
          return user;
      }
    }
View Full Code Here

      return;

    SessionManager manager = webApp.getSessionManager();
    String value = manager.createCookieValue();

    Cookie cookie = new Cookie("resinauthid", value);
    cookie.setVersion(1);

    long cookieMaxAge = 365L * 24L * 3600L * 1000L;

    cookie.setMaxAge((int) (cookieMaxAge / 1000L));
    cookie.setPath("/");
    cookie.setDomain(webApp.generateCookieDomain(request));

    auth.associateCookie(user, value);

    response.addCookie(cookie);
  }
View Full Code Here

        if (response == null)
        {
            throw new IllegalStateException("Servlet response not available");
        }

        Cookie cookie = new Cookie(name, value);
        cookie.setMaxAge(seconds_age);
        cookie.setPath(cookiePath.getContextPath()+cookiePath.getScriptName());
        response.addCookie (cookie);
    }
View Full Code Here

        throws IOException, ServletException
    {

        String cookieName = request.getParameter("cookiename");
        String cookieValue = request.getParameter("cookievalue");
        Cookie aCookie = null;
        if (cookieName != null && cookieValue != null) {
            aCookie = new Cookie(cookieName, cookieValue);
            aCookie.setPath(request.getContextPath() + "/");
            response.addCookie(aCookie);
        }

        response.setContentType("text/html");

        PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<head>");

        String title = RB.getString("cookies.title");
        out.println("<title>" + title + "</title>");
        out.println("</head>");
        out.println("<body bgcolor=\"white\">");

        // relative links

        // XXX
        // making these absolute till we work out the
        // addition of a PathInfo issue

        out.println("<a href=\"../cookies.html\">");
        out.println("<img src=\"../images/code.gif\" height=24 " +
                    "width=24 align=right border=0 alt=\"view code\"></a>");
        out.println("<a href=\"../index.html\">");
        out.println("<img src=\"../images/return.gif\" height=24 " +
                    "width=24 align=right border=0 alt=\"return\"></a>");

        out.println("<h3>" + title + "</h3>");

        Cookie[] cookies = request.getCookies();
        if ((cookies != null) && (cookies.length > 0)) {
            out.println(RB.getString("cookies.cookies") + "<br>");
            for (int i = 0; i < cookies.length; i++) {
                Cookie cookie = cookies[i];
                out.print("Cookie Name: " + HTMLFilter.filter(cookie.getName())
                          + "<br>");
                out.println("  Cookie Value: "
                            + HTMLFilter.filter(cookie.getValue())
                            + "<br><br>");
            }
        } else {
            out.println(RB.getString("cookies.no-cookies"));
        }
View Full Code Here

        String domain = UtilProperties.getPropertyValue("url.properties", "cookie.domain");
        // first try to get the username from the cookie
        synchronized (session) {
            if (UtilValidate.isEmpty(getUsername(request))) {
                // create the cookie and send it back
                Cookie cookie = new Cookie(usernameCookieName, request.getParameter("USERNAME"));
                cookie.setMaxAge(60 * 60 * 24 * 365);
                cookie.setPath("/");
                cookie.setDomain(domain);
                response.addCookie(cookie);
            }
        }
    }
View Full Code Here

            }
        }
        if (set) {
            Iterator<Cookie> iter = cookies.iterator();
            while (iter.hasNext()) {
                Cookie c = iter.next();
                if (name.equals(c.getName())) {
                    iter.remove();
                    break;
                }
            }
        } else {
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.